Skip to content

Commit 4f41cf9

Browse files
sethhorsleycirdes
andauthored
Ruby UI refactor (#179)
* RBUI -> RubyUI * rbui -> ruby_ui * fix rails version for phlex 2 * fix checkbox --------- Co-authored-by: Cirdes Henrique <cirdes@linkana.com>
1 parent 5519a5f commit 4f41cf9

250 files changed

Lines changed: 1473 additions & 1367 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2024 RBUI
3+
Copyright (c) 2024 RubyUI
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# RBUI (former PhlexUI) 🚀
1+
# RubyUI (former PhlexUI) 🚀
22

33
A UI component library, crafted precisely for Ruby devs who want to stay organized and build modern apps, fast. ✨
44
**Use this to build your own component library** 🛠️
55

6-
## About RBUI 📚
6+
## About RubyUI 📚
77

8-
RBUI is a UI component library designed to let Ruby developers create modern, fast, and organized applications. 💎
8+
RubyUI is a UI component library designed to let Ruby developers create modern, fast, and organized applications. 💎
99

1010
### Key Features:
1111

12-
- **Built for Speed** ⚡: RBUI leverages Phlex, which is up to 12x faster than traditional Rails ERB templates.
12+
- **Built for Speed** ⚡: RubyUI leverages Phlex, which is up to 12x faster than traditional Rails ERB templates.
1313
- **Stunning UI** 🎨: Design beautiful, streamlined, and customizable UIs that sell your app effortlessly.
1414
- **Stay Organized** 📁: Keep your UI components well-organized and easy to manage.
1515
- **Customer-Centric UX** 🧑‍💼: Create memorable app experiences for your users.
@@ -28,26 +28,26 @@ RBUI is a UI component library designed to let Ruby developers create modern, fa
2828
### 1. Install the gem
2929

3030
```bash
31-
bundle add rbui
31+
bundle add ruby_ui
3232
```
3333

3434
or add it to your Gemfile:
3535

3636
```ruby
37-
gem "rbui"
37+
gem "ruby_ui"
3838
```
3939

4040
### 2. Run the installer:
4141

4242
```bash
43-
bin/rails g rbui:install
43+
bin/rails g ruby_ui:install
4444
```
4545

4646
### 3. Done! 🎉
4747

4848
## Documentation 📖
4949

50-
Visit https://rbui.dev/docs/introduction to view the full documentation, including:
50+
Visit https://ruby_ui.dev/docs/introduction to view the full documentation, including:
5151

5252
- Detailed component guides
5353
- Themes
@@ -56,7 +56,7 @@ Visit https://rbui.dev/docs/introduction to view the full documentation, includi
5656

5757
## Speed Comparison 🏎️
5858

59-
RBUI, powered by Phlex, outperforms traditional methods:
59+
RubyUI, powered by Phlex, outperforms traditional methods:
6060

6161
- Phlex: Baseline 🏁
6262
- ViewComponent: 5.57x slower 🐢
@@ -75,4 +75,4 @@ Licensed under the [MIT license](https://github.com/shadcn/ui/blob/main/LICENSE.
7575

7676
---
7777

78-
© 2024 RBUI. All rights reserved. 🔒
78+
© 2024 RubyUI. All rights reserved. 🔒

bin/console

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

33
require "bundler/setup"
4-
require "rbui"
4+
require "ruby_ui"
55

66
Bundler.require(:development)
77

lib/generators/rbui/install/templates/base_store_initializer.rb.tt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require "rails/generators"
22

3-
module RBUI
3+
module RubyUI
44
module Generators
55
class BaseGenerator < defined?(Rails::Generators::Base) ? Rails::Generators::Base : Object
6-
namespace "rbui:base"
6+
namespace "ruby_ui:base"
77

88
source_root File.join(__dir__, "templates")
99

lib/generators/rbui/component_generator.rb renamed to lib/generators/ruby_ui/component_generator.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module RBUI
1+
module RubyUI
22
module Generators
3-
class ComponentGenerator < RBUI::Generators::BaseGenerator
4-
namespace "rbui:component"
3+
class ComponentGenerator < RubyUI::Generators::BaseGenerator
4+
namespace "ruby_ui:component"
55

66
source_root File.expand_path("../../..", __dir__)
77
argument :component_name, type: :string, required: true
@@ -21,7 +21,7 @@ def copy_common_files
2121
end
2222

2323
def copy_component_files
24-
puts "Component #{component} not found in rbui gem" if component_source.empty?
24+
puts "Component #{component} not found in ruby_ui gem" if component_source.empty?
2525

2626
component_files = Dir.glob("#{component_source}/*")
2727

@@ -32,22 +32,22 @@ def copy_component_files
3232
end
3333

3434
def update_index_file
35-
index_path = File.join(destination_root, "app/components/rbui/index.js")
35+
index_path = File.join(destination_root, "app/components/ruby_ui/index.js")
3636

37-
rbui_index_content = File.read(index_path)
37+
ruby_ui_index_content = File.read(index_path)
3838

39-
updated_rbui_index_content = add_controller_registration(rbui_index_content)
39+
updated_ruby_ui_index_content = add_controller_registration(ruby_ui_index_content)
4040

41-
File.write(index_path, updated_rbui_index_content)
41+
File.write(index_path, updated_ruby_ui_index_content)
4242
end
4343

44-
def add_controller_registration(rbui_index_content)
44+
def add_controller_registration(ruby_ui_index_content)
4545
valid_controllers = get_valid_controllers
4646

47-
rbui_index_content = update_imports(rbui_index_content, valid_controllers)
48-
update_registrations(rbui_index_content, valid_controllers)
47+
ruby_ui_index_content = update_imports(ruby_ui_index_content, valid_controllers)
48+
update_registrations(ruby_ui_index_content, valid_controllers)
4949
# Uncomment the following line if you want to update exports
50-
# rbui_index_content = update_exports(rbui_index_content, valid_controllers)
50+
# ruby_ui_index_content = update_exports(ruby_ui_index_content, valid_controllers)
5151
end
5252

5353
def get_valid_controllers
@@ -74,8 +74,8 @@ def controller_info(controller_file)
7474
# Build the new import path
7575
new_import_path = new_import_path("./#{relative_path.dirname}/#{file_name}")
7676

77-
# Create the registration name by dasherizing the component name and prefixing with 'rbui--'
78-
registration_name = "rbui--#{component_name.dasherize}"
77+
# Create the registration name by dasherizing the component name and prefixing with 'ruby_ui--'
78+
registration_name = "ruby_ui--#{component_name.dasherize}"
7979

8080
# Return a hash with import, registration, and export statements
8181
{
@@ -92,7 +92,7 @@ def controller_info(controller_file)
9292

9393
def new_import_path(relative_path)
9494
if using_importmap?
95-
"rbui/#{relative_path.sub(/^\.\//, "")}"
95+
"ruby_ui/#{relative_path.sub(/^\.\//, "")}"
9696
else
9797
relative_path
9898
end
@@ -118,11 +118,11 @@ def component
118118
end
119119

120120
def source_path
121-
@source_path ||= "lib/rbui"
121+
@source_path ||= "lib/ruby_ui"
122122
end
123123

124124
def destination_path
125-
@destination_path ||= "app/components/rbui"
125+
@destination_path ||= "app/components/ruby_ui"
126126
end
127127

128128
def component_source

lib/generators/rbui/install/install_generator.rb renamed to lib/generators/ruby_ui/install/install_generator.rb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
require_relative "../base_generator"
33

44
# TODO: make ejctectec components work without the gem
5-
module RBUI
5+
module RubyUI
66
module Generators
7-
class InstallGenerator < RBUI::Generators::BaseGenerator
8-
namespace "rbui:install"
7+
class InstallGenerator < RubyUI::Generators::BaseGenerator
8+
namespace "ruby_ui:install"
99

1010
if defined?(Rails::Generators::Base)
1111
source_root File.expand_path("templates", __dir__)
@@ -22,7 +22,7 @@ def add_phlex_rails
2222
say "Phlex Rails is already installed", :green
2323
else
2424
say "Adding Phlex Rails"
25-
run "bundle add phlex-rails --version=\"~> 1.2.1\""
25+
run "bundle add phlex-rails --version=\"~> 2.0.0.beta2\""
2626
end
2727

2828
say "Adding tailwind_merge"
@@ -59,11 +59,11 @@ def install_stuff
5959

6060
tailwind_config_path = Rails.root.join("config/tailwind.config.js")
6161
if !File.exist?(tailwind_config_path)
62-
say "Tailwind CSS is required for RBUI", :red
62+
say "Tailwind CSS is required for RubyUI", :red
6363
end
6464

65-
say "Add rbui initializer"
66-
template "base_store_initializer.rb", "config/initializers/rbui.rb"
65+
say "Add ruby_ui initializer"
66+
template "base_store_initializer.rb", "config/initializers/ruby_ui.rb"
6767

6868
if using_importmap?
6969
say "Using importmaps, adding tailwind-animate"
@@ -90,16 +90,16 @@ def install_stuff
9090
template "application.tailwind.css", "app/assets/stylesheets/application.tailwind.css", force: true
9191
end
9292

93-
def pin_rbui_js
93+
def pin_ruby_ui_js
9494
stimulus_path = Rails.root.join("app/javascript/application.js")
95-
package_name = "rbui-js"
95+
package_name = "ruby_ui-js"
9696

97-
say "Add RBUI Stimulus controllers"
98-
# run "mkdir -p app/javascript/controllers/rbui-js"
99-
template "index.js", "app/components/rbui/index.js"
97+
say "Add RubyUI Stimulus controllers"
98+
# run "mkdir -p app/javascript/controllers/ruby_ui-js"
99+
template "index.js", "app/components/ruby_ui/index.js"
100100

101101
if using_importmap?
102-
gsub_file "app/components/rbui/index.js", /^import { application }.*$/ do
102+
gsub_file "app/components/ruby_ui/index.js", /^import { application }.*$/ do
103103
'import { application } from "controllers/application";'
104104
end
105105

@@ -109,34 +109,34 @@ def pin_rbui_js
109109

110110
say "Pin #{package_name}"
111111
append_to_file Rails.root.join("config/importmap.rb") do
112-
"pin_all_from \"app/components/rbui\", under: \"rbui\"\n"
112+
"pin_all_from \"app/components/ruby_ui\", under: \"ruby_ui\"\n"
113113
end
114114

115115
run "bin/importmap pin #{package_name}"
116-
append_to_file stimulus_path, "\nimport \"rbui\";\n"
116+
append_to_file stimulus_path, "\nimport \"ruby_ui\";\n"
117117

118118
manifest_path = Rails.root.join("app/assets/config/manifest.js")
119119
if File.exist?(manifest_path)
120-
append_to_file manifest_path, "\n//= link rbui/index.js\n"
120+
append_to_file manifest_path, "\n//= link ruby_ui/index.js\n"
121121
end
122122

123123
fix_import_maps!
124124
else
125-
say "Add rbui-js package"
125+
say "Add ruby_ui-js package"
126126
run "yarn add #{package_name}"
127127

128-
append_to_file stimulus_path, "\nimport \"../components/rbui\";\n"
128+
append_to_file stimulus_path, "\nimport \"../components/ruby_ui\";\n"
129129

130130
run "yarn build"
131131
end
132132
end
133133

134-
def include_rbui
135-
message = "Include RBUI in your global component layout?\n This allows to call RBUI.Button {\"button\"} / RBUI::Button.new {\"button\"} with Button {\"button\"} (y/n)"
134+
def include_ruby_ui
135+
message = "Include RubyUI in your global component layout?\n This allows to call RubyUI.Button {\"button\"} / RubyUI::Button.new {\"button\"} with Button {\"button\"} (y/n)"
136136
if yes?(message)
137-
say "Add RBUI to your global component layout"
137+
say "Add RubyUI to your global component layout"
138138
insert_into_file "app/views/application_view.rb", after: "class ApplicationView < ApplicationComponent\n" do
139-
" include RBUI\n"
139+
" include RubyUI\n"
140140
end
141141
end
142142
end
File renamed without changes.

lib/generators/rbui/install/templates/application.tailwind.css.tt renamed to lib/generators/ruby_ui/install/templates/application.tailwind.css.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
--ring: 240 5.9% 10%;
2626
--radius: 0.5rem;
2727

28-
/* rbui especific */
28+
/* ruby_ui especific */
2929
--warning: 38 92% 50%;
3030
--warning-foreground: 0 0% 100%;
3131
--success: 87 100% 37%;
@@ -53,7 +53,7 @@
5353
--input: 240 3.7% 15.9%;
5454
--ring: 240 4.9% 83.9%;
5555

56-
/* rbui especific */
56+
/* ruby_ui especific */
5757
--warning: 38 92% 50%;
5858
--warning-foreground: 0 0% 100%;
5959
--success: 84 81% 44%;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#RubyUI.setup do |config|
2+
3+
# Setting a namespace allows you to access RubyUI components through this namespace.
4+
# For example, with namespace set to "UI", you can use:
5+
# UI::Button.new instead of RubyUI::Button.new
6+
# UI::Card.new instead of RubyUI::Card.new
7+
# This can help avoid naming conflicts and allows for cleaner, more concise code.
8+
# If you prefer to use RubyUI components directly, you can leave this unset.
9+
# config.namespace = "UI"
10+
#end

0 commit comments

Comments
 (0)