ruby_ui 1.0.0.pre.alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/generators/rbui/base_generator.rb +17 -0
- data/lib/generators/rbui/component_generator.rb +137 -0
- data/lib/generators/rbui/install/install_generator.rb +194 -0
- data/lib/rbui/accordion/accordion.rb +17 -0
- data/lib/rbui/accordion/accordion_content.rb +21 -0
- data/lib/rbui/accordion/accordion_default_content.rb +17 -0
- data/lib/rbui/accordion/accordion_default_trigger.rb +19 -0
- data/lib/rbui/accordion/accordion_icon.rb +38 -0
- data/lib/rbui/accordion/accordion_item.rb +28 -0
- data/lib/rbui/accordion/accordion_trigger.rb +16 -0
- data/lib/rbui/alert/alert.rb +36 -0
- data/lib/rbui/alert/alert_description.rb +17 -0
- data/lib/rbui/alert/alert_title.rb +17 -0
- data/lib/rbui/alert_dialog/alert_dialog.rb +26 -0
- data/lib/rbui/alert_dialog/alert_dialog_action.rb +17 -0
- data/lib/rbui/alert_dialog/alert_dialog_cancel.rb +21 -0
- data/lib/rbui/alert_dialog/alert_dialog_content.rb +45 -0
- data/lib/rbui/alert_dialog/alert_dialog_description.rb +17 -0
- data/lib/rbui/alert_dialog/alert_dialog_footer.rb +17 -0
- data/lib/rbui/alert_dialog/alert_dialog_header.rb +17 -0
- data/lib/rbui/alert_dialog/alert_dialog_title.rb +17 -0
- data/lib/rbui/alert_dialog/alert_dialog_trigger.rb +18 -0
- data/lib/rbui/aspect_ratio/aspect_ratio.rb +33 -0
- data/lib/rbui/avatar/avatar.rb +31 -0
- data/lib/rbui/avatar/avatar_fallback.rb +17 -0
- data/lib/rbui/avatar/avatar_image.rb +26 -0
- data/lib/rbui/badge/badge.rb +60 -0
- data/lib/rbui/base.rb +29 -0
- data/lib/rbui/button/button.rb +97 -0
- data/lib/rbui/calendar/calendar.rb +39 -0
- data/lib/rbui/calendar/calendar_body.rb +19 -0
- data/lib/rbui/calendar/calendar_days.rb +104 -0
- data/lib/rbui/calendar/calendar_header.rb +17 -0
- data/lib/rbui/calendar/calendar_next.rb +43 -0
- data/lib/rbui/calendar/calendar_prev.rb +43 -0
- data/lib/rbui/calendar/calendar_title.rb +27 -0
- data/lib/rbui/calendar/calendar_weekdays.rb +33 -0
- data/lib/rbui/card/card.rb +17 -0
- data/lib/rbui/card/card_content.rb +17 -0
- data/lib/rbui/card/card_description.rb +17 -0
- data/lib/rbui/card/card_footer.rb +17 -0
- data/lib/rbui/card/card_header.rb +17 -0
- data/lib/rbui/card/card_title.rb +17 -0
- data/lib/rbui/chart/chart.rb +23 -0
- data/lib/rbui/checkbox/checkbox.rb +23 -0
- data/lib/rbui/checkbox/checkbox_group.rb +20 -0
- data/lib/rbui/clipboard/clipboard.rb +42 -0
- data/lib/rbui/clipboard/clipboard_popover.rb +40 -0
- data/lib/rbui/clipboard/clipboard_source.rb +19 -0
- data/lib/rbui/clipboard/clipboard_trigger.rb +20 -0
- data/lib/rbui/codeblock/codeblock.rb +105 -0
- data/lib/rbui/collapsible/collapsible.rb +25 -0
- data/lib/rbui/collapsible/collapsible_content.rb +18 -0
- data/lib/rbui/collapsible/collapsible_trigger.rb +19 -0
- data/lib/rbui/combobox/combobox.rb +24 -0
- data/lib/rbui/combobox/combobox_content.rb +31 -0
- data/lib/rbui/combobox/combobox_empty.rb +21 -0
- data/lib/rbui/combobox/combobox_group.rb +38 -0
- data/lib/rbui/combobox/combobox_input.rb +22 -0
- data/lib/rbui/combobox/combobox_item.rb +53 -0
- data/lib/rbui/combobox/combobox_list.rb +29 -0
- data/lib/rbui/combobox/combobox_search_input.rb +56 -0
- data/lib/rbui/combobox/combobox_separator.rb +15 -0
- data/lib/rbui/combobox/combobox_trigger.rb +52 -0
- data/lib/rbui/combobox/combobox_value.rb +27 -0
- data/lib/rbui/command/command.rb +9 -0
- data/lib/rbui/command/command_dialog.rb +17 -0
- data/lib/rbui/command/command_dialog_content.rb +48 -0
- data/lib/rbui/command/command_dialog_trigger.rb +29 -0
- data/lib/rbui/command/command_empty.rb +19 -0
- data/lib/rbui/command/command_group.rb +40 -0
- data/lib/rbui/command/command_input.rb +56 -0
- data/lib/rbui/command/command_item.rb +32 -0
- data/lib/rbui/command/command_list.rb +17 -0
- data/lib/rbui/context_menu/context_menu.rb +26 -0
- data/lib/rbui/context_menu/context_menu_content.rb +25 -0
- data/lib/rbui/context_menu/context_menu_item.rb +66 -0
- data/lib/rbui/context_menu/context_menu_label.rb +24 -0
- data/lib/rbui/context_menu/context_menu_separator.rb +19 -0
- data/lib/rbui/context_menu/context_menu_trigger.rb +20 -0
- data/lib/rbui/dialog/dialog.rb +25 -0
- data/lib/rbui/dialog/dialog_content.rb +78 -0
- data/lib/rbui/dialog/dialog_description.rb +17 -0
- data/lib/rbui/dialog/dialog_footer.rb +17 -0
- data/lib/rbui/dialog/dialog_header.rb +17 -0
- data/lib/rbui/dialog/dialog_middle.rb +17 -0
- data/lib/rbui/dialog/dialog_title.rb +17 -0
- data/lib/rbui/dialog/dialog_trigger.rb +20 -0
- data/lib/rbui/dropdown_menu/dropdown_menu.rb +26 -0
- data/lib/rbui/dropdown_menu/dropdown_menu_content.rb +22 -0
- data/lib/rbui/dropdown_menu/dropdown_menu_item.rb +28 -0
- data/lib/rbui/dropdown_menu/dropdown_menu_label.rb +17 -0
- data/lib/rbui/dropdown_menu/dropdown_menu_separator.rb +19 -0
- data/lib/rbui/dropdown_menu/dropdown_menu_trigger.rb +18 -0
- data/lib/rbui/form/form.rb +15 -0
- data/lib/rbui/form/form_field.rb +20 -0
- data/lib/rbui/form/form_field_error.rb +20 -0
- data/lib/rbui/form/form_field_hint.rb +15 -0
- data/lib/rbui/form/form_field_label.rb +15 -0
- data/lib/rbui/hover_card/hover_card.rb +27 -0
- data/lib/rbui/hover_card/hover_card_content.rb +22 -0
- data/lib/rbui/hover_card/hover_card_trigger.rb +20 -0
- data/lib/rbui/input/input.rb +26 -0
- data/lib/rbui/link/link.rb +97 -0
- data/lib/rbui/pagination/pagination.rb +19 -0
- data/lib/rbui/pagination/pagination_content.rb +17 -0
- data/lib/rbui/pagination/pagination_ellipsis.rb +42 -0
- data/lib/rbui/pagination/pagination_item.rb +28 -0
- data/lib/rbui/popover/popover.rb +26 -0
- data/lib/rbui/popover/popover_content.rb +27 -0
- data/lib/rbui/popover/popover_trigger.rb +20 -0
- data/lib/rbui/radio_button/radio_button.rb +22 -0
- data/lib/rbui/railtie.rb +52 -0
- data/lib/rbui/select/select.rb +23 -0
- data/lib/rbui/select/select_content.rb +32 -0
- data/lib/rbui/select/select_group.rb +15 -0
- data/lib/rbui/select/select_input.rb +22 -0
- data/lib/rbui/select/select_item.rb +52 -0
- data/lib/rbui/select/select_label.rb +17 -0
- data/lib/rbui/select/select_trigger.rb +54 -0
- data/lib/rbui/select/select_value.rb +27 -0
- data/lib/rbui/sheet/sheet.rb +17 -0
- data/lib/rbui/sheet/sheet_content.rb +77 -0
- data/lib/rbui/sheet/sheet_description.rb +17 -0
- data/lib/rbui/sheet/sheet_footer.rb +17 -0
- data/lib/rbui/sheet/sheet_header.rb +17 -0
- data/lib/rbui/sheet/sheet_middle.rb +17 -0
- data/lib/rbui/sheet/sheet_title.rb +17 -0
- data/lib/rbui/sheet/sheet_trigger.rb +17 -0
- data/lib/rbui/shortcut_key/shortcut_key.rb +17 -0
- data/lib/rbui/table/table.rb +19 -0
- data/lib/rbui/table/table_body.rb +17 -0
- data/lib/rbui/table/table_caption.rb +17 -0
- data/lib/rbui/table/table_cell.rb +17 -0
- data/lib/rbui/table/table_footer.rb +17 -0
- data/lib/rbui/table/table_head.rb +17 -0
- data/lib/rbui/table/table_header.rb +17 -0
- data/lib/rbui/table/table_row.rb +17 -0
- data/lib/rbui/tabs/tabs.rb +25 -0
- data/lib/rbui/tabs/tabs_content.rb +26 -0
- data/lib/rbui/tabs/tabs_list.rb +17 -0
- data/lib/rbui/tabs/tabs_trigger.rb +28 -0
- data/lib/rbui/textarea/textarea.rb +26 -0
- data/lib/rbui/theme_toggle/theme_toggle.rb +41 -0
- data/lib/rbui/tooltip/tooltip.rb +26 -0
- data/lib/rbui/tooltip/tooltip_content.rb +26 -0
- data/lib/rbui/tooltip/tooltip_trigger.rb +19 -0
- data/lib/rbui/typography/typography_blockquote.rb +17 -0
- data/lib/rbui/typography/typography_h1.rb +17 -0
- data/lib/rbui/typography/typography_h2.rb +17 -0
- data/lib/rbui/typography/typography_h3.rb +17 -0
- data/lib/rbui/typography/typography_h4.rb +17 -0
- data/lib/rbui/typography/typography_inline_code.rb +17 -0
- data/lib/rbui/typography/typography_inline_link.rb +22 -0
- data/lib/rbui/typography/typography_large.rb +17 -0
- data/lib/rbui/typography/typography_lead.rb +17 -0
- data/lib/rbui/typography/typography_list.rb +47 -0
- data/lib/rbui/typography/typography_list_item.rb +17 -0
- data/lib/rbui/typography/typography_muted.rb +17 -0
- data/lib/rbui/typography/typography_p.rb +17 -0
- data/lib/rbui/typography/typography_small.rb +17 -0
- data/lib/rbui/version.rb +5 -0
- data/lib/rbui.rb +57 -0
- data/lib/ruby_ui.rb +1 -0
- metadata +291 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e8fe198601269bb419936470eb4544e7a18d649b11dca407cfccf6abab19c6d1
|
4
|
+
data.tar.gz: 78c7c0804dad0d83f8e6fd4d71846946b9d11f81b474e888b70aef5c8023eaea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e129efa1ca42b66ed176a70d4b0548c512aaf2a617802aa5559f1215a33c820822b2ed4784c04670b67220f02bbd7c56962c770293a156ee7e7606b59cc30ef
|
7
|
+
data.tar.gz: 01a600e4229632bc54cabd1abd4caf3acceb9fb689d973f74b18973b31e23247852a28d3db11b4b66532c094049d004b8987469c6240cfaccbbdeb36cb6b6e94
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
module Generators
|
5
|
+
class BaseGenerator < defined?(Rails::Generators::Base) ? Rails::Generators::Base : Object
|
6
|
+
namespace "rbui:base"
|
7
|
+
|
8
|
+
source_root File.join(__dir__, "templates")
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def using_importmap?
|
13
|
+
File.exist?(Rails.root.join("config/importmap.rb")) && File.exist?(Rails.root.join("bin/importmap"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module RBUI
|
2
|
+
module Generators
|
3
|
+
class ComponentGenerator < RBUI::Generators::BaseGenerator
|
4
|
+
namespace "rbui:component"
|
5
|
+
|
6
|
+
source_root File.expand_path("../../..", __dir__)
|
7
|
+
argument :component_name, type: :string, required: true
|
8
|
+
|
9
|
+
def copy_component
|
10
|
+
return puts "This generator can only be run in a Rails environment." unless defined?(Rails::Generators::Base)
|
11
|
+
|
12
|
+
copy_common_files
|
13
|
+
copy_component_files
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def copy_common_files
|
19
|
+
template "#{template_dir}/index.js", "#{destination_path}/index.js" unless File.exist?("#{destination_path}/index.js")
|
20
|
+
copy_file File.join(source_path, "base.rb"), File.join(destination_path, "base.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_component_files
|
24
|
+
puts "Component #{component} not found in rbui gem" if component_source.empty?
|
25
|
+
|
26
|
+
component_files = Dir.glob("#{component_source}/*")
|
27
|
+
|
28
|
+
component_files.each do |file|
|
29
|
+
copy_file file, File.join(destination_path, component, File.basename(file))
|
30
|
+
end
|
31
|
+
update_index_file
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_index_file
|
35
|
+
index_path = File.join(destination_root, "app/components/rbui/index.js")
|
36
|
+
|
37
|
+
rbui_index_content = File.read(index_path)
|
38
|
+
|
39
|
+
updated_rbui_index_content = add_controller_registration(rbui_index_content)
|
40
|
+
|
41
|
+
File.write(index_path, updated_rbui_index_content)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_controller_registration(rbui_index_content)
|
45
|
+
valid_controllers = get_valid_controllers
|
46
|
+
|
47
|
+
rbui_index_content = update_imports(rbui_index_content, valid_controllers)
|
48
|
+
update_registrations(rbui_index_content, valid_controllers)
|
49
|
+
# Uncomment the following line if you want to update exports
|
50
|
+
# rbui_index_content = update_exports(rbui_index_content, valid_controllers)
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_valid_controllers
|
54
|
+
all_js_controllers = Dir.glob(File.join(destination_path, "**", "*_controller.js"))
|
55
|
+
|
56
|
+
all_js_controllers.map do |controller_file|
|
57
|
+
controller_info(controller_file)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def controller_info(controller_file)
|
62
|
+
# Get the relative path from the destination path to the controller file
|
63
|
+
relative_path = Pathname.new(controller_file).relative_path_from(Pathname.new(destination_path))
|
64
|
+
|
65
|
+
# Extract the file name without the .js extension
|
66
|
+
file_name = relative_path.basename(".js").to_s
|
67
|
+
|
68
|
+
# Remove '_controller' suffix to get the component name
|
69
|
+
component_name = file_name.sub(/_controller$/, "")
|
70
|
+
|
71
|
+
# Create the new controller name by camelizing the component name and adding 'Controller'
|
72
|
+
new_controller = "#{component_name.camelize}Controller"
|
73
|
+
|
74
|
+
# Build the new import path
|
75
|
+
new_import_path = new_import_path("./#{relative_path.dirname}/#{file_name}")
|
76
|
+
|
77
|
+
# Create the registration name by dasherizing the component name and prefixing with 'rbui--'
|
78
|
+
registration_name = "rbui--#{component_name.dasherize}"
|
79
|
+
|
80
|
+
# Return a hash with import, registration, and export statements
|
81
|
+
{
|
82
|
+
# Import statement for importmaps
|
83
|
+
import: "import #{new_controller} from \"#{new_import_path}\";",
|
84
|
+
|
85
|
+
# Registration statement for the Stimulus controller
|
86
|
+
registration: "application.register(\"#{registration_name}\", #{new_controller});",
|
87
|
+
|
88
|
+
# Export statement for the controller
|
89
|
+
export: "export { default as #{new_controller} } from \"#{new_import_path}\";"
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def new_import_path(relative_path)
|
94
|
+
if using_importmap?
|
95
|
+
"rbui/#{relative_path.sub(/^\.\//, "")}"
|
96
|
+
else
|
97
|
+
relative_path
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def update_imports(content, controllers)
|
102
|
+
imports = controllers.map { |c| c[:import] }.sort.join("\n")
|
103
|
+
content.sub(/\/\/ Import all controller files.*?(?=\n\n)/m, "// Import all controller files\n#{imports}")
|
104
|
+
end
|
105
|
+
|
106
|
+
def update_registrations(content, controllers)
|
107
|
+
registrations = controllers.map { |c| c[:registration] }.sort.join("\n")
|
108
|
+
content.sub(/\/\/ Register all controllers.*?(?=\n\n)/m, "// Register all controllers\n#{registrations}")
|
109
|
+
end
|
110
|
+
|
111
|
+
def update_exports(content, controllers)
|
112
|
+
exports = controllers.map { |c| c[:export] }.sort.join("\n")
|
113
|
+
content.sub(/\/\/ Export all controllers.*?(?=\n\n)/m, "// Export all controllers so user of npm package can lazy load controllers\n#{exports}")
|
114
|
+
end
|
115
|
+
|
116
|
+
def component
|
117
|
+
@component ||= component_name.downcase
|
118
|
+
end
|
119
|
+
|
120
|
+
def source_path
|
121
|
+
@source_path ||= "lib/rbui"
|
122
|
+
end
|
123
|
+
|
124
|
+
def destination_path
|
125
|
+
@destination_path ||= "app/components/rbui"
|
126
|
+
end
|
127
|
+
|
128
|
+
def component_source
|
129
|
+
@component_source ||= File.join(self.class.source_root, source_path, component)
|
130
|
+
end
|
131
|
+
|
132
|
+
def template_dir
|
133
|
+
@template_dir ||= File.join(__dir__, "templates")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
# TODO: make ejctectec components work without the gem
|
4
|
+
module RBUI
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < RBUI::Generators::BaseGenerator
|
7
|
+
namespace "rbui:install"
|
8
|
+
|
9
|
+
if defined?(Rails::Generators::Base)
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
def confirm_installation
|
13
|
+
return if yes?("You need tailwindcss installed. Continue? (y/n)")
|
14
|
+
say "Installation cancelled.", :red
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_phlex_rails
|
19
|
+
say "Checking for Phlex Rails"
|
20
|
+
if gem_installed?("phlex-rails")
|
21
|
+
say "Phlex Rails is already installed", :green
|
22
|
+
else
|
23
|
+
say "Adding Phlex Rails"
|
24
|
+
run "bundle add phlex-rails --version=\"~> 1.2.1\""
|
25
|
+
end
|
26
|
+
|
27
|
+
say "Adding tailwind_merge"
|
28
|
+
run "bundle add tailwind_merge"
|
29
|
+
|
30
|
+
say "run phlex install"
|
31
|
+
run "bin/rails generate phlex:install"
|
32
|
+
end
|
33
|
+
|
34
|
+
def install_stuff
|
35
|
+
# make default option no
|
36
|
+
# extend the yes func to have a default option y/(n) and also allow for enter to accedpt the default
|
37
|
+
|
38
|
+
if ENV["TEST_DATA"] == "true"
|
39
|
+
say "Do you want to set up the dev test data?"
|
40
|
+
say "Add index controller"
|
41
|
+
run "bin/rails generate controller static index --no-helper --no-assets --no-test-framework --no-jbuilder"
|
42
|
+
|
43
|
+
say "Add index view"
|
44
|
+
run "bin/rails g phlex:view Static::Index"
|
45
|
+
|
46
|
+
append_to_file "app/controllers/static_controller.rb", after: " def index" do
|
47
|
+
# remove view because phlex is removing view
|
48
|
+
"\n render Static::IndexView"
|
49
|
+
end
|
50
|
+
|
51
|
+
template "index_view.rb", "app/views/static/index_view.rb", force: true
|
52
|
+
|
53
|
+
say "Add index route"
|
54
|
+
append_to_file "config/routes.rb", after: "Rails.application.routes.draw do" do
|
55
|
+
"\n root to: \"static#index\"\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
tailwind_config_path = Rails.root.join("config/tailwind.config.js")
|
60
|
+
if !File.exist?(tailwind_config_path)
|
61
|
+
say "Tailwind CSS is required for RBUI", :red
|
62
|
+
end
|
63
|
+
|
64
|
+
say "Add rbui initializer"
|
65
|
+
template "base_store_initializer.rb", "config/initializers/rbui.rb"
|
66
|
+
|
67
|
+
if using_importmap?
|
68
|
+
say "Using importmaps, adding tailwind-animate"
|
69
|
+
run "bin/importmap pin tailwindcss-animate"
|
70
|
+
|
71
|
+
# Remove the default pin
|
72
|
+
gsub_file "config/importmap.rb", /^pin "tailwindcss-animate".*$\n/, ""
|
73
|
+
|
74
|
+
# Add the vendor-specific pin
|
75
|
+
append_to_file "config/importmap.rb" do
|
76
|
+
'pin "tailwindcss-animate", to: "tailwindcss-animate.js", preload: true' + "\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
else
|
80
|
+
say "Not using importmaps, adding tailwind-animate via yarn"
|
81
|
+
run "yarn add tailwindcss-animate"
|
82
|
+
end
|
83
|
+
|
84
|
+
# check if tailwind.config is in config dir or in root or ask to specify a path
|
85
|
+
say "update tailwind.config.js"
|
86
|
+
template "tailwind.config.js", "config/tailwind.config.js", force: true, assigns: {using_importmap: using_importmap?}
|
87
|
+
|
88
|
+
say "Add CSS variables"
|
89
|
+
template "application.tailwind.css", "app/assets/stylesheets/application.tailwind.css", force: true
|
90
|
+
end
|
91
|
+
|
92
|
+
def pin_rbui_js
|
93
|
+
stimulus_path = Rails.root.join("app/javascript/application.js")
|
94
|
+
package_name = "rbui-js"
|
95
|
+
|
96
|
+
say "Add RBUI Stimulus controllers"
|
97
|
+
# run "mkdir -p app/javascript/controllers/rbui-js"
|
98
|
+
template "index.js", "app/components/rbui/index.js"
|
99
|
+
|
100
|
+
if using_importmap?
|
101
|
+
gsub_file "app/components/rbui/index.js", /^import { application }.*$/ do
|
102
|
+
'import { application } from "controllers/application";'
|
103
|
+
end
|
104
|
+
|
105
|
+
append_to_file Rails.root.join("config/initializers/assets.rb") do
|
106
|
+
"Rails.application.config.assets.paths << Rails.root.join(\"app/components\")\n"
|
107
|
+
end
|
108
|
+
|
109
|
+
say "Pin #{package_name}"
|
110
|
+
append_to_file Rails.root.join("config/importmap.rb") do
|
111
|
+
"pin_all_from \"app/components/rbui\", under: \"rbui\"\n"
|
112
|
+
end
|
113
|
+
|
114
|
+
run "bin/importmap pin #{package_name}"
|
115
|
+
append_to_file stimulus_path, "\nimport \"rbui\";\n"
|
116
|
+
|
117
|
+
manifest_path = Rails.root.join("app/assets/config/manifest.js")
|
118
|
+
if File.exist?(manifest_path)
|
119
|
+
append_to_file manifest_path, "\n//= link rbui/index.js\n"
|
120
|
+
end
|
121
|
+
|
122
|
+
fix_import_maps!
|
123
|
+
else
|
124
|
+
say "Add rbui-js package"
|
125
|
+
run "yarn add #{package_name}"
|
126
|
+
|
127
|
+
append_to_file stimulus_path, "\nimport \"../components/rbui\";\n"
|
128
|
+
|
129
|
+
run "yarn build"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def include_rbui
|
134
|
+
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)"
|
135
|
+
if yes?(message)
|
136
|
+
say "Add RBUI to your global component layout"
|
137
|
+
insert_into_file "app/views/application_view.rb", after: "class ApplicationView < ApplicationComponent\n" do
|
138
|
+
" include RBUI\n"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
else
|
144
|
+
def self.source_root
|
145
|
+
File.expand_path("templates", __dir__)
|
146
|
+
end
|
147
|
+
|
148
|
+
def add_stylesheet_link
|
149
|
+
puts "This generator can only be run in a Rails environment."
|
150
|
+
end
|
151
|
+
|
152
|
+
def revoke
|
153
|
+
puts "This generator can only be run in a Rails environment."
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def fix_import_maps!
|
160
|
+
importmap_config_path = Rails.root.join("config/importmap.rb")
|
161
|
+
|
162
|
+
gsub_file importmap_config_path, /^pin "date-fns".*$/ do
|
163
|
+
'pin "date-fns", to: "https://ga.jspm.io/npm:date-fns@3.3.1/index.mjs"'
|
164
|
+
end
|
165
|
+
run "bin/importmap pin @popperjs/core@2.11.8/+esm --from jsdelivr"
|
166
|
+
|
167
|
+
run "mv vendor/javascript/@popperjs--core--+esm.js vendor/javascript/stupid-popper-lib-2024.js"
|
168
|
+
|
169
|
+
append_to_file importmap_config_path do
|
170
|
+
'pin "@popperjs/core", to: "stupid-popper-lib-2024.js"'
|
171
|
+
end
|
172
|
+
|
173
|
+
uri = URI "https://ga.jspm.io/npm:chart.js@3.9.1/dist/chart.min.js"
|
174
|
+
request = Net::HTTP::Get.new uri
|
175
|
+
|
176
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
|
177
|
+
http.request(request)
|
178
|
+
}
|
179
|
+
|
180
|
+
File.write(Rails.root.join("vendor/javascript/chart.js--auto.js"), response.body) if response.is_a?(Net::HTTPSuccess)
|
181
|
+
|
182
|
+
append_to_file Rails.root.join("app/views/layouts/application.html.erb"), before: "</body>" do
|
183
|
+
"<script>
|
184
|
+
window.process = { env: { NODE_ENV: 'production'} }
|
185
|
+
</script>"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def gem_installed?(name)
|
190
|
+
Gem::Specification.find_all_by_name(name).any?
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AccordionContent < Base
|
5
|
+
def view_template(&)
|
6
|
+
div(**attrs, &)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def default_attrs
|
12
|
+
{
|
13
|
+
data: {
|
14
|
+
rbui__accordion_target: "content"
|
15
|
+
},
|
16
|
+
class: "overflow-y-hidden",
|
17
|
+
style: "height: 0px;"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AccordionDefaultTrigger < Base
|
5
|
+
def view_template(&block)
|
6
|
+
div(class: "flex items-center justify-between w-full") do
|
7
|
+
p(&block)
|
8
|
+
RBUI.AccordionIcon
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_attrs
|
13
|
+
{
|
14
|
+
data: {action: "click->rbui--accordion#toggle"},
|
15
|
+
class: "w-full flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AccordionIcon < Base
|
5
|
+
def view_template(&block)
|
6
|
+
span(**attrs) do
|
7
|
+
if block
|
8
|
+
block.call
|
9
|
+
else
|
10
|
+
icon
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def icon
|
16
|
+
svg(
|
17
|
+
xmlns: "http://www.w3.org/2000/svg",
|
18
|
+
viewbox: "0 0 20 20",
|
19
|
+
fill: "currentColor",
|
20
|
+
class: "w-4 h-4"
|
21
|
+
) do |s|
|
22
|
+
s.path(
|
23
|
+
fill_rule: "evenodd",
|
24
|
+
d:
|
25
|
+
"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",
|
26
|
+
clip_rule: "evenodd"
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_attrs
|
32
|
+
{
|
33
|
+
class: "opacity-50",
|
34
|
+
data: {rbui__accordion_target: "icon"}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AccordionItem < Base
|
5
|
+
def initialize(open: false, rotate_icon: 180, **attrs)
|
6
|
+
@open = open
|
7
|
+
@rotate_icon = rotate_icon
|
8
|
+
super(**attrs)
|
9
|
+
end
|
10
|
+
|
11
|
+
def view_template(&)
|
12
|
+
div(**attrs, &)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def default_attrs
|
18
|
+
{
|
19
|
+
data: {
|
20
|
+
controller: "rbui--accordion",
|
21
|
+
rbui__accordion_open_value: @open,
|
22
|
+
rbui__accordion_rotate_icon_value: @rotate_icon
|
23
|
+
},
|
24
|
+
class: "border-b"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AccordionTrigger < Base
|
5
|
+
def view_template(&)
|
6
|
+
button(**attrs, &)
|
7
|
+
end
|
8
|
+
|
9
|
+
def default_attrs
|
10
|
+
{
|
11
|
+
data: {action: "click->rbui--accordion#toggle"},
|
12
|
+
class: "w-full flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class Alert < Base
|
5
|
+
def initialize(variant: nil, **attrs)
|
6
|
+
@variant = variant
|
7
|
+
super(**attrs) # must be called after variant is set
|
8
|
+
end
|
9
|
+
|
10
|
+
def view_template(&)
|
11
|
+
div(**attrs, &)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def colors
|
17
|
+
case @variant
|
18
|
+
when nil
|
19
|
+
"ring-border bg-muted/20 text-foreground [&>svg]:opacity-80"
|
20
|
+
when :warning
|
21
|
+
"ring-warning/20 bg-warning/5 text-warning [&>svg]:text-warning/80"
|
22
|
+
when :success
|
23
|
+
"ring-success/20 bg-success/5 text-success [&>svg]:text-success/80"
|
24
|
+
when :destructive
|
25
|
+
"ring-destructive/20 bg-destructive/5 text-destructive [&>svg]:text-destructive/80"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_attrs
|
30
|
+
base_classes = "backdrop-blur relative w-full ring-1 ring-inset rounded-lg px-4 py-4 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg~*]:pl-8"
|
31
|
+
{
|
32
|
+
class: tokens(base_classes, colors)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AlertDialog < Base
|
5
|
+
def initialize(open: false, **attrs)
|
6
|
+
@open = open
|
7
|
+
super(**attrs)
|
8
|
+
end
|
9
|
+
|
10
|
+
def view_template(&)
|
11
|
+
div(**attrs, &)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def default_attrs
|
17
|
+
{
|
18
|
+
data: {
|
19
|
+
controller: "rbui--alert-dialog",
|
20
|
+
rbui__alert_dialog_open_value: @open.to_s
|
21
|
+
},
|
22
|
+
class: "inline-block"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBUI
|
4
|
+
class AlertDialogCancel < Base
|
5
|
+
def view_template(&)
|
6
|
+
render RBUI::Button.new(**attrs, &)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def default_attrs
|
12
|
+
{
|
13
|
+
variant: :outline,
|
14
|
+
data: {
|
15
|
+
action: "click->rbui--alert-dialog#dismiss"
|
16
|
+
},
|
17
|
+
class: "mt-2 sm:mt-0"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|