k0kubun / hamlit

High Performance Haml Implementation
https://rubygems.org/gems/hamlit
Other
981 stars 59 forks source link

Unable to render a partial #78

Closed snowmac closed 8 years ago

snowmac commented 8 years ago

So I need to render a parital and the code I use to generate the HTML when it's the Haml engine is:

Haml::Engine.new(partial).render(self, options)

What would be the code for Hamlit?

k0kubun commented 8 years ago

It'd be based on what kind of things you're passing by partial, self and options. For most cases, especially for non-rails environment, you want Hamlit::Template.

[1] pry(main)> partial = ".foo\n = b + c"
=> ".foo\n = b + c"
[2] pry(main)> def b; 'hello '; end
=> :b
[3] pry(main)> Haml::Engine.new(partial, ugly: true, attr_wrapper: '"').render(self, c: 'world')
=> "<div class=\"foo\">\nhello world\n</div>\n"
[4] pry(main)> Hamlit::Template.new(attr_quote: '"') { partial }.render(self, c: 'world')
=> "<div class=\"foo\">\nhello world\n</div>\n"
snowmac commented 8 years ago

Thank you. Doing that as a template renders it as a html string, but when I render it to the browser, its a string of html not the ui view. How do I fix that?

k0kubun commented 8 years ago

I couldn't understand what you mean and want to do. If you're building web app, what framework do you use?

See https://github.com/k0kubun/hamlit/blob/master/REFERENCE.md for Rails or Sinatra. Otherwise, you should use Tilt interface.

k0kubun commented 8 years ago

when I render it to the browser, its a string of html not the ui view

I guess there're two possibilities.

  1. Some parts of elements you want to render are HTML-escaped
    • One of biggest difference between Haml and Hamlit is that Hamlit HTML-escapes Ruby scripts.
    • Try Hamlit::Template.new(escape_html: false) { partial }.render(self, {})
  2. Don't you set a response header "Content-Type: text/html;"?
    • It's not related to Hamlit, though.
k0kubun commented 8 years ago

Closing for now. Feel free to reopen this issue if you still have a problem.