Class: Hamlit::HamlTempleEngine

Inherits:
Temple::Engine
  • Object
show all
Defined in:
lib/hamlit/parser/haml_temple_engine.rb

Instance Method Summary collapse

Instance Method Details

#compile(template) ⇒ Object



41
42
43
44
# File 'lib/hamlit/parser/haml_temple_engine.rb', line 41

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

#precompiledString

The source code that is evaluated to produce the Haml document.

This is automatically converted to the correct encoding (see the ‘:encoding` option).

Returns:

  • (String)


52
53
54
55
56
# File 'lib/hamlit/parser/haml_temple_engine.rb', line 52

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: '') ⇒ String

The source code that is evaluated to produce the Haml document.

This is automatically converted to the correct encoding (see the ‘:encoding` option).

Returns:

  • (String)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/hamlit/parser/haml_temple_engine.rb', line 68

def precompiled_with_ambles(local_names, after_preamble: '')
  preamble = "begin\nextend Hamlit::HamlHelpers\n_hamlout = @haml_buffer = Hamlit::HamlBuffer.new(haml_buffer, \#{HamlOptions.new(options).for_buffer.inspect})\n_erbout = _hamlout.buffer\n\#{after_preamble}\n".tr("\n", ';')
  postamble = "\#{precompiled_method_return_value}\nensure\n@haml_buffer = @haml_buffer.upper if @haml_buffer\nend\n".tr("\n", ';')
  "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
end

#precompiled_with_return_valueObject



58
59
60
# File 'lib/hamlit/parser/haml_temple_engine.rb', line 58

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