Skip to content

Commit 1a21bdb

Browse files
authored
Add generator for all components (#289)
* Add generator for all components Add a new generator that allows users to generate all components at once using the command `bin/rails g ruby_ui:component:all`. This makes it easier for users who want to install the complete set of components without having to run individual commands for each component. In my notebook, it's tanking 1m 3s to generate all components. We can improve this but i tried to keep the same approach as the component generator to make it easier to maintain. * fix linter * add force option to all generators * Change all generator to use force option * Add 3.4 to CI and remove head I was getting a segmentation fault when running the tests on head
1 parent f5a275f commit 1a21bdb

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
ruby: ["3.3", "head"]
16+
ruby: ["3.3", "3.4"]
1717

1818
steps:
1919
- uses: actions/checkout@v4

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ You can generate your components using `ruby_ui:component` generator.
5555
bin/rails g ruby_ui:component Accordion
5656
```
5757

58+
You also can generate all components using `ruby_ui:component:all` generator
59+
5860
## Documentation 📖
5961

6062
Visit https://rubyui.com/docs/introduction to view the full documentation, including:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module RubyUI
2+
module Generators
3+
module Component
4+
class AllGenerator < Rails::Generators::Base
5+
namespace "ruby_ui:component:all"
6+
7+
source_root File.expand_path("../../../ruby_ui", __dir__)
8+
class_option :force, type: :boolean, default: false
9+
10+
def generate_components
11+
say "Generating all components..."
12+
13+
Dir.children(self.class.source_root).each do |folder_name|
14+
next if folder_name.ends_with?(".rb")
15+
16+
run "bin/rails generate ruby_ui:component #{folder_name} --force #{options["force"]}"
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end

lib/generators/ruby_ui/component_generator.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ComponentGenerator < Rails::Generators::Base
88

99
source_root File.expand_path("../../ruby_ui", __dir__)
1010
argument :component_name, type: :string, required: true
11+
class_option :force, type: :boolean, default: false
1112

1213
def generate_component
1314
if component_not_found?
@@ -23,7 +24,7 @@ def copy_related_component_files
2324

2425
components_file_paths.each do |file_path|
2526
component_file_name = file_path.split("/").last
26-
copy_file file_path, Rails.root.join("app/components/ruby_ui", component_folder_name, component_file_name)
27+
copy_file file_path, Rails.root.join("app/components/ruby_ui", component_folder_name, component_file_name), force: options["force"]
2728
end
2829
end
2930

@@ -34,7 +35,7 @@ def copy_js_files
3435

3536
js_controller_file_paths.each do |file_path|
3637
controller_file_name = file_path.split("/").last
37-
copy_file file_path, Rails.root.join("app/javascript/controllers/ruby_ui", controller_file_name)
38+
copy_file file_path, Rails.root.join("app/javascript/controllers/ruby_ui", controller_file_name), force: options["force"]
3839
end
3940

4041
# Importmap doesn't have controller manifest, instead it uses `eagerLoadControllersFrom("controllers", application)`
@@ -68,7 +69,7 @@ def js_controller_file_paths = Dir.glob(File.join(component_folder_path, "*.js")
6869

6970
def install_components_dependencies(components)
7071
components&.each do |component|
71-
run "bin/rails generate ruby_ui:component #{component}"
72+
run "bin/rails generate ruby_ui:component #{component} --force #{options["force"]}"
7273
end
7374
end
7475

0 commit comments

Comments
 (0)