Sha256: 9274f7cfbf6d85735c6b735bd0b2b7df4b8fb13c8cc8e615a2ff57165b8d3f5c

Contents?: true

Size: 1.06 KB

Versions: 28

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Haml

  # This module makes Haml work with Rails using the template handler API.
  class Plugin
    def handles_encoding?; true; end

    def compile(template, source)
      options = Haml::Template.options.dup
      if template.respond_to?(:type)
        options[:mime_type] = template.type
      elsif template.respond_to? :mime_type
        options[:mime_type] = template.mime_type
      end
      options[:filename] = template.identifier
      Haml::Engine.new(source, options).compiler.precompiled_with_ambles(
        [],
        after_preamble: '@output_buffer = output_buffer ||= ActionView::OutputBuffer.new if defined?(ActionView::OutputBuffer)',
      )
    end

    def self.call(template, source = nil)
      source ||= template.source

      new.compile(template, source)
    end

    def cache_fragment(block, name = {}, options = nil)
      @view.fragment_for(block, name, options) do
        eval("_hamlout.buffer", block.binding)
      end
    end
  end
end

ActionView::Template.register_template_handler(:haml, Haml::Plugin)

Version data entries

28 entries across 25 versions & 3 rubygems

Version Path
brakeman-5.1.1 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
brakeman-5.1.0 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
brakeman-5.0.4 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
brakeman-5.0.2 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
brakeman-5.0.1 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
brakeman-5.0.0 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
brakeman-4.10.1 bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/plugin.rb
haml-5.2.1 lib/haml/plugin.rb
brakeman-5.0.0.pre1 bundle/ruby/2.7.0/gems/haml-5.2.0/lib/haml/plugin.rb
brakeman-4.10.0 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/plugin.rb
haml-5.2.0 lib/haml/plugin.rb
brakeman-4.9.1 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/plugin.rb
brakeman-4.9.0 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/plugin.rb
brakeman-4.8.2 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/plugin.rb
brakeman-4.8.1 bundle/ruby/2.4.0/gems/haml-5.1.2/lib/haml/plugin.rb
brakeman-4.8.0 bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/plugin.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.0/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/plugin.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.1/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/plugin.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.2/bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/plugin.rb
brakeman-4.7.2 bundle/ruby/2.6.0/gems/haml-5.1.2/lib/haml/plugin.rb