Class: Sufia::Install
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Sufia::Install
- Defined in:
- lib/generators/sufia/install_generator.rb
Instance Method Summary collapse
- #banner ⇒ Object
- #catalog_controller ⇒ Object
- #configure_usage_stats ⇒ Object
- #copy_helper ⇒ Object
-
#copy_migrations ⇒ Object
Setup the database migrations.
-
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work.
-
#inject_sufia_application_controller_behavior ⇒ Object
Add behaviors to the application controller.
- #inject_sufia_file_set_behavior ⇒ Object
-
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model.
-
#inject_sufia_user_behavior ⇒ Object
Add behaviors to the user model.
- #insert_abilities ⇒ Object
- #install_assets ⇒ Object
- #install_batch_edit ⇒ Object
- #install_blacklight_gallery ⇒ Object
- #install_config ⇒ Object
- #install_mailboxer ⇒ Object
- #install_sufia_700 ⇒ Object
- #run_required_generators ⇒ Object
- #solr_config ⇒ Object
- #use_blacklight_layout_theme ⇒ Object
- #use_browser_validations ⇒ Object
-
#user_stats ⇒ Object
Adds user stats-related methods.
Instance Method Details
#banner ⇒ Object
25 26 27 |
# File 'lib/generators/sufia/install_generator.rb', line 25 def say_status("info", "GENERATING SUFIA", :blue) end |
#catalog_controller ⇒ Object
113 114 115 |
# File 'lib/generators/sufia/install_generator.rb', line 113 def catalog_controller copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb" end |
#configure_usage_stats ⇒ Object
65 66 67 |
# File 'lib/generators/sufia/install_generator.rb', line 65 def configure_usage_stats copy_file 'config/analytics.yml', 'config/analytics.yml' end |
#copy_helper ⇒ Object
117 118 119 |
# File 'lib/generators/sufia/install_generator.rb', line 117 def copy_helper copy_file 'sufia_helper.rb', 'app/helpers/sufia_helper.rb' end |
#copy_migrations ⇒ Object
Setup the database migrations
34 35 36 |
# File 'lib/generators/sufia/install_generator.rb', line 34 def copy_migrations rake 'sufia:install:migrations' end |
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work
122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/generators/sufia/install_generator.rb', line 122 def inject_routes gsub_file 'config/routes.rb', /root (:to =>|to:) "catalog#index"/, '' gsub_file 'config/routes.rb', /'welcome#index'/, "'sufia/homepage#index'" # Replace the root path injected by CurationConcerns 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.\n" \ " # This behavior seems to show up only in production mode.\n" \ " mount Sufia::Engine => '/'\n" sentinel = /end\Z/ inject_into_file 'config/routes.rb', routing_code, before: sentinel, verbose: false end |
#inject_sufia_application_controller_behavior ⇒ Object
Add behaviors to the application controller
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/generators/sufia/install_generator.rb', line 95 def inject_sufia_application_controller_behavior file_path = "app/controllers/application_controller.rb" if File.exist?(file_path) insert_into_file file_path, after: 'CurationConcerns::ApplicationControllerBehavior' do " \n # Adds Sufia behaviors into the application controller \n" \ " include Sufia::Controller\n" end 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_file_set_behavior ⇒ Object
55 56 57 58 59 |
# File 'lib/generators/sufia/install_generator.rb', line 55 def inject_sufia_file_set_behavior insert_into_file 'app/models/file_set.rb', after: 'include ::CurationConcerns::FileSetBehavior' do "\n include Sufia::FileSetBehavior" end end |
#inject_sufia_solr_document_behavior ⇒ Object
Add behaviors to the SolrDocument model
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/generators/sufia/install_generator.rb', line 136 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 CurationConcerns::SolrDocumentBehavior/ 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 generator assumes that the model is defined in the file #{file_path}, which does not exist." end end |
#inject_sufia_user_behavior ⇒ Object
Add behaviors to the user model
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/sufia/install_generator.rb', line 43 def inject_sufia_user_behavior file_path = "app/models/#{model_name.underscore}.rb" if File.exist?(file_path) inject_into_file file_path, after: /include CurationConcerns\:\:User.*$/ do "\n # Connects this user object to Sufia behaviors." \ "\n include Sufia::User\n" end else puts " \e[31mFailure\e[0m Sufia requires a user object. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g sufia client" end end |
#insert_abilities ⇒ Object
88 89 90 91 92 |
# File 'lib/generators/sufia/install_generator.rb', line 88 def insert_abilities insert_into_file 'app/models/ability.rb', after: /CurationConcerns::Ability/ do "\n include Sufia::Ability\n" end end |
#install_assets ⇒ Object
152 153 154 |
# File 'lib/generators/sufia/install_generator.rb', line 152 def install_assets generate "sufia:assets" end |
#install_batch_edit ⇒ Object
156 157 158 |
# File 'lib/generators/sufia/install_generator.rb', line 156 def install_batch_edit generate "hydra_batch_edit:install" end |
#install_blacklight_gallery ⇒ Object
166 167 168 169 170 171 |
# File 'lib/generators/sufia/install_generator.rb', line 166 def install_blacklight_gallery generate "blacklight_gallery:install" # This was pulling in an extra copy of bootstrap, so we added the needed # includes to sufia.scss remove_file 'app/assets/stylesheets/blacklight_gallery.css.scss' end |
#install_config ⇒ Object
38 39 40 |
# File 'lib/generators/sufia/install_generator.rb', line 38 def install_config generate "sufia:config" end |
#install_mailboxer ⇒ Object
61 62 63 |
# File 'lib/generators/sufia/install_generator.rb', line 61 def install_mailboxer generate "mailboxer:install" end |
#install_sufia_700 ⇒ Object
148 149 150 |
# File 'lib/generators/sufia/install_generator.rb', line 148 def install_sufia_700 generate "sufia:upgrade700" end |
#run_required_generators ⇒ Object
29 30 31 |
# File 'lib/generators/sufia/install_generator.rb', line 29 def run_required_generators generate "curation_concerns:install --skip-assets -f" unless [:skip_curation_concerns] end |
#solr_config ⇒ Object
69 70 71 72 73 |
# File 'lib/generators/sufia/install_generator.rb', line 69 def solr_config say_status("info", "GENERATING SUFIA FULL-TEXT", :blue) source = File.("../../../../solr/config/solrconfig.xml", __FILE__) copy_file source, 'solr/conf/solrconfig.xml', force: true end |
#use_blacklight_layout_theme ⇒ Object
107 108 109 110 111 |
# File 'lib/generators/sufia/install_generator.rb', line 107 def use_blacklight_layout_theme file_path = "app/controllers/application_controller.rb" return unless File.exist?(file_path) gsub_file file_path, /with_themed_layout '1_column'/, "layout 'sufia-one-column'" end |
#use_browser_validations ⇒ Object
160 161 162 163 164 |
# File 'lib/generators/sufia/install_generator.rb', line 160 def use_browser_validations gsub_file 'config/initializers/simple_form.rb', /browser_validations = false/, 'browser_validations = true' end |
#user_stats ⇒ Object
Adds user stats-related methods
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/generators/sufia/install_generator.rb', line 76 def user_stats file_path = "app/models/#{model_name.underscore}.rb" if File.exist?(file_path) inject_into_file file_path, after: /include Sufia\:\:User.*$/ do "\n include Sufia::UserUsageStats" end else puts " \e[31mFailure\e[0m Sufia requires a user object. This generator assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails g sufia:user_stats client" end end |