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)


94
95
96
97
# File 'lib/tilt/haml.rb', line 94

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

#precompiled_postamble(locals) ⇒ Object



147
148
149
150
151
152
153
154
155
156
# File 'lib/tilt/haml.rb', line 147

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



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/tilt/haml.rb', line 132

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



128
129
130
131
132
133
134
135
136
# File 'lib/tilt/haml.rb', line 128

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.



109
110
111
112
113
114
115
116
117
118
# File 'lib/tilt/haml.rb', line 109

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