k0kubun / hamlit

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

Exec HAMLIT command into rails #107

Closed francesco-loreti closed 7 years ago

francesco-loreti commented 7 years ago

HI! Is it possible to implement the possibility to execute the HAMLIT commands into rails application? Because, for example, I can render a template from command line out of rails program("hamlit rendere filename.html.haml") but not inside application or into rails console.

Thanks

k0kubun commented 7 years ago

I couldn't understand your intention. Could you provide example use case with following things?


For example,

Haml template source code

example.haml:

%foo

Command to execute

$ hamlit render example.haml

stdout, stderr and exit status

stdout

<div class='foo'></div>

stderr

exit status

0


And as you may know, example above is already implemented. So I want some other Rails-specific use case that can't be done with it.

Thanks.

francesco-loreti commented 7 years ago

If I use ERB I can user ERB.new for render inside my application an erb file. More or less as http://blog.revathskumar.com/2014/10/ruby-rendering-erb-template.html

In HAMLIT is it possible?

k0kubun commented 7 years ago

Possible. Sorry for poor documentation.

foo = "hello world"
ERB.new("<%= foo %>").result(binding) #=> "hello world"

is the same as:

foo = "hello world"
eval(Hamlit::Engine.new.call("= foo"), binding) #=> "hello world"

and:

Hamlit::Template.new { "= foo" }.render(nil, { foo: "hello world" }) #=> "hello world"