Class: EZML::TemplateEngine

Inherits:
Temple::Engine
  • Object
show all
Defined in:
lib/ezml/template_engine.rb

Instance Method Summary collapse

Instance Method Details

#compile(template) ⇒ Object



38
39
40
41
# File 'lib/ezml/template_engine.rb', line 38

def compile(template)
  initialize_encoding(template, options[:encoding])
  @precompiled = call(template)
end

#precompiledObject



43
44
45
46
47
# File 'lib/ezml/template_engine.rb', line 43

def precompiled
  encoding = Encoding.find(@encoding || '')
  return @precompiled.dup.force_encoding(encoding) if encoding == Encoding::ASCII_8BIT
  return @precompiled.encode(encoding)
end

#precompiled_with_ambles(local_names, after_preamble: '') ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ezml/template_engine.rb', line 53

def precompiled_with_ambles(local_names, after_preamble: '')
  preamble = "begin\nextend EZML::Helpers\n_ezmlout = @ezml_buffer = EZML::Buffer.new(ezml_buffer, \#{Options.new(options).for_buffer.inspect})\n_erbout = _ezmlout.buffer\n\#{after_preamble}\n".tr("\n", ';')
  postamble = "\#{precompiled_method_return_value}\nensure\n@ezml_buffer = @ezml_buffer.upper if @ezml_buffer\nend\n".tr("\n", ';')
  "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
end

#precompiled_with_return_valueObject



49
50
51
# File 'lib/ezml/template_engine.rb', line 49

def precompiled_with_return_value
  "#{precompiled};#{precompiled_method_return_value}".dup
end