Ways to reduce boilerplate? #408
-
Overall we love what = render(ButtonComponent.new(:primary, :inverse, type: :submit)) What we'll probably do is drop the = render(Button, :primary, :inverse, type: :submit) Or if we want to keep the component named = render('button', :primary, :inverse, type: :submit) We might end up monkey patching |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You could create a
|
Beta Was this translation helpful? Give feedback.
-
I've created this helper. I don't know if its 100% bullet proof, tho. Any thoughts @jaredcwhite? module ComponentsHelper
# Shorthand for rendering view_components
#
# Usage:
#
# <%= component :section, title: 'Greeting', classes: 'my--1' do %>
# <p class="Txt--center">Hello world</p>
# <% end %>
def component(name, *args, &block)
component_class = "#{name.to_s.camelcase}::Component".constantize
render_component(component_class.new(*args), &block)
end
ruby2_keywords :component
end <%= component :section, title: 'Greeting', classes: 'my--1' do %> should equal <%= render_component Section::Component.new(title: 'Greeting', classes: 'my--1') do %> |
Beta Was this translation helpful? Give feedback.
I've created this helper. I don't know if its 100% bullet proof, tho. Any thoughts @jaredcwhite?
should equal