Class: MaquinaComponents::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_engine_css_importObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/maquina_components/install/install_generator.rb', line 29

def add_engine_css_import
  css_path = "app/assets/tailwind/application.css"
  full_path = File.join(destination_root, css_path)

  unless File.exist?(full_path)
    say_status :skip, "#{css_path} not found", :yellow
    return
  end

  import_line = '@import "../builds/tailwind/maquina_components_engine.css";'

  if File.read(full_path).include?(import_line)
    say_status :skip, "Engine CSS import already present", :blue
    return
  end

  # Insert after @import "tailwindcss"; or @import 'tailwindcss'; line
  inject_into_file css_path, after: /@import\s+["']tailwindcss["'];?\n/ do
    "\n#{import_line}\n"
  end

  say_status :insert, "Added maquina_components engine CSS import", :green
end

#add_theme_variablesObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/maquina_components/install/install_generator.rb', line 53

def add_theme_variables
  return if options[:skip_theme]

  css_path = "app/assets/tailwind/application.css"
  full_path = File.join(destination_root, css_path)

  unless File.exist?(full_path)
    say_status :skip, "#{css_path} not found", :yellow
    return
  end

  if File.read(full_path).include?("--color-primary:")
    say_status :skip, "Theme variables already present", :blue
    return
  end

  theme_content = File.read(File.expand_path("templates/theme.css.tt", __dir__))

  append_to_file css_path, "\n#{theme_content}"

  say_status :append, "Added theme variables to application.css", :green
end

#check_tailwindcss_railsObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/maquina_components/install/install_generator.rb', line 17

def check_tailwindcss_rails
  css_path = "app/assets/tailwind/application.css"

  unless File.exist?(File.join(destination_root, css_path))
    say_status :warning, "tailwindcss-rails doesn't appear to be installed", :yellow
    say "Please install tailwindcss-rails first:"
    say "  bundle add tailwindcss-rails"
    say "  rails tailwindcss:install"
    say ""
  end
end

#create_helperObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/generators/maquina_components/install/install_generator.rb', line 76

def create_helper
  return if options[:skip_helper]

  helper_path = "app/helpers/maquina_components_helper.rb"
  full_path = File.join(destination_root, helper_path)

  if File.exist?(full_path)
    say_status :skip, "#{helper_path} already exists", :blue
    return
  end

  template "maquina_components_helper.rb.tt", helper_path
  say_status :create, helper_path, :green
end

#show_post_install_messageObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/generators/maquina_components/install/install_generator.rb', line 91

def show_post_install_message
  say ""
  say "=" * 60
  say "  maquina_components installed successfully!", :green
  say "=" * 60
  say ""
  say "Next steps:"
  say ""
  say "1. Customize theme variables in app/assets/tailwind/application.css"
  say "   to match your design system."
  say ""
  say "2. Override the icon helper in app/helpers/maquina_components_helper.rb"
  say "   to use your own icon system (Heroicons, Lucide, etc.)."
  say ""
  say "3. Start using components in your views:"
  say ""
  say '   <%= render "components/card" do %>'
  say '     <%= render "components/card/header" do %>'
  say '       <%= render "components/card/title", text: "Hello" %>'
  say "     <% end %>"
  say "   <% end %>"
  say ""
  say "4. For form elements, use data attributes:"
  say ""
  say '   <%= f.text_field :email, data: { component: "input" } %>'
  say '   <%= f.submit "Save", data: { component: "button", variant: "primary" } %>'
  say ""
  say "Documentation: https://github.com/maquina-app/maquina_components"
  say ""
end