Class: Swage::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_dependenciesObject



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

def add_dependencies
  deps = %W[ tailwindcss-rails phlex-rails phlexible superform ruby_ui ]
  missing = []
  deps.each do |d|
    unless Gem.loaded_specs.has_key?(d)
      say "missing #{d} in gemfile"
      missing << d
    end
  end

  if missing.any?
    return if @engine && missing.length == 1 && missing[0] == "ruby_ui"
    if yes?("would you like to automatically install the missing dependencies?")
      add_source "https://rubygems.org" do
        deps.each do |d|
          gem d
        end
      end
    else
      exit 1
    end
  end

  # because rails is silly and won't let you do stuff unless you have everything as a gem already
  return if @engine && !@override
  add_source "https://rubygems.org" do
    gem "tailwindcss-rails"
    gem "phlex"
    gem "superform"
    # gem "rogue"
  end
end

#check_for_engineObject



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

def check_for_engine
  @engine = options["engine"] # set use instance variables because they look nicer

  if probably_engine? && !@engine
    if yes?("This appears to be an engine. do you wish to insatll swage as such?")
      say "Installing in engine mode. Hint: use `rails g swage:install --engine`"
      @engine = true
    end
  end
end

#check_for_jsObject



31
32
33
34
35
36
37
38
# File 'lib/generators/swage/install/install_generator.rb', line 31

def check_for_js
  return if @engine # engines don't have their own js ecosystem
  unless using_importmap? || using_bun? || using_yarn? || using_npm? || using_pnpm?
    if yes?("No javascript package manager was detected. Do you wish to exit now, or continue and install missing requirements manually?")
      exit 0
    end
  end
end

#check_for_overrideObject



23
24
25
26
27
28
29
# File 'lib/generators/swage/install/install_generator.rb', line 23

def check_for_override
  if @engine
    @override = options["override"]
  else
    @override = true
  end
end

#create_application_viewObject



129
130
131
132
# File 'lib/generators/swage/install/install_generator.rb', line 129

def create_application_view
  remove_file File.join(destination_root, "app/views/layouts/application.html.erb")
  template "application_view.rb.tt", File.join(destination_root, "app/views/layouts/application.rb") if @override
end

#create_base_componentObject



109
110
111
# File 'lib/generators/swage/install/install_generator.rb', line 109

def create_base_component
  template "base_component.rb.tt", File.join(destination_root, "app/components/base.rb"), force: true if @override
end

#create_base_formObject



121
122
123
# File 'lib/generators/swage/install/install_generator.rb', line 121

def create_base_form
  template "form.rb.tt", File.join(destination_root, "app/components/form.rb"), force: true if @override
end

#create_base_viewObject



117
118
119
# File 'lib/generators/swage/install/install_generator.rb', line 117

def create_base_view
  template "base_view.rb.tt", File.join(destination_root, "app/views/base.rb"), force: true if @override
end

#create_flash_componentObject



113
114
115
# File 'lib/generators/swage/install/install_generator.rb', line 113

def create_flash_component
  template "flash.rb.tt", File.join(destination_root, "app/components/flash.rb"), force: true if @override
end

#create_initializerObject



104
105
106
107
# File 'lib/generators/swage/install/install_generator.rb', line 104

def create_initializer
  say "install swage"
  template "swage.rb.tt", File.join(destination_root, "config/initializers/swage.rb"), force: true
end

#insatll_ruby_uiObject



92
93
94
95
96
97
98
# File 'lib/generators/swage/install/install_generator.rb', line 92

def insatll_ruby_ui
  if !@engine || (@engine && @override)
    say "install rubyui"
    generate "ruby_ui:install"
    generate "ruby_ui:component:all"
  end
end

#install_phlexObject



80
81
82
83
84
# File 'lib/generators/swage/install/install_generator.rb', line 80

def install_phlex
  return if @engine
  say "install phlex"
  generate "phlex:install"
end

#install_superformObject



86
87
88
89
90
# File 'lib/generators/swage/install/install_generator.rb', line 86

def install_superform
  return if @engine
  say "install superform"
  generate "superform:install"
end

#install_tailwindObject



73
74
75
76
77
78
# File 'lib/generators/swage/install/install_generator.rb', line 73

def install_tailwind
  if !@engine || (@engine && @override)
    say "install tailwind"
    execute_command "rake", "tailwindcss:install"
  end
end

#install_tw_animate_cssObject

because this file is usually missing while installing ruby_ui



100
101
102
# File 'lib/generators/swage/install/install_generator.rb', line 100

def install_tw_animate_css # because this file is usually missing while installing ruby_ui
  template "tw-animate-css.js.tt", File.join(destination_root, "vendor/javascript/tw-animate-css.js") unless @engine
end

#modify_application_controllerObject



125
126
127
# File 'lib/generators/swage/install/install_generator.rb', line 125

def modify_application_controller
  template "application_controller.rb.tt", File.join(destination_root, "app/controllers/application_controller.rb") if @override
end

#modify_engineObject



134
135
136
137
138
# File 'lib/generators/swage/install/install_generator.rb', line 134

def modify_engine
  return unless @engine
  @name ||= get_name
  template "engine.rb.tt", File.join(destination_root, "lib", get_name, "engine.rb")
end