18 lines
371 B
Ruby
18 lines
371 B
Ruby
|
class HandlebarsRenderer
|
||
|
attr_reader :handlebars
|
||
|
def initialize
|
||
|
@handlebars = Handlebars::Handlebars.new
|
||
|
end
|
||
|
|
||
|
def render(template_string, bindings)
|
||
|
template = handlebars.compile(sanitize_template(template_string))
|
||
|
template.call(bindings)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def sanitize_template(template_string)
|
||
|
template_string.gsub('{{# if', '{{#if')
|
||
|
end
|
||
|
end
|