View Component sidecar generator

Curated ago by @pedroaugustorduarte

Description

rails g view_component NomeDoComponente

with stimulus:

rails g view_component NomeDoComponente –stimulus

File:
- component.html.erb html for the component
- component.rb ruby code for internal component logic
- preview.rb preview for lookbook
- /spec/component_spec.rb spec for component with rspec

1
2
3
4
5
6
7
8
9
# frozen_string_literal: true

class <%= class_name %>::Preview < <%= preview_parent_class %>
  layout 'view_component_layout'

  def default
    render(<%= class_name %>::Component.new<%= "(#{render_signature})" if render_signature %>)
  end
end