Sha256: 143b4e714a224f66df8cfb0a29f8000647b1503f29bbea0c24ef60532159df33

Contents?: true

Size: 1.45 KB

Versions: 8

Compression:

Stored size: 1.45 KB

Contents

require 'tilt/template'
require 'haml'

module Tilt
  # Haml template implementation. See:
  # http://haml.hamptoncatlin.com/
  class HamlTemplate < Template
    self.default_mime_type = 'text/html'

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

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

    # Precompiled Haml source. Taken from the precompiled_with_ambles
    # method in Haml::Precompiler:
    # http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126
    def precompiled_template(locals)
      @engine.precompiled
    end

    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

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

Version data entries

8 entries across 8 versions & 4 rubygems

Version Path
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/tilt-2.0.1/lib/tilt/haml.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/tilt-2.0.1/lib/tilt/haml.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/tilt-2.0.1/lib/tilt/haml.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/tilt-2.0.1/lib/tilt/haml.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/tilt-2.0.1/lib/tilt/haml.rb
tilt-2.0.1 lib/tilt/haml.rb
tilt-2.0.0 lib/tilt/haml.rb
tilt-2.0.0.beta1 lib/tilt/haml.rb