Class: Tilt::HamlTemplate

Inherits:
Template show all
Defined in:
lib/tilt/haml.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, #fixed_locals?, #initialize, #metadata, metadata, #name, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
# File 'lib/tilt/haml.rb', line 28

def evaluate(scope, locals, &block)
  raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?
  super
end

#precompiled_postamble(locals) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/tilt/haml.rb', line 81

def precompiled_postamble(locals)
  @engine.instance_eval do
    "        \#{precompiled_method_return_value}\n      ensure\n        @haml_buffer = @haml_buffer.upper if haml_buffer\n      end\n    RUBY\n  end\nend\n"

#precompiled_preamble(locals) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/tilt/haml.rb', line 66

def precompiled_preamble(locals)
  local_assigns = super
  @engine.instance_eval do
    "      begin\n        extend Haml::Helpers\n        _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, \#{options_for_buffer.inspect})\n        _erbout = _hamlout.buffer\n        __in_erb_template = true\n        _haml_locals = locals\n        \#{local_assigns}\n    RUBY\n  end\nend\n"

#precompiled_template(locals) ⇒ Object

Precompiled Haml source. Taken from the precompiled_with_ambles method in Haml::Precompiler: github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126



62
63
64
65
66
67
68
69
70
# File 'lib/tilt/haml.rb', line 62

def precompiled_template(locals)
  @engine.precompiled_with_ambles(
    [],
    after_preamble: "      __in_erb_template = true\n      _haml_locals = locals\n    RUBY\n  )\nend\n"

#prepareObject

Following definitions are for Haml <= 4 and deprecated.



43
44
45
46
47
48
49
50
51
52
# File 'lib/tilt/haml.rb', line 43

def prepare
  @options[:filename] = eval_file
  @options[:line] = @line
  if @options.include?(:outvar)
    @options[:buffer] = @options.delete(:outvar)
    @options[:save_buffer] = true
  end
  @engine = ::Haml::TempleEngine.new(@options)
  @engine.compile(@data)
end