Open dlee opened 12 years ago
i also wanted this because i'm trying to share data between the frontend and these handlebars templates.
In my rails app i created initializers/handlebars.rb
(a dirty monkeypatch, i know)
module Handlebars
class SafeString
def self.new(string)
if context = Context.current
context.handlebars['SafeString'].new(string)
else
string.html_safe
end
end
end
end
then with the data:
def procs_to_html_safe(data)
data.each_with_object({}){|(k, v), result| (v.class.to_s == 'Proc') ? result[k] = v.call : result[k] = v}
end
It would be nice if there was support for Rails' String#html_safe to be treated the same way as Handlebars::SafeString.