k0kubun / hamlit

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

Support for Third Party Component Libraries (ViewComponent) #156

Closed mc962 closed 4 years ago

mc962 commented 4 years ago

Will there be any issues with Hamlit supporting Third Party Component libraries such as github's view_component library?

I have been looking at hamlit for a project, while also following recent Rails developments concerning integrating third-party component libraries such as described in the https://github.com/rails/rails/pull/36388 PR.

From reading the description of both the Rails PR and view_component, it seems like they will support haml, and it seems like in general if haml is supported then hamlit will be supported. But I want to confirm if there might be issues with integrating hamlit with component libraries, when they are supported/released in Rails.

k0kubun commented 4 years ago

Looking at TestComponent in https://github.com/rails/rails/pull/36388, that seems totally feasible.

In that example, I think it should work by just changing ActionView::Template::Handlers::ERB.erb_implementation.new(template, trim: true).src to Hamlit::RailsTemplate.call(template).

Let me close this as I'm still not sure what should be done in hamlit.gem side, but please reopen this if you have ideas of things to be done here.

mc962 commented 4 years ago

I'm not sure what may have been updated in the 6 or so months since this issue was opened, but I just tried to make ViewComponent with a project that uses hamlit, and it seemed to render/behave fine.

It was a limited, initial test, so there might be unknown issues that I have not yet come across, but it seems like ViewComponent is cooperating fine with hamlit these days, with just following the instructions to install from ViewComponent's page.

joevandyk commented 2 years ago

I'm trying to use haml_tag inside a viewcomponent template and getting undefined method 'haml_tag' errors

(didn't get the error with haml)

k0kubun commented 2 years ago

It's intentional that Hamlit doesn't offer most of Haml's helpers like haml_tag. REFERENCE.md says it's under development, but it's actually a wont-fix at this point. If you're using Rails, you should be able to use content_tag. Even if it doesn't work or even exist, you should be able to define such a helper or look for such a gem yourself. Helpers in a rendering context are something template engines shouldn't care about, e.g. Slim and ERB don't, because it requires monkey-patching to achieve it with Ruby code compiled from a template. It should be the responsibility of other libraries at a proper layer.

(didn't get the error with haml)

Note that Haml is going to remove haml_tag too. If you use the main branch of haml/haml, you cannot use haml_tag.