Sha256: 3c1bbc3801e0bcd600f312533b7f7a055d2323d1e0b4a5d6ea89c020a4f6b382

Contents?: true

Size: 1.54 KB

Versions: 47

Compression:

Stored size: 1.54 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)
      raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen?

      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 if @haml_buffer
          end
        RUBY
      end
    end
  end
end

Version data entries

47 entries across 46 versions & 14 rubygems

Version Path
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
brakeman-3.7.0 bundle/ruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
brakeman-3.6.2 bundle/ruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/tilt-2.0.7/lib/tilt/haml.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/tilt-2.0.7/lib/tilt/haml.rb
brakeman-3.6.1 bundle/ruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
brakeman-3.6.0 bundle/ruby/2.3.0/gems/tilt-2.0.7/lib/tilt/haml.rb
tilt-2.0.7 lib/tilt/haml.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/tilt-2.0.6/lib/tilt/haml.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/tilt-2.0.6/lib/tilt/haml.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/tilt-2.0.6/lib/tilt/haml.rb