Class: Tilt::HamlTemplate

Inherits:
Template show all
Defined in:
lib/vendor/tilt-1.4.1/lib/tilt/haml.rb

Overview

Haml template implementation. See: haml.hamptoncatlin.com/

Instance Attribute Summary

Attributes inherited from Template

#data, #file, #line, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Template

#allows_script?, #basename, #default_encoding, #eval_file, #initialize, #name, #read_template_file, #render

Constructor Details

This class inherits a constructor from Tilt::Template

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 9

def self.engine_initialized?
  defined? ::Haml::Engine
end

Instance Method Details

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



22
23
24
25
26
27
28
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 22

def evaluate(scope, locals, &block)
  if @engine.respond_to?(:precompiled_method_return_value, true)
    super
  else
    @engine.render(scope, locals, &block)
  end
end

#initialize_engineObject



13
14
15
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 13

def initialize_engine
  require_template_library 'haml'
end

#precompiled_postamble(locals) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 52

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

#precompiled_preamble(locals) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 37

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



33
34
35
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 33

def precompiled_template(locals)
  @engine.precompiled
end

#prepareObject



17
18
19
20
# File 'lib/vendor/tilt-1.4.1/lib/tilt/haml.rb', line 17

def prepare
  options = @options.merge(:filename => eval_file, :line => line)
  @engine = ::Haml::Engine.new(data, options)
end