Module: AmberComponent::TemplateHandler

Defined in:
lib/amber_component/template_handler.rb

Overview

Provides code which handles rendering different template languages outside of Rails.

Class Method Summary collapse

Class Method Details

.render_from_string(context, content, type, block = nil) ⇒ String

Parameters:

  • context (AmberComponent::Base)
  • content (String)
  • type (Symbol, String)
  • block (Proc, nil) (defaults to: nil)

Returns:

  • (String)

Raises:



13
14
15
16
17
18
19
20
21
22
# File 'lib/amber_component/template_handler.rb', line 13

def render_from_string(context, content, type, block = nil)
  tilt_handler = ::Tilt[type]
  raise UnknownViewTypeError, <<~ERR.squish unless tilt_handler
    Unknown view type for `#{context.class}`!
    Check return value of param type in `view type: :[type]`
    or the view file extension.
  ERR

  tilt_handler.new { content }.render(context, &block).html_safe
end