Class: Sufia::Install
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sufia::Install
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/sufia/install_generator.rb
Instance Method Summary collapse
- #add_sufia_assets ⇒ Object
- #banner ⇒ Object
- #catalog_controller ⇒ Object
- #copy_helper ⇒ Object
-
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work.
-
#inject_sufia_controller_behavior ⇒ Object
Add behaviors to the application controller.
-
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model.
- #insert_abilities ⇒ Object
- #install_admin_stats ⇒ Object
- #install_blacklight_gallery ⇒ Object
- #install_sufia_600 ⇒ Object
- #remove_blacklight_scss ⇒ Object
- #run_required_generators ⇒ Object
- #tinymce_config ⇒ Object
Instance Method Details
#add_sufia_assets ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/generators/sufia/install_generator.rb', line 66 def add_sufia_assets insert_into_file 'app/assets/stylesheets/application.css', after: ' *= require_self' do "\n *= require sufia" end gsub_file 'app/assets/javascripts/application.js', '//= require_tree .', '//= require sufia' end |
#banner ⇒ Object
29 30 31 |
# File 'lib/generators/sufia/install_generator.rb', line 29 def say_status("info", "GENERATING SUFIA", :blue) end |
#catalog_controller ⇒ Object
54 55 56 |
# File 'lib/generators/sufia/install_generator.rb', line 54 def catalog_controller copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb" end |
#copy_helper ⇒ Object
58 59 60 |
# File 'lib/generators/sufia/install_generator.rb', line 58 def copy_helper copy_file 'sufia_helper.rb', 'app/helpers/sufia_helper.rb' end |
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/generators/sufia/install_generator.rb', line 80 def inject_routes gsub_file 'config/routes.rb', /root (:to =>|to:) "catalog#index"/, '' routing_code = "\n Hydra::BatchEdit.add_routes(self)\n" \ " # This must be the very last route in the file because it has a catch-all route for 404 errors. # This behavior seems to show up only in production mode. mount Sufia::Engine => '/'\n root to: 'homepage#index'\n" sentinel = /devise_for :users/ inject_into_file 'config/routes.rb', routing_code, after: sentinel, verbose: false end |
#inject_sufia_controller_behavior ⇒ Object
Add behaviors to the application controller
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/generators/sufia/install_generator.rb', line 40 def inject_sufia_controller_behavior controller_name = "ApplicationController" file_path = "app/controllers/application_controller.rb" if File.exist?(file_path) insert_into_file file_path, after: 'include Blacklight::Controller' do " \n# Adds Sufia behaviors into the application controller (#{controller_name}) \n" \ " include Sufia::Controller\n" end gsub_file file_path, "layout 'blacklight'", "layout 'sufia-one-column'" else puts " \e[31mFailure\e[0m Could not find #{file_path}. To add Sufia behaviors to your Controllers, you must include the Sufia::Controller module in the Controller class definition." end end |
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/generators/sufia/install_generator.rb', line 93 def inject_sufia_solr_document_behavior file_path = "app/models/solr_document.rb" if File.exist?(file_path) inject_into_file file_path, after: /include Blacklight::Solr::Document.*$/ do "\n # Adds Sufia behaviors to the SolrDocument.\n" \ " include Sufia::SolrDocumentBehavior\n" end else puts " \e[31mFailure\e[0m Sufia requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist." end end |
#insert_abilities ⇒ Object
33 34 35 36 37 |
# File 'lib/generators/sufia/install_generator.rb', line 33 def insert_abilities insert_into_file 'app/models/ability.rb', after: /Hydra::Ability/ do "\n include Sufia::Ability\n" end end |
#install_admin_stats ⇒ Object
113 114 115 |
# File 'lib/generators/sufia/install_generator.rb', line 113 def install_admin_stats generate "sufia:admin_stat" end |
#install_blacklight_gallery ⇒ Object
109 110 111 |
# File 'lib/generators/sufia/install_generator.rb', line 109 def install_blacklight_gallery generate "blacklight_gallery:install" end |
#install_sufia_600 ⇒ Object
105 106 107 |
# File 'lib/generators/sufia/install_generator.rb', line 105 def install_sufia_600 generate "sufia:upgrade600" end |
#remove_blacklight_scss ⇒ Object
62 63 64 |
# File 'lib/generators/sufia/install_generator.rb', line 62 def remove_blacklight_scss remove_file 'app/assets/stylesheets/blacklight.css.scss' end |
#run_required_generators ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/generators/sufia/install_generator.rb', line 21 def run_required_generators say_status("info", "GENERATING BLACKLIGHT", :blue) generate "blacklight:install --devise" say_status("info", "GENERATING HYDRA", :blue) generate "hydra:head -f" generate "sufia:models:install" end |
#tinymce_config ⇒ Object
75 76 77 |
# File 'lib/generators/sufia/install_generator.rb', line 75 def tinymce_config copy_file "config/tinymce.yml", "config/tinymce.yml" end |