Closed kmurph73 closed 8 years ago
I'd like to use haml_tag in a Rails helper ... however haml_tag, along with many other methods, are not implemented in https://github.com/k0kubun/hamlit/blob/master/lib/hamlit/helpers.rb
It'd be good to see https://github.com/k0kubun/hamlit/blob/v2.5.0/lib/hamlit/rails_helpers.rb too. Hamlit::Helpers
is for both Sinatra and Rails, Hamlit::RailsHelpers
is only for Rails.
is there a way to use the helpers in https://github.com/k0kubun/hamlit/blob/master/lib/hamlit/parser/haml_helpers.rb in our Rails app, or is this not possible due to the performant design of Hamlit?
You shouldn't use Hamlit::HamlHelpers
as an alternative of Haml::Helpers
.
As written in https://github.com/k0kubun/hamlit/blob/master/REFERENCE.md#haml-helpers-are-still-in-development, some of these helpers require Haml::Buffer
. Since Hamlit's compiled code does not have Haml::Buffer
, Hamlit::HamlHelpers
won't work and some methods can't be implemented without it.
Try hamlit compile
and haml -d
. https://github.com/k0kubun/hamlit#command-line-interface
I think we can add more helpers without Haml::Buffer
, but personally I don't use the ones not implemented.
I'd like to use haml_tag in a Rails helper
The reason why haml_tag is not implemented is not performance but the tight coupling to Haml's internal. It's just difficult to port to Hamlit. https://github.com/haml/haml/blob/4.0.6/lib/haml/helpers.rb#L459-L518 But I'll reconsider it later.
Thanks for the pointer to the RailsHelpers
... essentially I'm looking for the functionality of haml_tag_if
, as I'd like to conditionally nest some HAML under a div
.
In the meantime I just converted the partial to erb, which works well enough.
Well, I'm dumb. Rather than conditionally wrap some html in a div
I just optionally wrapped it in an empty div, which has the same effect. Thank you for your help.
eg:
%div{class: child ? 'child' : ''}
in my usecase I actually need haml_tag_if
:c
any pointers?
It's no longer even part of haml.gem from v6 and going forward. For a template engine to maintain natural interface and performance, it shouldn't be a template engine's responsibility to define helpers. You should ask any web framework you're using to define such helpers on view context classes or just define it as a helper method yourself. On Rails, for example, content_tag
could be used as a way to construct a tag, and you can define any wrapper of it to provide any convenient functions.
yes, I found the solution - link_to_if
from ruby is the right function here :)
Does hamlit make a relevant difference anymore? It seems that the original haml implementation is also using temple now?
Haml 6 became a Hamlit-based implementation, so it's intended that there's no difference going forward. I intend to maintain both, so it's safe to use either of those for now, but if you wish, you should be able to switch back to Haml 6 with no issue.
Now that it's been a month since we cut a beta release of Haml 6, reminded by your comment, I've just made an official Haml 6 release.
I'd like to use
haml_tag
in a Rails helper ... howeverhaml_tag
, along with many other methods, are not implemented in https://github.com/k0kubun/hamlit/blob/master/lib/hamlit/helpers.rb ... is there a way to use the helpers in https://github.com/k0kubun/hamlit/blob/master/lib/hamlit/parser/haml_helpers.rb in our Rails app, or is this not possible due to the performant design of Hamlit?Thank you for Hamlit and any help.