Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Rails' String#html_safe #10

Open
dlee opened this issue Sep 27, 2012 · 1 comment
Open

Support for Rails' String#html_safe #10

dlee opened this issue Sep 27, 2012 · 1 comment

Comments

@dlee
Copy link

dlee commented Sep 27, 2012

It would be nice if there was support for Rails' String#html_safe to be treated the same way as Handlebars::SafeString.

@blairanderson
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants