With web components coming to browsers soon and most JavaScript MV*s already using them, it seemed the right time to figure out how to do this in Rails. We can do this by making extensive use of partials.
In Handlebars, components can be inline or block form by creating them with or without a {{yield}}
respectively. Rails has the same configuration. The differences are how the partial is added to the view and how locals are passed to it.
In this gist, I have created a component generator. This will create the Slim and SCSS files for your component and update a SCSS file (a pattern I have used at work) with the correct @import
. The command for doing this is:
Inline component:
rails generate component <NAME>
Block component: