class Emcee::DirectiveProcessor

The ‘DirectiveProcessor` is responsible for parsing and evaluating directive comments in a source file.

Constants

HEADER_PATTERN

Matches the entire header/directive block. This is everything from the top of the file, enclosed in html comments.

Public Instance Methods

render(context, locals) click to toggle source

Implement ‘render` so that it uses our own header pattern.

# File lib/emcee/directive_processor.rb, line 10
def render(context, locals)
  @context = context
  @pathname = context.pathname
  @directory = File.dirname(@pathname)

  @header  = data[HEADER_PATTERN, 0] || ""
  @body    = $' || data
  # Ensure body ends in a new line
  @body += "\n" if @body != "" && @body !~ /\n\Z/m

  @included_pathnames = []

  @result = ""
  @result.force_encoding(body.encoding)

  @has_written_body = false

  process_directives
  process_source

  @result
end