Class: Wabi::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Wabi::Generators::InstallGenerator
- Defined in:
- lib/wabi/generators/install_generator.rb
Instance Method Summary collapse
- #copy_theme_controller ⇒ Object
- #copy_tokens ⇒ Object
- #init_lockfile ⇒ Object
- #print_next_steps ⇒ Object
-
#register_ui_acronym ⇒ Object
Components install into app/components/ui/ under the Components::UI namespace.
Instance Method Details
#copy_theme_controller ⇒ Object
21 22 23 24 25 |
# File 'lib/wabi/generators/install_generator.rb', line 21 def copy_theme_controller copy_file "controllers/wabi/theme_controller.js", "app/javascript/controllers/wabi/theme_controller.js", force: [:force], skip: ![:force] end |
#copy_tokens ⇒ Object
16 17 18 19 |
# File 'lib/wabi/generators/install_generator.rb', line 16 def copy_tokens copy_file "tokens.css", "app/assets/tailwind/wabi/tokens.css", force: [:force], skip: ![:force] end |
#init_lockfile ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/wabi/generators/install_generator.rb', line 27 def init_lockfile path = File.join(destination_root, "config/wabi.lock.json") FileUtils.mkdir_p(File.dirname(path)) return if File.exist?(path) lockfile = Wabi::Lockfile.load(path) lockfile.save end |
#print_next_steps ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wabi/generators/install_generator.rb', line 52 def print_next_steps say "\n Wabi installed. Next steps:", :green say "" say " 1. Import tokens AFTER the Tailwind import in app/assets/tailwind/application.css:" say " @import \"tailwindcss\";" say " @import \"./wabi/tokens.css\";" say "" say " 2. Use 'tailwind' (not 'application') in your stylesheet link tag:" say " stylesheet_link_tag \"tailwind\", \"data-turbo-track\": \"reload\"" say " (Rails 8.1's :app symbol also works if you keep the default ERB layout.)" say "" say " 3. Mount the theme controller on <html> in your layout:" say " <html data-controller=\"wabi--theme\">" say "" say " 4. Add components from the registry:" say " bin/rails g wabi:add button input card" say " Components autoload under Components::UI::* (Phlex 2.x convention)." say " Render them as: render Components::UI::Button.new" say "" say " 5. If Tailwind doesn't pick up component classes, add this near the top of" say " application.css (Tailwind 4 normally auto-detects .rb files, but in" say " unusual asset paths an explicit @source helps):" say " @source \"../../components/**/*.rb\";" say "" say " Run wabi:install --force later to refresh tokens.css and theme_controller.js" say " after a gem upgrade (your wabi.lock.json is preserved)." end |
#register_ui_acronym ⇒ Object
Components install into app/components/ui/ under the Components::UI namespace. Zeitwerk would expect Components::Ui for the “ui” dir, so the app 500s on the first component reference unless “UI” is a known acronym. Register it (idempotent — skipped if the file already exists).
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wabi/generators/install_generator.rb', line 39 def register_ui_acronym create_file "config/initializers/wabi.rb", <<~RUBY # frozen_string_literal: true # Wabi components live in app/components/ui/ under the Components::UI # namespace. Zeitwerk needs the "UI" acronym to map the ui/ directory # to the UI constant (otherwise it expects Components::Ui). ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym "UI" end RUBY end |