Class: Hamlit::RailsTemplate

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.optionsObject


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

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

.set_options(opts) ⇒ Object


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

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

Instance Method Details

#call(template, source = nil) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hamlit/rails_template.rb', line 26

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

  # 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

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

#supports_streaming?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/hamlit/rails_template.rb', line 39

def supports_streaming?
  RailsTemplate.options[:streaming]
end