Class: ActiveCanvas::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#choose_css_frameworkObject



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
# File 'lib/generators/active_canvas/install/install_generator.rb', line 43

def choose_css_framework
  say "Step 2: CSS Framework", :yellow
  say "-" * 40
  say "Choose which framework to use in the editor and public pages:"
  say ""
  say "  1. tailwind  - Tailwind CSS (recommended)"
  say "  2. bootstrap - Bootstrap 5"
  say "  3. none      - No framework"
  say ""

  framework = ask_value("Enter choice [tailwind]:", default: "tailwind")
  framework = framework.downcase.strip

  @css_framework = case framework
  when "tailwind", "1" then :tailwind
  when "bootstrap", "2" then :bootstrap5
  when "none", "3" then :none
  else :tailwind
  end

  if @css_framework == :tailwind
    setup_tailwind
  elsif @css_framework == :bootstrap5
    setup_bootstrap
  else
    say "→ No framework selected. You can change this in Admin > Settings.", :yellow
  end
  say ""
end

#configure_ai_featuresObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/generators/active_canvas/install/install_generator.rb', line 73

def configure_ai_features
  say "Step 3: AI Features", :yellow
  say "-" * 40
  say "ActiveCanvas includes AI-powered features:"
  say "  • Text/HTML generation from prompts"
  say "  • Image generation (DALL-E)"
  say "  • Screenshot to code conversion"
  say ""
  say "Supported providers:", :cyan
  say "  • OpenAI (GPT-4, DALL-E) - recommended"
  say "  • Anthropic (Claude)"
  say "  • OpenRouter (access to many models)"
  say ""

  @setup_ai = yes_no?("Configure AI API keys now?", default: true)

  if @setup_ai
    configure_ai_keys
  else
    say "→ Add API keys later in Admin > Settings > AI", :yellow
  end
  say ""
end

#create_initializerObject



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/generators/active_canvas/install/install_generator.rb', line 97

def create_initializer
  say "Step 4: Configuration", :yellow
  say "-" * 40

  @mount_path = ask_value("Mount path [/canvas]:", default: "/canvas")
  @mount_path = "/#{@mount_path}" unless @mount_path.start_with?("/")

  template "initializer.rb", "config/initializers/active_canvas.rb"
  say "✓ Created config/initializers/active_canvas.rb", :green
  say ""
end

#install_migrationsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/active_canvas/install/install_generator.rb', line 23

def install_migrations
  say "Step 1: Database Migrations", :yellow
  say "-" * 40

  if yes_no?("Copy ActiveCanvas migrations to your app?", default: true)
    rake "active_canvas:install:migrations"
    say "✓ Migrations copied", :green

    if yes_no?("Run migrations now?", default: true)
      rake "db:migrate"
      say "✓ Migrations completed", :green
    else
      say "→ Remember to run: bin/rails db:migrate", :yellow
    end
  else
    say "→ Skipped. Run later: bin/rails active_canvas:install:migrations", :yellow
  end
  say ""
end

#mount_engineObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/generators/active_canvas/install/install_generator.rb', line 109

def mount_engine
  @mount_path ||= "/canvas"
  return if options[:skip_route]

  say "Step 5: Routes", :yellow
  say "-" * 40

  routes_file = "config/routes.rb"
  if File.read(routes_file).include?("ActiveCanvas::Engine")
    say "✓ ActiveCanvas::Engine already mounted", :green
  else
    route "mount ActiveCanvas::Engine => '#{@mount_path}'"
    say "✓ Mounted ActiveCanvas at #{@mount_path}", :green
  end
  say ""
end

#show_completionObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/generators/active_canvas/install/install_generator.rb', line 136

def show_completion
  say "=" * 60, :green
  say "  Setup Complete!", :green
  say "=" * 60, :green
  say ""
  say "Next steps:", :yellow
  say ""
  say "  1. Start your Rails server:"
  say "     $ bin/rails server", :cyan
  say ""
  say "  2. Visit the admin panel:"
  say "     http://localhost:3000#{@mount_path}/admin", :cyan
  say ""
  say "  3. Configure authentication in:"
  say "     config/initializers/active_canvas.rb", :cyan
  say ""

  if @css_framework && @css_framework != :none
    say "  4. Your CSS framework (#{@css_framework}) is configured."
    say "     It will be loaded automatically in the editor.", :cyan
    say ""
  end

  unless @setup_ai
    say "  5. Add AI API keys in Admin > Settings > AI", :cyan
    say "     Or via environment variables / Rails credentials", :cyan
    say ""
  end

  say "Documentation: https://github.com/giovapanasiti/active_canvas"
  say ""
end

#sync_ai_modelsObject



126
127
128
129
130
131
132
133
134
# File 'lib/generators/active_canvas/install/install_generator.rb', line 126

def sync_ai_models
  if @setup_ai && yes_no?("Sync AI models now? (requires API keys in ENV)", default: false)
    say ""
    say "Syncing AI models...", :cyan
    rake "active_canvas:sync_models"
    say "✓ AI models synced", :green
  end
  say ""
end

#welcomeObject



13
14
15
16
17
18
19
20
21
# File 'lib/generators/active_canvas/install/install_generator.rb', line 13

def welcome
  say ""
  say "=" * 60, :cyan
  say "  Welcome to ActiveCanvas Setup Wizard", :cyan
  say "=" * 60, :cyan
  say ""
  say "This wizard will help you set up ActiveCanvas in your Rails app."
  say ""
end