Class: Haml::TempleEngine

Inherits:
Temple::Engine
  • Object
show all
Defined in:
lib/haml/template.rb,
lib/haml/temple_engine.rb

Instance Method Summary collapse

Instance Method Details

#compile(template)

41
42
43
44
# File 'lib/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/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_method_return_value_with_haml_xss Also known as: precompiled_method_return_value

18
19
20
# File 'lib/haml/template.rb', line 18

def precompiled_method_return_value_with_haml_xss
  "::Haml::Util.html_safe(#{precompiled_method_return_value_without_haml_xss})"
end

#precompiled_method_return_value_without_haml_xss

21
# File 'lib/haml/template.rb', line 21

alias_method :precompiled_method_return_value_without_haml_xss, :precompiled_method_return_value

#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/haml/temple_engine.rb', line 68

def precompiled_with_ambles(local_names, after_preamble: '')
  preamble = <<END.tr("\n", ';')
begin
extend Haml::Helpers
_hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{Options.new(options).for_buffer.inspect})
_erbout = _hamlout.buffer
#{after_preamble}
END
  postamble = <<END.tr("\n", ';')
#{precompiled_method_return_value}
ensure
@haml_buffer = @haml_buffer.upper if @haml_buffer
end
END
  "#{preamble}#{locals_code(local_names)}#{precompiled}#{postamble}".dup
end

#precompiled_with_return_value

58
59
60
# File 'lib/haml/temple_engine.rb', line 58

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