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 20 21 22 23 |
# 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 "\e[31m-------------------------------------------------------------------------------\e[0m" puts "\e[31mWARNING! Binda::MaintenanceController is already registered here:\e[0m" puts "\e[31m app/controllers/maintenance_controller.rb\e[0m" puts puts "\e[31mUnless you know what you are doing, delete that file and run:\e[0m" puts "\e[31m rails generate binda:maintenance\e[0m" puts "\e[31m-------------------------------------------------------------------------------\e[0m" exit else 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 end |
#add_helper ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 40 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
33 34 35 36 37 38 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 33 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
25 26 27 28 29 30 31 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 25 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
49 50 51 52 53 |
# File 'lib/generators/binda/maintenance/maintenance_generator.rb', line 49 def end puts "" puts "Maintenance page setup completed! Yay!" puts "===============================================================================" end |