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
10
11
12
13
14
Description:
============
    Creates a new view component, test and preview files.
    Pass the component name, either CamelCased or under_scored, and an optional list of attributes as arguments.

Example:
========
    bin/rails generate view_component Profile name age

    creates a Profile component and test:
        Component:    app/frontend/components/profile/component.rb
        Template:     app/frontend/components/profile/component.html.erb
        Test:         spec/frontend/components/profile_component_spec.rb
        Preview:      app/frontend/components/profile/component_preview.rb