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, default_mime_type, default_mime_type=, #eval_file, #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)


26
27
28
29
# File 'lib/tilt/haml.rb', line 26

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

#precompiled_postamble(locals) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/tilt/haml.rb', line 78

def precompiled_postamble(locals)
  @engine.instance_eval do
    <<-RUBY
        #{precompiled_method_return_value}
      ensure
        @haml_buffer = @haml_buffer.upper if haml_buffer
      end
    RUBY
  end
end

#precompiled_preamble(locals) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tilt/haml.rb', line 63

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

#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



59
60
61
62
63
64
65
66
67
# File 'lib/tilt/haml.rb', line 59

def precompiled_template(locals)
  @engine.precompiled_with_ambles(
    [],
    after_preamble: <<-RUBY
      __in_erb_template = true
      _haml_locals = locals
    RUBY
  )
end

#prepareObject

Following definitions are for Haml <= 4 and deprecated.



41
42
43
44
45
46
47
48
49
# File 'lib/tilt/haml.rb', line 41

def prepare
  options = {}.update(@options).update(filename: eval_file, 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