Class: BetterUi::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#copy_theme_file ⇒ Object



27
28
29
30
31
32
# File 'lib/generators/better_ui/install/install_generator.rb', line 27

def copy_theme_file
  return unless options[:copy_theme]

  say "Copying BetterUi theme file for customization...", :green
  template "better_ui_theme.css.tt", "app/assets/stylesheets/better_ui_theme.css"
end

#install_npm_package ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/better_ui/install/install_generator.rb', line 15

def install_npm_package
  say "Installing @pandev-srl/better-ui npm package...", :green

  if File.exist?(File.join(destination_root, "yarn.lock"))
    run "yarn add @pandev-srl/better-ui"
  elsif File.exist?(File.join(destination_root, "pnpm-lock.yaml"))
    run "pnpm add @pandev-srl/better-ui"
  else
    run "npm install @pandev-srl/better-ui"
  end
end

#show_post_install_message ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
79
80
81
82
83
84
# File 'lib/generators/better_ui/install/install_generator.rb', line 34

def show_post_install_message
  say "\n"
  say "=" * 80, :green
  say "BetterUi installation complete!", :green
  say "=" * 80, :green
  say "\n"

  say "JavaScript Setup:", :cyan
  say "  Add to your JavaScript entry point (e.g., app/javascript/application.js):"
  say ""
  say "    import { Application } from \"@hotwired/stimulus\""
  say "    import { registerControllers } from \"@pandev-srl/better-ui\""
  say ""
  say "    const application = Application.start()"
  say "    registerControllers(application)"
  say "\n"

  say "CSS Setup:", :cyan

  if options[:copy_theme]
    say "  Theme file copied to: app/assets/stylesheets/better_ui_theme.css"
    say "  Import in your main CSS file:"
    say ""
    say "    @import \"tailwindcss\";"
    say "    @import \"./better_ui_theme.css\";"
  else
    say "  Add to your main CSS file (e.g., app/assets/stylesheets/application.css):"
    say ""
    say "    /* Option 1: Import pre-built CSS */"
    say "    @import \"@pandev-srl/better-ui/css\";"
    say ""
    say "    /* Option 2: Import individual modules for customization */"
    say "    @import \"tailwindcss\";"
    say "    @import \"@pandev-srl/better-ui/theme\";       /* Design tokens */"
    say "    @import \"@pandev-srl/better-ui/typography\";  /* Typography utilities */"
    say "    @import \"@pandev-srl/better-ui/utilities\";   /* General utilities */"
  end

  say "\n"
  say "Tailwind Configuration:", :cyan
  say "  Ensure Tailwind scans BetterUi components for classes:"
  say "  Add to your CSS file:"
  say ""
  say "    @source \"../../../vendor/bundle/**/*.{rb,erb}\";"
  say "\n"

  say "Usage:", :cyan
  say "  <%= render BetterUi::ButtonComponent.new(label: \"Click me\") %>"
  say "\n"
  say "=" * 80, :green
end