Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.3", "head"]
ruby: ["3.3", "3.4"]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions lib/generators/ruby_ui/component/all_generator.rb
Original file line number Diff line number Diff line change
@@ -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|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do something like Dir.glob("path/to/ruby_ui/*/") you will get ruby_ui folders, then you won't need to do next if folder_name == "base.rb".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It started to return the full path. I decided to check if the string ends_with?(".rb") to make it more generic and robust

folder_name: /Users/cirdes/Workspace/ruby-ui/ruby_ui/lib/ruby_ui/accordion/

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
7 changes: 4 additions & 3 deletions lib/generators/ruby_ui/component_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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

Expand All @@ -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)`
Expand Down Expand Up @@ -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

Expand Down
Loading