trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.06k stars 236 forks source link

how to render erb templates when haml/hamlit and erb extensions installed #467

Closed nruth closed 6 years ago

nruth commented 6 years ago

With cells-erb my templates render as needed, but I want to be able to have haml templates too. When I also install cells-haml or cells-hamlit I get errors like

Template missing: view: `topics.haml` prefixes: ["app/concepts/dashboard/view"]

Which is understandable, because the topics template is topics.erb. I can't see how to tell the cell or override render so that it looks for an erb file instead. Is this supported or explained somewhere outside the cells website docs?

nruth commented 6 years ago

It looks like this isn't supported and I'm not going to be able to implement it so closing.

apotonick commented 6 years ago

It is possible by include Cell::Haml into your cell class. The only problem is that cells-rails might get in your way here because of our automatic behavior: https://github.com/trailblazer/cells-rails/blob/master/lib/cell/railtie.rb#L63 I am strongly voting for deprecating this in favor of Application::Cell where you have to do this manually, or some more explicit mechnism.

nruth commented 6 years ago

Thanks for looking at this. It is a (legacy) rails app so that railtie behaviour looks like it's probably the cause.

My class definition was like this:

module Dashboard
  module Cell
    class Topics < Trailblazer::Cell
      include ::Cell::Erb

    ... bunch of refactored methods
    end
  end
end

Removing the ham(lit) gem made it render the erb template but I didn't have success overriding the options or suffix methods/properties in my cell.

I'm subclassing Trailblazer::Cell because I wanted to use the not-deprecated file paths described in http://trailblazer.to/gems/cells/trailblazer.html

I got round this by just not mixing template types, but an explicit mechanism for this sounds good.