ViewComponent / demo

Rails application with ViewComponent
MIT License
157 stars 15 forks source link

Add support to render components with sidecar template files #11

Closed joelhawksley closed 5 years ago

cgriego commented 5 years ago

One of the stated hopes for components was to address the testability and code coverage measurability of these reusable view objects. That hadn't been addressed really, but this feels like a step away from it. Using helpers like content_tag inside the Ruby class could work, but what about exposing Builder or something like it to construct HTML inside the class? And there could also be a render method available inside the class to render template files to a developer's heart's content.

joelhawksley commented 5 years ago

@cgriego this PR doesn't affect the testability, it simply changes the source of the template string.

That hadn't been addressed really

Can you be more specific? We're able to unit test components now, and are able to at least audit what methods on the component have been called.

I'd love to see a sample implementation using content_tag and the associated benchmarks!

tomasc commented 5 years ago

@cgriego I am using components with the content_tag for quite some time. There is nothing difficult about that – those can be simple PORO classes.

I think the appeal of @joelhawksley approach is the possibility to use simplified (shorter, more HTML-like) markup – be it .html.erb or .slim or whatever – and take benefit of standard Rails-y things such as fragment caching.

The missing piece in my opinion are CSS/JS assets located in the same folder as the component, and perhaps even some mechanism for their namespacing.