Skip to content

Commit

Permalink
Add generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kawakamimoeki committed Oct 13, 2024
1 parent dda3a6b commit cf7f069
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ mount Clapton::Engine => "/clapton"

![TODO APP DEMO](./docs/todo-app-demo.gif)

### Generate Component and State

```bash
rails generate clapton TaskList
```

After running the generator, you will see the following files:

- `app/components/task_list_component.rb`
- `app/states/task_list_state.rb`

### Preset Components

```ruby
Expand Down
1 change: 1 addition & 0 deletions lib/clapton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "clapton/state"
require "clapton/test_helper/rspec"
require "clapton/test_helper/minitest"
require "rails/generators/clapton_generator"

module Clapton
end
21 changes: 21 additions & 0 deletions lib/rails/generators/clapton_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Rails
module Generators
class ClaptonGenerator < Rails::Generators::NamedBase
def create_component_file
create_file "app/components/#{file_name}_component.rb" do
<<~RUBY
class #{class_name}Component < Clapton::Component
end
RUBY
end

create_file "app/states/#{file_name}_state.rb" do
<<~RUBY
class #{class_name}State < Clapton::State
end
RUBY
end
end
end
end
end

0 comments on commit cf7f069

Please sign in to comment.