Class: Tilt::EtanniTemplate

Inherits:
Template show all
Defined in:
lib/tilt/etanni.rb

Instance Attribute Summary

Attributes inherited from Template

#compiled_path, #data, #file, #line, #options

Instance Method Summary collapse

Methods inherited from Template

#basename, #compiled_method, default_mime_type, default_mime_type=, #eval_file, #initialize, metadata, #metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

#precompiled(locals) ⇒ Object



23
24
25
26
# File 'lib/tilt/etanni.rb', line 23

def precompiled(locals)
  source, offset = super
  [source, offset + 1]
end

#precompiled_template(locals) ⇒ Object



19
20
21
# File 'lib/tilt/etanni.rb', line 19

def precompiled_template(locals)
  @code
end

#prepareObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tilt/etanni.rb', line 6

def prepare
  separator = data.hash.abs
  chomp = "<<#{separator}.chomp"
  start = "\n_out_ << #{chomp}\n"
  stop = "\n#{separator}\n"
  replacement = "#{stop}\\1#{start}"

  temp = @data.strip
  temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, replacement)

  @code = "_out_ = [<<#{separator}.chomp]\n#{temp}#{stop}_out_.join"
end