From 058e19e26cede7fec2512be01e7ba92f5d987d8d Mon Sep 17 00:00:00 2001 From: Cirdes Henrique Date: Sat, 10 May 2025 18:34:28 -0300 Subject: [PATCH 1/5] 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. --- README.md | 2 ++ .../ruby_ui/component/all_generator.rb | 24 +++++++++++++++++++ lib/generators/ruby_ui/component_generator.rb | 3 ++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lib/generators/ruby_ui/component/all_generator.rb diff --git a/README.md b/README.md index 94335863..8cfca6f4 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ You can generate your components using `ruby_ui:component` generator. bin/rails g ruby_ui:component Accordion ``` +You also can generate all components using `ruby_ui:component:all` generator + ## Documentation 📖 Visit https://rubyui.com/docs/introduction to view the full documentation, including: diff --git a/lib/generators/ruby_ui/component/all_generator.rb b/lib/generators/ruby_ui/component/all_generator.rb new file mode 100644 index 00000000..b424bec1 --- /dev/null +++ b/lib/generators/ruby_ui/component/all_generator.rb @@ -0,0 +1,24 @@ +module RubyUI + module Generators + module Component + class AllGenerator < Rails::Generators::Base + + namespace "ruby_ui:component:all" + + source_root File.expand_path("../../../ruby_ui", __dir__) + + def generate_components + say "Generating all components..." + + Dir.children(self.class.source_root).each do |folder_name| + puts "folder_name: #{folder_name}" + next if folder_name == "base.rb" + + component_name = folder_name.camelize + run "bin/rails generate ruby_ui:component #{component_name} --force true" + end + end + end + end + end +end diff --git a/lib/generators/ruby_ui/component_generator.rb b/lib/generators/ruby_ui/component_generator.rb index cef55cb6..205b330f 100644 --- a/lib/generators/ruby_ui/component_generator.rb +++ b/lib/generators/ruby_ui/component_generator.rb @@ -8,6 +8,7 @@ class ComponentGenerator < Rails::Generators::Base source_root File.expand_path("../../ruby_ui", __dir__) argument :component_name, type: :string, required: true + class_option :force, type: :boolean, default: false def generate_component if component_not_found? @@ -23,7 +24,7 @@ def copy_related_component_files components_file_paths.each do |file_path| component_file_name = file_path.split("/").last - copy_file file_path, Rails.root.join("app/components/ruby_ui", component_folder_name, component_file_name) + copy_file file_path, Rails.root.join("app/components/ruby_ui", component_folder_name, component_file_name), force: options["force"] end end From 5351b8bcf7408709dae7d964cb5c8bb35ae7f7f4 Mon Sep 17 00:00:00 2001 From: Cirdes Henrique Date: Sun, 11 May 2025 12:26:29 -0300 Subject: [PATCH 2/5] fix linter --- lib/generators/ruby_ui/component/all_generator.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/generators/ruby_ui/component/all_generator.rb b/lib/generators/ruby_ui/component/all_generator.rb index b424bec1..e5c09612 100644 --- a/lib/generators/ruby_ui/component/all_generator.rb +++ b/lib/generators/ruby_ui/component/all_generator.rb @@ -2,7 +2,6 @@ module RubyUI module Generators module Component class AllGenerator < Rails::Generators::Base - namespace "ruby_ui:component:all" source_root File.expand_path("../../../ruby_ui", __dir__) From 2ce49afd0189e2b3446ce4aea55b4267d5af6625 Mon Sep 17 00:00:00 2001 From: Cirdes Henrique Date: Sun, 11 May 2025 12:35:31 -0300 Subject: [PATCH 3/5] add force option to all generators --- lib/generators/ruby_ui/component_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/ruby_ui/component_generator.rb b/lib/generators/ruby_ui/component_generator.rb index 205b330f..7035e255 100644 --- a/lib/generators/ruby_ui/component_generator.rb +++ b/lib/generators/ruby_ui/component_generator.rb @@ -35,7 +35,7 @@ def copy_js_files js_controller_file_paths.each do |file_path| controller_file_name = file_path.split("/").last - copy_file file_path, Rails.root.join("app/javascript/controllers/ruby_ui", controller_file_name) + copy_file file_path, Rails.root.join("app/javascript/controllers/ruby_ui", controller_file_name), force: options["force"] end # Importmap doesn't have controller manifest, instead it uses `eagerLoadControllersFrom("controllers", application)` @@ -69,7 +69,7 @@ def js_controller_file_paths = Dir.glob(File.join(component_folder_path, "*.js") def install_components_dependencies(components) components&.each do |component| - run "bin/rails generate ruby_ui:component #{component}" + run "bin/rails generate ruby_ui:component #{component} --force #{options["force"]}" end end From e5c6605e2346c77b0d86670b40cb4b9453244ef0 Mon Sep 17 00:00:00 2001 From: Cirdes Henrique Date: Mon, 12 May 2025 19:01:08 -0300 Subject: [PATCH 4/5] Change all generator to use force option --- lib/generators/ruby_ui/component/all_generator.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/generators/ruby_ui/component/all_generator.rb b/lib/generators/ruby_ui/component/all_generator.rb index e5c09612..b0c9ba9b 100644 --- a/lib/generators/ruby_ui/component/all_generator.rb +++ b/lib/generators/ruby_ui/component/all_generator.rb @@ -5,16 +5,15 @@ class AllGenerator < Rails::Generators::Base namespace "ruby_ui:component:all" source_root File.expand_path("../../../ruby_ui", __dir__) + class_option :force, type: :boolean, default: false def generate_components say "Generating all components..." Dir.children(self.class.source_root).each do |folder_name| - puts "folder_name: #{folder_name}" - next if folder_name == "base.rb" + next if folder_name.ends_with?(".rb") - component_name = folder_name.camelize - run "bin/rails generate ruby_ui:component #{component_name} --force true" + run "bin/rails generate ruby_ui:component #{folder_name} --force #{options["force"]}" end end end From 87863bd5ac921a28e462066bef6cae71de2040a6 Mon Sep 17 00:00:00 2001 From: Cirdes Henrique Date: Mon, 12 May 2025 19:05:44 -0300 Subject: [PATCH 5/5] Add 3.4 to CI and remove head I was getting a segmentation fault when running the tests on head --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed1f3ac7..a6de74e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["3.3", "head"] + ruby: ["3.3", "3.4"] steps: - uses: actions/checkout@v4