Class: Rack::Component::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/component/renderer.rb

Overview

Compile a Tilt template, which a component will render

Constant Summary collapse

DEFAULT_TILT_OPTIONS =
{ escape_html: true }.freeze
FORMATS =
i[erb rhtml erubis haml liquid markdown md mkd].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Renderer

Returns a new instance of Renderer.



8
9
10
11
12
13
# File 'lib/rack/component/renderer.rb', line 8

def initialize(options = {})
  require 'tilt'
  engine, template, @config = OptionParser.call(options)
  require 'erubi' if engine == 'erb' && @config[:escape_html]
  @template = Tilt[engine].new(@config) { template }
end

Instance Method Details

#call(scope, &child) ⇒ Object



15
16
17
# File 'lib/rack/component/renderer.rb', line 15

def call(scope, &child)
  @template.render(scope, &child)
end