Class: Haml::RailsTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/haml/rails_template.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.options



11
12
13
14
15
16
17
18
19
# File 'lib/haml/rails_template.rb', line 11

def options
  @options ||= {
    generator:     Temple::Generators::RailsOutputBuffer,
    use_html_safe: true,
    streaming:     true,
    buffer_class:  'ActionView::OutputBuffer',
    disable_capture: true,
  }
end

.set_options(opts)



21
22
23
# File 'lib/haml/rails_template.rb', line 21

def set_options(opts)
  options.update(opts)
end

Instance Method Details

#call(template, source = nil)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/haml/rails_template.rb', line 26

def call(template, source = nil)
  source ||= template.source
  options = RailsTemplate.options

  # Make the filename available in parser etc.
  if template.respond_to?(:identifier)
    options = options.merge(filename: template.identifier)
  end

  # https://github.com/haml/haml/blob/4.0.7/lib/haml/template/plugin.rb#L19-L20
  # https://github.com/haml/haml/blob/4.0.7/lib/haml/options.rb#L228
  if template.respond_to?(:type) && template.type == 'text/xml'
    options = options.merge(format: :xhtml)
  end

  if ActionView::Base.try(:annotate_rendered_view_with_filenames) && template.format == :html
    options = options.merge(
      preamble: "<!-- BEGIN #{template.short_identifier} -->\n",
      postamble: "<!-- END #{template.short_identifier} -->\n",
    )
  end

  Engine.new(options).call(source)
end

#supports_streaming?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/haml/rails_template.rb', line 51

def supports_streaming?
  RailsTemplate.options[:streaming]
end