better_ui 0.3.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of better_ui might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +140 -230
- data/app/assets/stylesheets/better_ui/_base.scss +9 -0
- data/app/assets/stylesheets/better_ui/_components.scss +2 -0
- data/app/assets/stylesheets/better_ui/_utilities.scss +14 -0
- data/app/assets/stylesheets/better_ui/application.css +32 -0
- data/app/assets/stylesheets/better_ui/components/_avatar.scss +200 -0
- data/app/assets/stylesheets/better_ui/components/_badge.scss +154 -0
- data/app/assets/stylesheets/better_ui/components/_breadcrumb.scss +106 -0
- data/app/assets/stylesheets/better_ui/components/_button.scss +105 -0
- data/app/assets/stylesheets/better_ui/components/_card.scss +60 -0
- data/app/assets/stylesheets/better_ui/components/_heading.scss +81 -0
- data/app/assets/stylesheets/better_ui/components/_icon.scss +134 -0
- data/app/assets/stylesheets/better_ui/components/_index.scss +17 -0
- data/app/assets/stylesheets/better_ui/components/_link.scss +100 -0
- data/app/assets/stylesheets/better_ui/components/_panel.scss +104 -0
- data/app/assets/stylesheets/better_ui/components/_spinner.scss +129 -0
- data/app/assets/stylesheets/better_ui/components/_table.scss +156 -0
- data/app/assets/stylesheets/better_ui/components/_variables.scss +1 -0
- data/app/assets/stylesheets/better_ui.scss +4 -0
- data/app/components/better_ui/application/alert_component.html.erb +27 -0
- data/app/components/better_ui/application/alert_component.rb +202 -0
- data/app/components/better_ui/application/card_component.html.erb +24 -0
- data/app/components/better_ui/application/card_component.rb +53 -0
- data/app/components/better_ui/application/card_container_component.html.erb +8 -0
- data/app/components/better_ui/application/card_container_component.rb +14 -0
- data/app/components/better_ui/application/header_component.html.erb +88 -0
- data/app/components/better_ui/application/header_component.rb +188 -0
- data/app/components/better_ui/application/navbar_component.html.erb +294 -0
- data/app/components/better_ui/application/navbar_component.rb +249 -0
- data/app/components/better_ui/application/sidebar_component.html.erb +207 -0
- data/app/components/better_ui/application/sidebar_component.rb +318 -0
- data/app/components/better_ui/application/toast_component.html.erb +35 -0
- data/app/components/better_ui/application/toast_component.rb +223 -0
- data/app/components/better_ui/general/avatar_component.html.erb +19 -0
- data/app/components/better_ui/general/avatar_component.rb +171 -0
- data/app/components/better_ui/general/{badge/component.html.erb → badge_component.html.erb} +2 -6
- data/app/components/better_ui/general/badge_component.rb +135 -0
- data/app/components/better_ui/general/{breadcrumb/component.html.erb → breadcrumb_component.html.erb} +4 -4
- data/app/components/better_ui/general/breadcrumb_component.rb +130 -0
- data/app/components/better_ui/general/{button/component.html.erb → button_component.html.erb} +7 -7
- data/app/components/better_ui/general/button_component.rb +160 -0
- data/app/components/better_ui/general/heading_component.html.erb +1 -0
- data/app/components/better_ui/general/heading_component.rb +49 -0
- data/app/components/better_ui/general/icon_component.html.erb +2 -0
- data/app/components/better_ui/general/icon_component.rb +77 -0
- data/app/components/better_ui/general/link_component.html.erb +17 -0
- data/app/components/better_ui/general/link_component.rb +132 -0
- data/app/components/better_ui/general/panel_component.html.erb +27 -0
- data/app/components/better_ui/general/panel_component.rb +92 -0
- data/app/components/better_ui/general/spinner_component.html.erb +15 -0
- data/app/components/better_ui/general/spinner_component.rb +79 -0
- data/app/components/better_ui/general/table_component.html.erb +73 -0
- data/app/components/better_ui/general/table_component.rb +143 -0
- data/app/controllers/better_ui/application_controller.rb +1 -0
- data/app/helpers/better_ui/general/components/avatar_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/badge_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/breadcrumb_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/button_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/heading_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/icon_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/link_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/panel_helper.rb +16 -0
- data/app/helpers/better_ui/general/components/spinner_helper.rb +17 -0
- data/app/helpers/better_ui/general/components/table_helper.rb +17 -0
- data/app/helpers/better_ui/general_helper.rb +15 -0
- data/app/helpers/better_ui_helper.rb +12 -0
- data/app/views/components/better_ui/general/table/_custom_body_row.html.erb +17 -0
- data/app/views/components/better_ui/general/table/_custom_footer_rows.html.erb +17 -0
- data/app/views/components/better_ui/general/table/_custom_header_rows.html.erb +12 -0
- data/app/views/layouts/component_preview.html.erb +32 -0
- data/config/initializers/lookbook.rb +12 -12
- data/config/routes.rb +2 -0
- data/lib/better_ui/engine.rb +92 -5
- data/lib/better_ui/version.rb +1 -1
- data/lib/better_ui.rb +32 -4
- data/lib/generators/better_ui/install_generator.rb +103 -0
- data/lib/generators/better_ui/stylesheet_generator.rb +159 -0
- data/lib/generators/better_ui/templates/README +125 -0
- data/lib/generators/better_ui/templates/components/_avatar.scss +200 -0
- data/lib/generators/better_ui/templates/components/_badge.scss +154 -0
- data/lib/generators/better_ui/templates/components/_breadcrumb.scss +106 -0
- data/lib/generators/better_ui/templates/components/_button.scss +109 -0
- data/lib/generators/better_ui/templates/components/_card.scss +60 -0
- data/lib/generators/better_ui/templates/components/_heading.scss +81 -0
- data/lib/generators/better_ui/templates/components/_icon.scss +134 -0
- data/lib/generators/better_ui/templates/components/_index.scss +17 -0
- data/lib/generators/better_ui/templates/components/_link.scss +100 -0
- data/lib/generators/better_ui/templates/components/_panel.scss +104 -0
- data/lib/generators/better_ui/templates/components/_spinner.scss +129 -0
- data/lib/generators/better_ui/templates/components/_table.scss +156 -0
- data/lib/generators/better_ui/templates/components/_variables.scss +0 -0
- data/lib/generators/better_ui/templates/components_stylesheet.scss +35 -0
- data/lib/generators/better_ui/templates/index.scss +18 -0
- data/lib/generators/better_ui/templates/initializer.rb +41 -0
- metadata +178 -147
- data/app/components/better_ui/application/card/component.html.erb +0 -20
- data/app/components/better_ui/application/card/component.rb +0 -214
- data/app/components/better_ui/application/main/component.html.erb +0 -9
- data/app/components/better_ui/application/main/component.rb +0 -123
- data/app/components/better_ui/application/navbar/component.html.erb +0 -92
- data/app/components/better_ui/application/navbar/component.rb +0 -136
- data/app/components/better_ui/application/sidebar/component.html.erb +0 -227
- data/app/components/better_ui/application/sidebar/component.rb +0 -130
- data/app/components/better_ui/general/accordion/component.html.erb +0 -5
- data/app/components/better_ui/general/accordion/component.rb +0 -92
- data/app/components/better_ui/general/accordion/item_component.html.erb +0 -12
- data/app/components/better_ui/general/accordion/item_component.rb +0 -176
- data/app/components/better_ui/general/alert/component.html.erb +0 -32
- data/app/components/better_ui/general/alert/component.rb +0 -242
- data/app/components/better_ui/general/avatar/component.html.erb +0 -20
- data/app/components/better_ui/general/avatar/component.rb +0 -301
- data/app/components/better_ui/general/badge/component.rb +0 -248
- data/app/components/better_ui/general/breadcrumb/component.rb +0 -187
- data/app/components/better_ui/general/button/component.rb +0 -214
- data/app/components/better_ui/general/divider/component.html.erb +0 -10
- data/app/components/better_ui/general/divider/component.rb +0 -226
- data/app/components/better_ui/general/dropdown/component.html.erb +0 -25
- data/app/components/better_ui/general/dropdown/component.rb +0 -170
- data/app/components/better_ui/general/dropdown/divider_component.html.erb +0 -1
- data/app/components/better_ui/general/dropdown/divider_component.rb +0 -41
- data/app/components/better_ui/general/dropdown/item_component.html.erb +0 -6
- data/app/components/better_ui/general/dropdown/item_component.rb +0 -119
- data/app/components/better_ui/general/field/component.html.erb +0 -27
- data/app/components/better_ui/general/field/component.rb +0 -37
- data/app/components/better_ui/general/heading/component.html.erb +0 -22
- data/app/components/better_ui/general/heading/component.rb +0 -257
- data/app/components/better_ui/general/icon/component.html.erb +0 -7
- data/app/components/better_ui/general/icon/component.rb +0 -239
- data/app/components/better_ui/general/input/checkbox/component.html.erb +0 -5
- data/app/components/better_ui/general/input/checkbox/component.rb +0 -238
- data/app/components/better_ui/general/input/datetime/component.html.erb +0 -5
- data/app/components/better_ui/general/input/datetime/component.rb +0 -223
- data/app/components/better_ui/general/input/radio/component.html.erb +0 -5
- data/app/components/better_ui/general/input/radio/component.rb +0 -230
- data/app/components/better_ui/general/input/select/component.html.erb +0 -16
- data/app/components/better_ui/general/input/select/component.rb +0 -184
- data/app/components/better_ui/general/input/select/select_component.html.erb +0 -5
- data/app/components/better_ui/general/input/select/select_component.rb +0 -37
- data/app/components/better_ui/general/input/text/component.html.erb +0 -5
- data/app/components/better_ui/general/input/text/component.rb +0 -171
- data/app/components/better_ui/general/input/textarea/component.html.erb +0 -5
- data/app/components/better_ui/general/input/textarea/component.rb +0 -166
- data/app/components/better_ui/general/link/component.html.erb +0 -18
- data/app/components/better_ui/general/link/component.rb +0 -258
- data/app/components/better_ui/general/modal/component.html.erb +0 -5
- data/app/components/better_ui/general/modal/component.rb +0 -47
- data/app/components/better_ui/general/modal/modal_component.html.erb +0 -52
- data/app/components/better_ui/general/modal/modal_component.rb +0 -160
- data/app/components/better_ui/general/pagination/component.html.erb +0 -85
- data/app/components/better_ui/general/pagination/component.rb +0 -216
- data/app/components/better_ui/general/panel/component.html.erb +0 -28
- data/app/components/better_ui/general/panel/component.rb +0 -249
- data/app/components/better_ui/general/progress/component.html.erb +0 -11
- data/app/components/better_ui/general/progress/component.rb +0 -160
- data/app/components/better_ui/general/spinner/component.html.erb +0 -35
- data/app/components/better_ui/general/spinner/component.rb +0 -93
- data/app/components/better_ui/general/table/component.html.erb +0 -5
- data/app/components/better_ui/general/table/component.rb +0 -217
- data/app/components/better_ui/general/table/tbody_component.html.erb +0 -3
- data/app/components/better_ui/general/table/tbody_component.rb +0 -30
- data/app/components/better_ui/general/table/td_component.html.erb +0 -3
- data/app/components/better_ui/general/table/td_component.rb +0 -44
- data/app/components/better_ui/general/table/tfoot_component.html.erb +0 -3
- data/app/components/better_ui/general/table/tfoot_component.rb +0 -28
- data/app/components/better_ui/general/table/th_component.html.erb +0 -6
- data/app/components/better_ui/general/table/th_component.rb +0 -51
- data/app/components/better_ui/general/table/thead_component.html.erb +0 -3
- data/app/components/better_ui/general/table/thead_component.rb +0 -28
- data/app/components/better_ui/general/table/tr_component.html.erb +0 -3
- data/app/components/better_ui/general/table/tr_component.rb +0 -30
- data/app/components/better_ui/general/tabs/component.html.erb +0 -11
- data/app/components/better_ui/general/tabs/component.rb +0 -120
- data/app/components/better_ui/general/tabs/panel_component.html.erb +0 -3
- data/app/components/better_ui/general/tabs/panel_component.rb +0 -37
- data/app/components/better_ui/general/tabs/tab_component.html.erb +0 -13
- data/app/components/better_ui/general/tabs/tab_component.rb +0 -111
- data/app/components/better_ui/general/tag/component.html.erb +0 -3
- data/app/components/better_ui/general/tag/component.rb +0 -104
- data/app/components/better_ui/general/tooltip/component.html.erb +0 -7
- data/app/components/better_ui/general/tooltip/component.rb +0 -239
- data/app/helpers/better_ui/application/components/card/card_helper.rb +0 -96
- data/app/helpers/better_ui/application/components/card.rb +0 -11
- data/app/helpers/better_ui/application/components/main/main_helper.rb +0 -64
- data/app/helpers/better_ui/application/components/navbar/navbar_helper.rb +0 -77
- data/app/helpers/better_ui/application/components/sidebar/sidebar_helper.rb +0 -51
- data/app/helpers/better_ui/application_helper.rb +0 -55
- data/app/helpers/better_ui/general/components/accordion/accordion_helper.rb +0 -73
- data/app/helpers/better_ui/general/components/accordion.rb +0 -11
- data/app/helpers/better_ui/general/components/alert/alert_helper.rb +0 -57
- data/app/helpers/better_ui/general/components/avatar/avatar_helper.rb +0 -29
- data/app/helpers/better_ui/general/components/badge/badge_helper.rb +0 -53
- data/app/helpers/better_ui/general/components/breadcrumb/breadcrumb_helper.rb +0 -37
- data/app/helpers/better_ui/general/components/button/button_helper.rb +0 -65
- data/app/helpers/better_ui/general/components/container/container_helper.rb +0 -60
- data/app/helpers/better_ui/general/components/divider/divider_helper.rb +0 -63
- data/app/helpers/better_ui/general/components/dropdown/divider_helper.rb +0 -32
- data/app/helpers/better_ui/general/components/dropdown/dropdown_helper.rb +0 -79
- data/app/helpers/better_ui/general/components/dropdown/item_helper.rb +0 -62
- data/app/helpers/better_ui/general/components/field/field_helper.rb +0 -26
- data/app/helpers/better_ui/general/components/heading/heading_helper.rb +0 -72
- data/app/helpers/better_ui/general/components/icon/icon_helper.rb +0 -16
- data/app/helpers/better_ui/general/components/input/checkbox/checkbox_helper.rb +0 -81
- data/app/helpers/better_ui/general/components/input/datetime/datetime_helper.rb +0 -91
- data/app/helpers/better_ui/general/components/input/radio/radio_helper.rb +0 -79
- data/app/helpers/better_ui/general/components/input/radio_group/radio_group_helper.rb +0 -124
- data/app/helpers/better_ui/general/components/input/select/select_helper.rb +0 -70
- data/app/helpers/better_ui/general/components/input/text/text_helper.rb +0 -138
- data/app/helpers/better_ui/general/components/input/textarea/textarea_helper.rb +0 -73
- data/app/helpers/better_ui/general/components/link/link_helper.rb +0 -89
- data/app/helpers/better_ui/general/components/modal/modal_helper.rb +0 -85
- data/app/helpers/better_ui/general/components/modal.rb +0 -11
- data/app/helpers/better_ui/general/components/pagination/pagination_helper.rb +0 -82
- data/app/helpers/better_ui/general/components/panel/panel_helper.rb +0 -83
- data/app/helpers/better_ui/general/components/progress/progress_helper.rb +0 -53
- data/app/helpers/better_ui/general/components/spinner/spinner_helper.rb +0 -19
- data/app/helpers/better_ui/general/components/table/table_helper.rb +0 -53
- data/app/helpers/better_ui/general/components/table/tbody_helper.rb +0 -13
- data/app/helpers/better_ui/general/components/table/td_helper.rb +0 -19
- data/app/helpers/better_ui/general/components/table/tfoot_helper.rb +0 -13
- data/app/helpers/better_ui/general/components/table/th_helper.rb +0 -19
- data/app/helpers/better_ui/general/components/table/thead_helper.rb +0 -13
- data/app/helpers/better_ui/general/components/table/tr_helper.rb +0 -13
- data/app/helpers/better_ui/general/components/tabs/panel_helper.rb +0 -62
- data/app/helpers/better_ui/general/components/tabs/tab_helper.rb +0 -55
- data/app/helpers/better_ui/general/components/tabs/tabs_helper.rb +0 -95
- data/app/helpers/better_ui/general/components/tag/tag_helper.rb +0 -26
- data/app/helpers/better_ui/general/components/tooltip/tooltip_helper.rb +0 -60
- data/app/views/layouts/better_ui/application.html.erb +0 -17
- data/lib/better_ui/railtie.rb +0 -20
data/lib/better_ui/engine.rb
CHANGED
|
@@ -1,14 +1,101 @@
|
|
|
1
|
+
require 'view_component'
|
|
2
|
+
require 'redcarpet'
|
|
3
|
+
require 'tailwindcss-rails'
|
|
4
|
+
require 'coderay'
|
|
5
|
+
require 'font-awesome-sass'
|
|
6
|
+
begin
|
|
7
|
+
require 'lookbook'
|
|
8
|
+
rescue LoadError
|
|
9
|
+
# Lookbook non è richiesto, è una dipendenza opzionale
|
|
10
|
+
end
|
|
11
|
+
begin
|
|
12
|
+
require 'listen'
|
|
13
|
+
rescue LoadError
|
|
14
|
+
# Listen non è richiesto, è una dipendenza opzionale
|
|
15
|
+
end
|
|
16
|
+
begin
|
|
17
|
+
require 'action_cable'
|
|
18
|
+
rescue LoadError
|
|
19
|
+
# ActionCable non è richiesto, è una dipendenza opzionale
|
|
20
|
+
end
|
|
21
|
+
|
|
1
22
|
module BetterUi
|
|
23
|
+
# Engine Rails per Better UI
|
|
24
|
+
# Gestisce l'isolamento del namespace, le dipendenze, gli asset e le configurazioni
|
|
2
25
|
class Engine < ::Rails::Engine
|
|
3
26
|
isolate_namespace BetterUi
|
|
4
|
-
|
|
5
|
-
|
|
27
|
+
|
|
28
|
+
# Configurazione per rendere disponibili gli assets all'applicazione host
|
|
29
|
+
initializer 'better_ui.assets' do |app|
|
|
30
|
+
# Aggiungi i percorsi asset
|
|
31
|
+
app.config.assets.paths << root.join('app', 'assets', 'stylesheets')
|
|
32
|
+
app.config.assets.paths << root.join('app', 'assets', 'images')
|
|
33
|
+
app.config.assets.paths << root.join('app', 'assets', 'fonts')
|
|
34
|
+
|
|
35
|
+
# Aggiungi i file SCSS e CSS alla precompilazione
|
|
36
|
+
if app.config.respond_to?(:assets)
|
|
37
|
+
app.config.assets.precompile += %w(
|
|
38
|
+
better_ui/application.css
|
|
39
|
+
better_ui/components/*.css
|
|
40
|
+
better_ui/components/**/*.css
|
|
41
|
+
better_ui/components/index.css
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Configurazione per Propshaft se disponibile
|
|
46
|
+
if defined?(Propshaft) && app.config.respond_to?(:asset_host)
|
|
47
|
+
app.config.asset_host = app.config.asset_host
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Assicuriamo che gli helper siano correttamente caricati
|
|
52
|
+
config.autoload_paths << root.join('app', 'helpers')
|
|
53
|
+
config.eager_load_paths << root.join('app', 'helpers')
|
|
54
|
+
|
|
55
|
+
# Caricamento dei componenti helper
|
|
56
|
+
initializer 'better_ui.load_helpers', before: :load_config_initializers do
|
|
57
|
+
# Carica prima i componenti singoli
|
|
58
|
+
Dir.glob(root.join('app/helpers/better_ui/general/components/*.rb')).sort.each do |component|
|
|
59
|
+
require component
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Poi carica il general_helper che li unisce tutti
|
|
63
|
+
require_relative '../../app/helpers/better_ui/general_helper' if File.exist?(root.join('app/helpers/better_ui/general_helper.rb'))
|
|
64
|
+
|
|
65
|
+
# Infine carica il modulo principale
|
|
66
|
+
require_relative '../../app/helpers/better_ui_helper' if File.exist?(root.join('app/helpers/better_ui_helper.rb'))
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Configurazione per rendere disponibili i componenti all'applicazione host
|
|
70
|
+
initializer 'better_ui.view_helpers' do
|
|
6
71
|
ActiveSupport.on_load :action_controller do
|
|
7
|
-
helper BetterUi::
|
|
72
|
+
helper BetterUi::Helper if defined?(BetterUi::Helper)
|
|
8
73
|
end
|
|
9
|
-
|
|
74
|
+
|
|
10
75
|
ActiveSupport.on_load :action_view do
|
|
11
|
-
include BetterUi::
|
|
76
|
+
include BetterUi::Helper if defined?(BetterUi::Helper)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Configurazione per ViewComponent
|
|
81
|
+
config.view_component.preview_paths ||= []
|
|
82
|
+
config.view_component.preview_paths << root.join('test', 'components', 'previews')
|
|
83
|
+
|
|
84
|
+
# Configurazione per Lookbook in sviluppo e test
|
|
85
|
+
if defined?(Lookbook)
|
|
86
|
+
initializer 'better_ui.lookbook' do
|
|
87
|
+
if Rails.env.development? || Rails.env.test?
|
|
88
|
+
config.lookbook = Lookbook
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Configurazione per l'uso personalizzato dei componenti
|
|
94
|
+
initializer 'better_ui.custom_configuration', before: :load_config_initializers do |app|
|
|
95
|
+
app.config.to_prepare do
|
|
96
|
+
BetterUi.configure do |config|
|
|
97
|
+
# Configurazione di default, può essere sovrascritta dall'applicazione host
|
|
98
|
+
end
|
|
12
99
|
end
|
|
13
100
|
end
|
|
14
101
|
end
|
data/lib/better_ui/version.rb
CHANGED
data/lib/better_ui.rb
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
require "better_ui/version"
|
|
2
2
|
require "better_ui/engine"
|
|
3
|
-
require "better_ui/railtie"
|
|
4
|
-
|
|
5
|
-
require "font-awesome-sass"
|
|
6
3
|
|
|
7
4
|
module BetterUi
|
|
8
|
-
|
|
5
|
+
class Configuration
|
|
6
|
+
attr_accessor :button_defaults, :alert_defaults, :card_defaults, :tabs_defaults
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@button_defaults = {}
|
|
10
|
+
@alert_defaults = {}
|
|
11
|
+
@card_defaults = {}
|
|
12
|
+
@tabs_defaults = {}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def configuration
|
|
18
|
+
@configuration ||= Configuration.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def configure
|
|
22
|
+
yield(configuration) if block_given?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Metodo utile per accedere al percorso degli stilesheets
|
|
26
|
+
def stylesheets_path
|
|
27
|
+
File.join(File.dirname(__FILE__), '..', 'app', 'assets', 'stylesheets')
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Caricamento dei generator
|
|
33
|
+
require 'rails/generators'
|
|
34
|
+
if defined?(Rails::Generators)
|
|
35
|
+
require 'generators/better_ui/stylesheet_generator'
|
|
36
|
+
require 'generators/better_ui/install_generator'
|
|
9
37
|
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BetterUi
|
|
4
|
+
module Generators
|
|
5
|
+
# Generatore per l'installazione di Better UI in un'applicazione Rails
|
|
6
|
+
#
|
|
7
|
+
# Questo generatore:
|
|
8
|
+
# 1. Aggiunge le dipendenze necessarie
|
|
9
|
+
# 2. Monta l'engine nelle routes
|
|
10
|
+
# 3. Aggiunge gli asset all'applicazione
|
|
11
|
+
# 4. Crea un file di configurazione initializer
|
|
12
|
+
# 5. Genera i file di stile personalizzabili (opzionalmente)
|
|
13
|
+
class InstallGenerator < Rails::Generators::Base
|
|
14
|
+
source_root File.expand_path('templates', __dir__)
|
|
15
|
+
|
|
16
|
+
desc "Installa Better UI nell'applicazione Rails"
|
|
17
|
+
|
|
18
|
+
class_option :skip_routes, type: :boolean, default: false,
|
|
19
|
+
desc: "Salta l'aggiunta del mount engine nelle routes"
|
|
20
|
+
class_option :skip_stylesheets, type: :boolean, default: false,
|
|
21
|
+
desc: "Salta la generazione dei file di stile personalizzabili"
|
|
22
|
+
class_option :skip_config, type: :boolean, default: false,
|
|
23
|
+
desc: "Salta la creazione del file di configurazione"
|
|
24
|
+
|
|
25
|
+
def mount_engine
|
|
26
|
+
return if options[:skip_routes]
|
|
27
|
+
|
|
28
|
+
route_file = "config/routes.rb"
|
|
29
|
+
|
|
30
|
+
if File.exist?(route_file)
|
|
31
|
+
mount_code = " mount BetterUi::Engine => '/better_ui'"
|
|
32
|
+
|
|
33
|
+
append_to_file route_file, injectible_routes(mount_code)
|
|
34
|
+
|
|
35
|
+
say "Engine di Better UI montato in #{route_file}", :green
|
|
36
|
+
else
|
|
37
|
+
say "File routes.rb non trovato. Salta il montaggio dell'engine.", :yellow
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def copy_initializer
|
|
42
|
+
return if options[:skip_config]
|
|
43
|
+
|
|
44
|
+
template "initializer.rb", "config/initializers/better_ui.rb"
|
|
45
|
+
say "File di configurazione creato in config/initializers/better_ui.rb", :green
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def add_assets
|
|
49
|
+
application_css = "app/assets/stylesheets/application.css"
|
|
50
|
+
application_scss = "app/assets/stylesheets/application.scss"
|
|
51
|
+
|
|
52
|
+
file_to_update = if File.exist?(application_scss)
|
|
53
|
+
application_scss
|
|
54
|
+
elsif File.exist?(application_css)
|
|
55
|
+
application_css
|
|
56
|
+
else
|
|
57
|
+
nil
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if file_to_update
|
|
61
|
+
if file_to_update.end_with?('.css')
|
|
62
|
+
inject_into_file file_to_update, " *= require better_ui/application\n", before: " */\n"
|
|
63
|
+
else
|
|
64
|
+
append_to_file file_to_update, "\n@import 'better_ui/application';\n"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
say "Better UI assets aggiunti a #{file_to_update}", :green
|
|
68
|
+
else
|
|
69
|
+
say "File CSS dell'applicazione non trovato. Salta l'aggiunta degli assets.", :yellow
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def create_stylesheets
|
|
74
|
+
return if options[:skip_stylesheets]
|
|
75
|
+
|
|
76
|
+
generate "better_ui:stylesheet"
|
|
77
|
+
say "Fogli di stile personalizzabili generati", :green
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def show_instructions
|
|
81
|
+
say "\n========================================================", :green
|
|
82
|
+
say "Better UI installato con successo!", :green
|
|
83
|
+
say "========================================================", :green
|
|
84
|
+
say "\nPer utilizzare i componenti nella tua applicazione:", :blue
|
|
85
|
+
say "- Accedi a http://localhost:3000/better_ui per vedere la documentazione", :blue
|
|
86
|
+
say "- Utilizza i componenti nel tuo codice, ad esempio:", :blue
|
|
87
|
+
say " <%= render BetterUi::General::ButtonComponent.new(label: 'Clicca qui') %>", :blue
|
|
88
|
+
say "\nPer personalizzare i componenti, modifica i file in:", :blue
|
|
89
|
+
say " app/assets/stylesheets/components/", :blue
|
|
90
|
+
say "- I file *_overrides.scss contengono le classi vuote per le personalizzazioni", :blue
|
|
91
|
+
say "\nPer configurare i valori predefiniti, modifica:", :blue
|
|
92
|
+
say " config/initializers/better_ui.rb", :blue
|
|
93
|
+
say "\n========================================================\n", :green
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
|
|
98
|
+
def injectible_routes(mount_code)
|
|
99
|
+
"\n#{mount_code}\n"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BetterUi
|
|
4
|
+
module Generators
|
|
5
|
+
# Generatore per creare file SCSS personalizzati per i componenti BetterUI
|
|
6
|
+
#
|
|
7
|
+
# Questo generatore crea:
|
|
8
|
+
# 1. Un foglio di stile principale che importa tutti i componenti usando @use/@forward
|
|
9
|
+
# 2. File di override per ogni componente che permettono personalizzazioni senza modificare i file originali
|
|
10
|
+
# 3. Un file indice che raccoglie tutti gli override usando @forward
|
|
11
|
+
class StylesheetGenerator < Rails::Generators::Base
|
|
12
|
+
source_root File.expand_path('templates', __dir__)
|
|
13
|
+
|
|
14
|
+
desc "Genera un foglio di stile SCSS di base per personalizzare i componenti di BetterUI"
|
|
15
|
+
|
|
16
|
+
# Opzioni configurabili
|
|
17
|
+
class_option :prefix, type: :string, default: "custom",
|
|
18
|
+
desc: "Prefisso da utilizzare per il foglio di stile (default: 'custom')"
|
|
19
|
+
class_option :path, type: :string, default: "app/assets/stylesheets",
|
|
20
|
+
desc: "Path dove installare i file CSS all'interno della cartella app (default: 'app/assets/stylesheets')"
|
|
21
|
+
|
|
22
|
+
# Lista dei file dei componenti da gestire
|
|
23
|
+
COMPONENT_FILES = [
|
|
24
|
+
'_variables.scss',
|
|
25
|
+
'_button.scss',
|
|
26
|
+
'_heading.scss',
|
|
27
|
+
'_breadcrumb.scss',
|
|
28
|
+
'_link.scss',
|
|
29
|
+
'_panel.scss',
|
|
30
|
+
'_icon.scss',
|
|
31
|
+
'_table.scss',
|
|
32
|
+
'_badge.scss',
|
|
33
|
+
'_spinner.scss',
|
|
34
|
+
'_avatar.scss',
|
|
35
|
+
'_card.scss'
|
|
36
|
+
].freeze
|
|
37
|
+
|
|
38
|
+
# Crea il foglio di stile principale
|
|
39
|
+
def create_stylesheet
|
|
40
|
+
# Crea il file principale che importa tutti i componenti
|
|
41
|
+
template "components_stylesheet.scss",
|
|
42
|
+
File.join(options[:path], "#{options[:prefix]}_better_ui.scss")
|
|
43
|
+
|
|
44
|
+
# Crea la directory dei componenti se non esiste
|
|
45
|
+
directory = File.join(options[:path], "components")
|
|
46
|
+
FileUtils.mkdir_p(directory) unless File.directory?(directory)
|
|
47
|
+
|
|
48
|
+
# Crea il file indice che raccoglie tutti gli override
|
|
49
|
+
template "index.scss", File.join(directory, "_index.scss")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Crea i file di override per ogni componente
|
|
53
|
+
def create_overrides
|
|
54
|
+
# Crea la directory dei componenti se non esiste
|
|
55
|
+
directory = File.join(options[:path], "components")
|
|
56
|
+
FileUtils.mkdir_p(directory) unless File.directory?(directory)
|
|
57
|
+
|
|
58
|
+
# Crea i file di override per ogni componente
|
|
59
|
+
COMPONENT_FILES.each do |filename|
|
|
60
|
+
# Nome del file di override (es. _button_overrides.scss)
|
|
61
|
+
override_filename = filename.sub('.scss', '_overrides.scss')
|
|
62
|
+
override_path = File.join(directory, override_filename)
|
|
63
|
+
|
|
64
|
+
# Crea il file di override solo se non esiste già
|
|
65
|
+
unless File.exist?(override_path)
|
|
66
|
+
# Percorso del file template originale
|
|
67
|
+
template_path = File.join(self.class.source_root, "components", filename)
|
|
68
|
+
|
|
69
|
+
# Se il file template esiste, crea il file di override basato su di esso
|
|
70
|
+
if File.exist?(template_path)
|
|
71
|
+
original_content = File.read(template_path)
|
|
72
|
+
override_content = generate_empty_override(original_content, filename)
|
|
73
|
+
create_file override_path, override_content
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Mostra le istruzioni README dopo l'esecuzione del generatore
|
|
80
|
+
def show_readme
|
|
81
|
+
readme "README" if behavior == :invoke
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
# Genera un file di override vuoto con le stesse classi del file originale
|
|
87
|
+
#
|
|
88
|
+
# @param content [String] Il contenuto del file SCSS originale
|
|
89
|
+
# @param filename [String] Il nome del file del componente
|
|
90
|
+
# @return [String] Il contenuto formattato del file di override
|
|
91
|
+
def generate_empty_override(content, filename)
|
|
92
|
+
# Estrae il nome del componente dal nome file (es. "_button.scss" -> "button")
|
|
93
|
+
component_name = filename.sub('_', '').sub('.scss', '')
|
|
94
|
+
|
|
95
|
+
# Intestazione del file di override
|
|
96
|
+
result = "/* ==============================\n"
|
|
97
|
+
result += " * #{component_name.capitalize} Component Overrides\n"
|
|
98
|
+
result += " * ==============================\n"
|
|
99
|
+
result += " * Questo file contiene le classi vuote per sovrascrivere gli stili di default.\n"
|
|
100
|
+
result += " * Aggiungi qui le tue personalizzazioni.\n"
|
|
101
|
+
result += " */\n\n"
|
|
102
|
+
|
|
103
|
+
# Aggiungiamo il layer di Tailwind se presente nell'originale
|
|
104
|
+
if content.include?('@layer components')
|
|
105
|
+
result += "@layer components {\n"
|
|
106
|
+
layer_present = true
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Estrae le classi principali (Block) usando regex
|
|
110
|
+
class_matches = content.scan(/\.(bui-[a-zA-Z0-9_-]+)\s*\{/)
|
|
111
|
+
class_matches.flatten.uniq.each do |css_class|
|
|
112
|
+
result += layer_present ? " " : ""
|
|
113
|
+
result += ".#{css_class} {\n // Aggiungi personalizzazioni qui\n#{layer_present ? " " : ""}}\n\n"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Estrae classi modifier (es. &--small, &__icon, ecc.)
|
|
117
|
+
modifier_matches = content.scan(/&([a-zA-Z0-9_-]+)\s*\{/)
|
|
118
|
+
if !modifier_matches.empty?
|
|
119
|
+
# Raggruppa i modifier per classe principale
|
|
120
|
+
main_classes = class_matches.flatten.uniq
|
|
121
|
+
main_classes.each do |main_class|
|
|
122
|
+
# Estrae tutti i modifier di questa classe principale
|
|
123
|
+
class_content = extract_class_block(content, main_class)
|
|
124
|
+
modifiers = class_content.scan(/&([a-zA-Z0-9_-]+)\s*\{/).flatten.uniq
|
|
125
|
+
|
|
126
|
+
if !modifiers.empty?
|
|
127
|
+
result += layer_present ? " " : ""
|
|
128
|
+
result += ".#{main_class} {\n"
|
|
129
|
+
|
|
130
|
+
modifiers.each do |modifier|
|
|
131
|
+
result += layer_present ? " " : " "
|
|
132
|
+
result += "&#{modifier} {\n // Aggiungi personalizzazioni qui\n#{layer_present ? " " : " "}}\n\n"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
result += layer_present ? " " : ""
|
|
136
|
+
result += "}\n\n"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Chiude il layer se presente
|
|
142
|
+
result += "}\n" if layer_present
|
|
143
|
+
|
|
144
|
+
result
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Estrae il blocco di codice relativo a una classe CSS specifica
|
|
148
|
+
#
|
|
149
|
+
# @param content [String] Il contenuto del file SCSS completo
|
|
150
|
+
# @param css_class [String] Il nome della classe CSS da estrarre
|
|
151
|
+
# @return [String] Il blocco di codice della classe
|
|
152
|
+
def extract_class_block(content, css_class)
|
|
153
|
+
regex = /\.(#{css_class})\s*\{((?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*)\}/m
|
|
154
|
+
match = content.match(regex)
|
|
155
|
+
match ? match[2] : ""
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
==========================================================
|
|
2
|
+
BETTER UI
|
|
3
|
+
==========================================================
|
|
4
|
+
|
|
5
|
+
Fogli di stile per componenti generati con successo!
|
|
6
|
+
|
|
7
|
+
STRUTTURA DEI FILE:
|
|
8
|
+
----------------------------------------------------------
|
|
9
|
+
I seguenti file sono stati creati:
|
|
10
|
+
|
|
11
|
+
1. File principale:
|
|
12
|
+
* <%= options[:prefix] %>_better_ui_components.scss
|
|
13
|
+
|
|
14
|
+
2. File indice:
|
|
15
|
+
* components/_index.scss (raccoglie tutti gli override usando @forward)
|
|
16
|
+
|
|
17
|
+
3. File di override:
|
|
18
|
+
* components/_variables_overrides.scss
|
|
19
|
+
* components/_button_overrides.scss
|
|
20
|
+
* components/_heading_overrides.scss
|
|
21
|
+
... e altri file di override
|
|
22
|
+
|
|
23
|
+
COME UTILIZZARE:
|
|
24
|
+
----------------------------------------------------------
|
|
25
|
+
1. Il file principale già utilizza @use per importare tutti i componenti:
|
|
26
|
+
@use 'better_ui/components' as bui;
|
|
27
|
+
@use 'components/index' as overrides;
|
|
28
|
+
|
|
29
|
+
2. Personalizza i componenti modificando i file *_overrides.scss:
|
|
30
|
+
Ogni file di override contiene classi vuote corrispondenti
|
|
31
|
+
alle classi originali, pronte per essere personalizzate.
|
|
32
|
+
|
|
33
|
+
3. Se hai bisogno di aggiungere nuovi file SCSS, ricorda di includere
|
|
34
|
+
il riferimento nel file components/_index.scss usando @forward.
|
|
35
|
+
|
|
36
|
+
BEST PRACTICES:
|
|
37
|
+
----------------------------------------------------------
|
|
38
|
+
* Segui la metodologia BEM per le tue personalizzazioni
|
|
39
|
+
* Usa le variabili CSS definite in _variables.scss
|
|
40
|
+
* Mantieni la coerenza visiva tra i componenti
|
|
41
|
+
* Aggiungi nuovi modificatori nei file di override
|
|
42
|
+
|
|
43
|
+
ESEMPIO DI PERSONALIZZAZIONE:
|
|
44
|
+
----------------------------------------------------------
|
|
45
|
+
// In _button_overrides.scss
|
|
46
|
+
@layer components {
|
|
47
|
+
.bui-button {
|
|
48
|
+
// Modifica la classe base
|
|
49
|
+
@apply transition-all;
|
|
50
|
+
|
|
51
|
+
// Modifica uno specifico modificatore
|
|
52
|
+
&--primary {
|
|
53
|
+
@apply bg-indigo-600 hover:bg-indigo-700;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Aggiungi un nuovo modificatore
|
|
57
|
+
&--custom {
|
|
58
|
+
@apply bg-gradient-to-r from-purple-500 to-pink-500;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
===============================================================================
|
|
64
|
+
|
|
65
|
+
Installazione completata!
|
|
66
|
+
|
|
67
|
+
Il tuo foglio di stile SCSS per la personalizzazione dei componenti di BetterUi
|
|
68
|
+
è stato creato in:
|
|
69
|
+
|
|
70
|
+
<%= options[:path] %>/<%= options[:prefix] %>_better_ui_components.scss
|
|
71
|
+
|
|
72
|
+
===============================================================================
|
|
73
|
+
|
|
74
|
+
PROSSIMI PASSI:
|
|
75
|
+
|
|
76
|
+
1. Assicurati che Tailwind CSS sia correttamente configurato nel tuo progetto.
|
|
77
|
+
Questo foglio di stile utilizza le utility @apply di Tailwind CSS.
|
|
78
|
+
|
|
79
|
+
2. Importa il foglio di stile nella tua applicazione:
|
|
80
|
+
|
|
81
|
+
In app/assets/stylesheets/application.scss:
|
|
82
|
+
|
|
83
|
+
@use '<%= options[:prefix] %>_better_ui_components';
|
|
84
|
+
|
|
85
|
+
Oppure in app/assets/stylesheets/application.css:
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
*= require <%= options[:prefix] %>_better_ui_components
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
Se hai utilizzato un path personalizzato, assicurati di importare
|
|
92
|
+
correttamente il file dal percorso specificato.
|
|
93
|
+
|
|
94
|
+
3. I file SCSS utilizzano la moderna sintassi @use e @forward di Sass
|
|
95
|
+
invece della sintassi @import deprecata. Questo ti permette di evitare
|
|
96
|
+
conflitti di nome e organizzare meglio il tuo codice SCSS.
|
|
97
|
+
|
|
98
|
+
4. Personalizza le variabili SCSS e le classi secondo le tue esigenze.
|
|
99
|
+
Il foglio di stile utilizza le classi di Tailwind CSS tramite la direttiva
|
|
100
|
+
@apply, consentendoti di sfruttare l'ecosistema Tailwind mantenendo un
|
|
101
|
+
codice SCSS organizzato e modulare.
|
|
102
|
+
|
|
103
|
+
5. Nei componenti Ruby, usa le classi con prefisso 'bui-' invece di includere
|
|
104
|
+
direttamente le classi Tailwind. Ad esempio per i bottoni:
|
|
105
|
+
|
|
106
|
+
# Esempio di utilizzo di classi CSS personalizzate
|
|
107
|
+
BUTTON_TYPES = {
|
|
108
|
+
default: "bui-btn-default",
|
|
109
|
+
red: "bui-btn-red",
|
|
110
|
+
blue: "bui-btn-blue"
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Questo approccio centralizza gli stili nel foglio SCSS e rende più facile
|
|
114
|
+
mantenere e modificare l'aspetto dei componenti.
|
|
115
|
+
|
|
116
|
+
6. Assicurati che il tuo foglio di stile venga caricato dopo i fogli di stile
|
|
117
|
+
di BetterUI per sovrascrivere correttamente gli stili predefiniti.
|
|
118
|
+
|
|
119
|
+
===============================================================================
|
|
120
|
+
|
|
121
|
+
Per ulteriori informazioni sulla personalizzazione dei componenti,
|
|
122
|
+
consulta la documentazione ufficiale su:
|
|
123
|
+
https://github.com/YOUR_USERNAME/better_ui
|
|
124
|
+
|
|
125
|
+
===============================================================================
|