class Haml::Plugin
This module makes Haml
work with Rails using the template handler API.
Attributes
annotate_rendered_view_with_filenames[RW]
Public Class Methods
call(template, source = nil)
click to toggle source
# File lib/haml/plugin.rb, line 40 def self.call(template, source = nil) source ||= template.source new.compile(template, source) end
Public Instance Methods
cache_fragment(block, name = {}, options = nil)
click to toggle source
# File lib/haml/plugin.rb, line 46 def cache_fragment(block, name = {}, options = nil) @view.fragment_for(block, name, options) do eval("_hamlout.buffer", block.binding) end end
compile(template, source)
click to toggle source
# File lib/haml/plugin.rb, line 14 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 preamble = '@output_buffer = output_buffer ||= ActionView::OutputBuffer.new if defined?(ActionView::OutputBuffer);' postamble = '' if self.class.annotate_rendered_view_with_filenames # short_identifier is only available in Rails 6+. On older versions, 'inspect' gives similar results. ident = template.respond_to?(:short_identifier) ? template.short_identifier : template.inspect preamble += "haml_concat '<!-- BEGIN #{ident} -->'.html_safe;" postamble += "haml_concat '<!-- END #{ident} -->'.html_safe;" end Haml::Engine.new(source, options).compiler.precompiled_with_ambles( [], after_preamble: preamble, before_postamble: postamble ) end
handles_encoding?()
click to toggle source
# File lib/haml/plugin.rb, line 12 def handles_encoding?; true; end