Class: Solrengine::Ui::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/solrengine/ui/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_lookbook_preview_layoutObject



45
46
47
48
49
50
# File 'lib/generators/solrengine/ui/install_generator.rb', line 45

def add_lookbook_preview_layout
  layout_path = "app/views/layouts/lookbook_preview.html.erb"
  return if File.exist?(layout_path)

  copy_file "lookbook_preview.html.erb", layout_path
end

#add_lookbook_preview_pathObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/solrengine/ui/install_generator.rb', line 31

def add_lookbook_preview_path
  app_file = "config/application.rb"
  content = File.read(app_file)
  return if content.include?("lookbook.preview_paths")

  inject_into_file app_file, before: /^  end/ do
    <<~RUBY

      # SolRengine UI Lookbook previews
      config.lookbook.preview_paths << File.join(Gem.loaded_specs["solrengine-ui"].full_gem_path, "previews") if defined?(Lookbook)
    RUBY
  end
end

#add_lookbook_routeObject



21
22
23
24
25
26
27
28
29
# File 'lib/generators/solrengine/ui/install_generator.rb', line 21

def add_lookbook_route
  route_file = "config/routes.rb"
  content = File.read(route_file)
  return if content.include?("Lookbook")

  inject_into_file route_file, after: "Rails.application.routes.draw do\n" do
    "  mount Lookbook::Engine, at: \"/lookbook\" if Rails.env.development?\n\n"
  end
end

#add_tailwind_sourceObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/solrengine/ui/install_generator.rb', line 8

def add_tailwind_source
  css_file = "app/assets/stylesheets/application.tailwind.css"
  return unless File.exist?(css_file)

  content = File.read(css_file)
  return if content.include?("solrengine-ui")

  gem_path = Gem.loaded_specs["solrengine-ui"]&.full_gem_path
  return unless gem_path

  append_to_file css_file, "\n/* SolRengine UI components */\n@source \"#{gem_path}/app\";\n"
end

#configure_lookbook_preview_layoutObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/generators/solrengine/ui/install_generator.rb', line 52

def configure_lookbook_preview_layout
  app_file = "config/application.rb"
  content = File.read(app_file)
  return if content.include?("lookbook.preview_layout")

  inject_into_file app_file, before: /^  end/ do
    <<~RUBY

      # SolRengine UI Lookbook preview layout (loads Tailwind + dark mode)
      config.lookbook.preview_layout = "lookbook_preview" if defined?(Lookbook)
    RUBY
  end
end

#show_post_installObject



66
67
68
69
70
71
72
73
74
# File 'lib/generators/solrengine/ui/install_generator.rb', line 66

def show_post_install
  say "\n  SolRengine UI installed!", :green
  say ""
  say "  Next steps:"
  say "    1. Add gem 'lookbook' to your Gemfile (development group) if not already added"
  say "    2. yarn add @solrengine/ui (for Stimulus controllers)"
  say "    3. bin/dev and visit /lookbook to see all components"
  say ""
end