Class: Maquina::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Maquina::InstallGenerator
- Defined in:
- lib/generators/maquina/install_generator.rb
Instance Method Summary collapse
- #add_concerns ⇒ Object
- #add_route ⇒ Object
- #copy_controllers ⇒ Object
- #copy_layout ⇒ Object
-
#copy_migrations ⇒ Object
def copy_stimulus_controllers Dir.glob(File.join(engine_stimulus_path, “*_controller.js”)) do |file| copy_file file, File.join(app_stimulus_path, File.basename(file)) end end.
- #copy_views ⇒ Object
-
#create_initializer_file ⇒ Object
TODO: Add this to application.rb insert_into_file “config/application.rb”, before: “ end” do <<EOF # Disable Rails’ field_with_errors functionality config.action_view.field_error_proc = proc { |html_tag, instance| html_tag.html_safe } EOF end.
Instance Method Details
#add_concerns ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/generators/maquina/install_generator.rb', line 24 def add_concerns inject_into_file "app/controllers/application_controller.rb", after: "ActionController::Base" do <<~EOF \n include Maquina::Authenticate EOF end end |
#add_route ⇒ Object
19 20 21 22 |
# File 'lib/generators/maquina/install_generator.rb', line 19 def add_route return if Rails.application.routes.routes.detect { |route| route.app.app == Maquina::Engine } route %(mount Maquina::Engine => "/") end |
#copy_controllers ⇒ Object
46 47 48 49 50 |
# File 'lib/generators/maquina/install_generator.rb', line 46 def copy_controllers empty_directory "app/controllers/maquina" copy_file File.join(engine_controllers_path, "maquina", "dashboard_controller.rb"), File.join(app_controllers_path, "maquina", "dashboard_controller.rb") end |
#copy_layout ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/maquina/install_generator.rb', line 32 def copy_layout empty_directory "app/views/layouts/maquina" directory File.join(engine_views_path, "layouts", "maquina"), File.join(app_views_path, "layouts", "maquina") gsub_file "app/views/layouts/maquina/application.html.erb", "maquina_importmap_tags", "javascript_importmap_tags" gsub_file "app/views/layouts/maquina/sessions.html.erb", "maquina_importmap_tags", "javascript_importmap_tags" end |
#copy_migrations ⇒ Object
def copy_stimulus_controllers
Dir.glob(File.join(engine_stimulus_path, "*_controller.js")) do |file|
copy_file file, File.join(app_stimulus_path, File.basename(file))
end
end
64 65 66 |
# File 'lib/generators/maquina/install_generator.rb', line 64 def copy_migrations rake "maquina:install:migrations" end |
#copy_views ⇒ Object
52 53 54 55 56 |
# File 'lib/generators/maquina/install_generator.rb', line 52 def copy_views empty_directory "app/views/maquina/dashboard" directory File.join(engine_views_path, "maquina", "dashboard"), File.join(app_views_path, "maquina", "dashboard") end |
#create_initializer_file ⇒ Object
TODO: Add this to application.rb insert_into_file “config/application.rb”, before: “ end” do
<<EOF
# Disable Rails' field_with_errors functionality
config.action_view.field_error_proc = proc { |html_tag, instance| html_tag.html_safe }
EOF
end
15 16 17 |
# File 'lib/generators/maquina/install_generator.rb', line 15 def create_initializer_file template "config/initializers/maquina.rb" end |