Class: Walrus::Grammar::EchoDirective

Inherits:
Directive
  • Object
show all
Defined in:
lib/walrus/grammar/echo_directive.rb

Instance Method Summary collapse

Instance Method Details

#compile(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/walrus/grammar/echo_directive.rb', line 28

def compile options = {}
  if @expression.respond_to? :each
    expression = @expression
  else
    expression = [@expression]
  end

  # TODO: potentially include line, col and file name info in the
  # comments generated by the compiler

  compiled  = ''
  first     = true
  expression.each do |expr|
    if first
      compiled <<
        "accumulate(instance_eval { %s }) # Echo directive\n" %
        expr.compile
      first = false
    else
      compiled <<
        "accumulate(instance_eval { %s }) # Echo directive (continued)\n" %
        expr.compile
    end
  end
  compiled
end