3 ms·
I maintain a collection of view components[0] and lots are built without a template, just using the Rails tag helpers directly[1]. They're easy to write, famili
by petepete 4y ago
I maintain a collection of view components[0] and lots are built without a template, just using the Rails tag helpers directly[1]. They're easy to write, familiar to any Rails dev and very fast.
[0] https://govuk-components.netlify.app/ https://govuk-components.netlify.app/
[1] https://github.com/DFE-Digital/govuk-components/blob/main/app/components/govuk_component/pagination_component.rb#L68 https://github.com/DFE-Digital/govuk-components/blob/main/ap...
- caseyf 4y agoI do this as well. Our design system in-progress has 32 components and only 3 are rendered with templates. They are fast and easy to write and easy to modify for sure. I wouldn't mind having the code look more like the output (without a template) but it's not something I've been missing...
- zem 4y agointeresting approach, thanks for sharing it!
- andrei_says_ 4y agoAm I understanding correctly that there’s a significant difference in performance between using a ViewComponent + a partial vs. a ViewComponent which renders html via a tag - from inside the component? Don’t partials get compiled when used from a ViewComponent? Also - the gov.uk project makes my heart sing ;)
- petepete 4y ago> Am I understanding correctly that there’s a significant difference in performance between using a ViewComponent + a partial vs. a ViewComponent which renders html via a tag - from inside the component? I don't think there will be much difference at all in everyday use, but some libraries that value performance don't avoid templates for that reason, Pagy for example. https://github.com/ddnexus/pagy https://github.com/ddnexus/pagy Personally I omit them in my projects whenever we want to customise attributes, I hate seeing stuff like this in templates: <h2 class="<%= heading_classes %>" id="<%= heading_id %>">Some header</h2> I'd much rather see: <%= tag.h2("Some header", class: heading_classes, id: heading_id) %> And as lots of the components allow attributes to be customised, using the tag helpers directly seems like a good choice. > Also - the gov.uk project makes my heart sing ;) Thanks :) Although I just reimplement the components and forms in Rails, the proper hard work is done upstream.