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 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..b0c9ba9b --- /dev/null +++ b/lib/generators/ruby_ui/component/all_generator.rb @@ -0,0 +1,22 @@ +module RubyUI + module Generators + module Component + 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| + next if folder_name.ends_with?(".rb") + + run "bin/rails generate ruby_ui:component #{folder_name} --force #{options["force"]}" + 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..7035e255 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 @@ -34,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)` @@ -68,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