Class: Walrus::Grammar::RawDirective

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

Instance Method Summary collapse

Instance Method Details

#compile(options = {}) ⇒ Object

Returns a string containing the compiled (Ruby) version of receiver.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/walrus/grammar/raw_directive.rb', line 29

def compile options = {}
  compiled  = []
  first     = true
  @content.to_s.to_source_string.each do |line|
    newline = ''
    if line =~ /(\r\n|\r|\n)\z/       # check for literal newline at end of line
      line.chomp!                     # get rid of it
      newline = ' + ' + $~[0].dump    # include non-literal newline instead
    end

    if first
      compiled << "accumulate('%s'%s) # RawDirective\n" % [ line, newline ]
      first = false
    else
      compiled << "accumulate('%s'%s) # RawDirective (continued)\n" % [ line, newline ]
    end
  end
  compiled.join
end