class Slimi::RailsTemplateHandler::Renderer

Render HTML from given source and options.

Public Class Methods

new( source:, template: ) click to toggle source

@param [String] source @param [ActionView::Template] template

# File lib/slimi/rails_template_handler.rb, line 20
def initialize(
  source:,
  template:
)
  @source = source
  @template = template
end

Public Instance Methods

call() click to toggle source

@return [String]

# File lib/slimi/rails_template_handler.rb, line 29
def call
  engine.call(source)
end

Private Instance Methods

engine() click to toggle source

@return [Slimi::Engine]

# File lib/slimi/rails_template_handler.rb, line 36
def engine
  Engine.new(engine_options)
end
engine_amble_options() click to toggle source

@return [Hash{Symbol => Object}]

# File lib/slimi/rails_template_handler.rb, line 55
def engine_amble_options
  if with_annotate_rendered_view_with_filenames?
    {
      postamble: "<!-- END #{@template.short_identifier} -->\n",
      preamble: "<!-- BEGIN #{@template.short_identifier} -->\n"
    }
  else
    {}
  end
end
engine_default_options() click to toggle source

@return [Hash{Symbol => Object}]

# File lib/slimi/rails_template_handler.rb, line 46
def engine_default_options
  {
    generator: ::Temple::Generators::RailsOutputBuffer,
    streaming: true,
    use_html_safe: true
  }
end
engine_options() click to toggle source

@return [Hash{Symbol => Object}]

# File lib/slimi/rails_template_handler.rb, line 41
def engine_options
  engine_default_options.merge(engine_amble_options)
end
source() click to toggle source

@return [String]

# File lib/slimi/rails_template_handler.rb, line 67
def source
  @source || @template.source
end
with_annotate_rendered_view_with_filenames?() click to toggle source

@return [Boolean]

# File lib/slimi/rails_template_handler.rb, line 72
def with_annotate_rendered_view_with_filenames?
  ::ActionView::Base.try(:annotate_rendered_view_with_filenames) && @template.format == :html
end