Class: Binda::MaintenanceGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Binda::MaintenanceGenerator
- Defined in:
- lib/generators/binda/maintenance/maintenance_generator.rb
Instance Method Summary collapse
- #add_controller ⇒ Object
- #add_helper ⇒ Object
- #add_route ⇒ Object
- #add_templates ⇒ Object
- #end ⇒ Object
Instance Method Details
#add_controller ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 4 def add_controller puts "Maintenance page setup" puts "" puts "1) Adding controller" if File.exist?(Rails.root.join('app', 'controllers', 'maintenance_controller.rb' )) puts "-------------------------------------------------------------------------------" puts "WARNING: Apparently you have already a controller named MaintenanceController." puts "Unless you know what you are doing, delete it and run the generator again." puts "-------------------------------------------------------------------------------" exit end generate "controller", "maintenance index --no-assets --no-helper" inject_into_file Rails.root.join('app', 'controllers', 'maintenance_controller.rb'), after: "def index" do "\n render template: 'layouts/maintenance'" end end |
#add_helper ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 36 def add_helper ac_path = Rails.root.join('app', 'controllers', 'application_controller.rb' ) unless File.readlines(ac_path).grep(/::Binda::MaintenanceHelpers/).size > 0 inject_into_file ac_path, after: "ActionController::Base" do "\n include ::Binda::MaintenanceHelpers" end end end |
#add_route ⇒ Object
29 30 31 32 33 34 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 29 def add_route return if Rails.application.routes.named_routes.any?{ |key, _| key.to_s === "maintenance" } # replace 'maintenance/index' root with 'maintenance' route "get 'maintenance', to: 'maintenance#index', as: 'maintenance'" gsub_file Rails.root.join('config', 'routes.rb'), "get 'maintenance/index'", "" end |
#add_templates ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 21 def add_templates puts "2) Adding templates" template 'app/assets/javascripts/maintenance.js' template 'app/assets/stylesheets/maintenance.scss' template 'app/views/layouts/maintenance.html.erb' template 'config/initializers/maintenance.rb' end |
#end ⇒ Object
45 46 47 48 49 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 45 def end puts "" puts "Maintenance page setup completed! Yay!" puts "===============================================================================" end |