Sha256: b5cee58a0884f436e9a67f66162bc4654e8c6da2ad2d455e66b9dcc0d8ff35e3

Contents?: true

Size: 1.57 KB

Versions: 181

Compression:

Stored size: 1.57 KB

Contents

require 'tilt/template'

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

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

    def initialize_engine
      require_template_library 'haml'
    end

    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

181 entries across 156 versions & 27 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/tilt-1.4.1/lib/tilt/haml.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/tilt-1.4.1/lib/tilt/haml.rb
classiccms-0.7.5 vendor/bundle/gems/tilt-1.3.3/lib/tilt/haml.rb
classiccms-0.7.4 vendor/bundle/gems/tilt-1.3.3/lib/tilt/haml.rb
classiccms-0.7.3 vendor/bundle/gems/tilt-1.3.3/lib/tilt/haml.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/tilt-1.4.1/lib/tilt/haml.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/tilt-1.4.1/lib/tilt/haml.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/tilt-1.4.1/lib/tilt/haml.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/tilt-1.3.3/lib/tilt/haml.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/tilt-1.3.3/lib/tilt/haml.rb
scout_realtime-1.0.5 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-1.0.4 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-1.0.3 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-1.0.3.pre lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-1.0.2 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-1.0.1 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-1.0.0 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-0.5.5 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-0.5.5.pre lib/vendor/tilt-1.4.1/lib/tilt/haml.rb
scout_realtime-0.5.4 lib/vendor/tilt-1.4.1/lib/tilt/haml.rb