Class: CurateGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- CurateGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/curate/curate_generator.rb
Constant Summary collapse
- DEFAULT_CURATION_CONCERNS =
[:generic_works, :datasets, :articles, :etds, :images, :documents]
Instance Method Summary collapse
-
#copy_migrations ⇒ Object
Setup the database migrations.
- #create_curate_config ⇒ Object
- #create_recipients_list ⇒ Object
-
#inject_controller_behavior ⇒ Object
Add behaviors to the application controller.
- #inject_curate_ability ⇒ Object
- #inject_curate_user ⇒ Object
-
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work.
- #install_readme ⇒ Object
- #register_remote_identifiers ⇒ Object
- #remove_blacklight ⇒ Object
- #remove_catalog_controller ⇒ Object
- #run_migrations ⇒ Object
- #run_required_generators ⇒ Object
- #update_assets ⇒ Object
-
#update_devise_route ⇒ Object
This enables our registrations controller to run the after_update_path_for hook.
Instance Method Details
#copy_migrations ⇒ Object
Setup the database migrations
49 50 51 |
# File 'lib/generators/curate/curate_generator.rb', line 49 def copy_migrations rake 'curate_engine:install:migrations' end |
#create_curate_config ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/curate/curate_generator.rb', line 63 def create_curate_config initializer 'curate_config.rb' do data = [] data << "Curate.configure do |config|" DEFAULT_CURATION_CONCERNS.each_with_object(data) {|curation_concern, mem| mem << " config.register_curation_concern :#{curation_concern.to_s.singularize}" } data << " # # You can override curate's antivirus runner by configuring a lambda \(or" data << " # # object that responds to call\)" data << " # config.default_antivirus_instance = lambda {|filename| … }" data << "" data << " # # Used for constructing permanent URLs" data << " # config.application_root_url = 'https://repository.higher.edu/'" data << "" data << " # # Override the file characterization runner that is used" data << " # config.characterization_runner = lambda {|filename| … }" data << "end" data << "" data.join("\n") end end |
#create_recipients_list ⇒ Object
99 100 101 |
# File 'lib/generators/curate/curate_generator.rb', line 99 def create_recipients_list create_file('config/recipients_list.yml', "---\n- [email protected]\n") end |
#inject_controller_behavior ⇒ Object
Add behaviors to the application controller
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/curate/curate_generator.rb', line 34 def inject_controller_behavior controller_name = "ApplicationController" file_path = "app/controllers/application_controller.rb" if File.exists?(file_path) insert_into_file file_path, :after => 'include Blacklight::Controller' do "\n include CurateController\n" end gsub_file file_path, "layout 'blacklight'", "" else puts " \e[31mFailure\e[0m Could not find #{file_path}. To add Curate behaviors to your ApplicationController, you must include the CurateController module in the ApplicationController class definition." end end |
#inject_curate_ability ⇒ Object
109 110 111 112 113 |
# File 'lib/generators/curate/curate_generator.rb', line 109 def inject_curate_ability inject_into_file 'app/models/ability.rb', :after => /Hydra::Ability\s*\n/ do " include Curate::Ability\n\n" end end |
#inject_curate_user ⇒ Object
103 104 105 106 107 |
# File 'lib/generators/curate/curate_generator.rb', line 103 def inject_curate_user inject_into_file 'app/models/user.rb', after: /include Sufia\:\:User.*$/ do "\n include Curate::UserBehavior\n" end end |
#inject_routes ⇒ Object
The engine routes have to come after the devise routes so that /users/sign_in will work
54 55 56 57 58 59 |
# File 'lib/generators/curate/curate_generator.rb', line 54 def inject_routes routing_code = "\n curate_for\n" sentinel = /devise_for +:users.*$/ inject_into_file 'config/routes.rb', routing_code, { :after => sentinel, :verbose => false } gsub_file 'config/routes.rb', /^\s+root.+$/, " root 'catalog#index'" end |
#install_readme ⇒ Object
137 138 139 |
# File 'lib/generators/curate/curate_generator.rb', line 137 def install_readme readme 'README.md' end |
#register_remote_identifiers ⇒ Object
85 86 87 88 89 |
# File 'lib/generators/curate/curate_generator.rb', line 85 def register_remote_identifiers if .fetch('with_doi', false) generate 'curate:work:with_doi', DEFAULT_CURATION_CONCERNS.collect(&:to_s).join(" ") end end |
#remove_blacklight ⇒ Object
129 130 131 |
# File 'lib/generators/curate/curate_generator.rb', line 129 def remove_blacklight remove_file('app/assets/stylesheets/blacklight.css.scss') end |
#remove_catalog_controller ⇒ Object
115 116 117 118 |
# File 'lib/generators/curate/curate_generator.rb', line 115 def remove_catalog_controller say_status("warning", "Removing Blacklight's generated CatalogController...It will cause you grief", :yellow) remove_file('app/controllers/catalog_controller.rb') end |
#run_migrations ⇒ Object
133 134 135 |
# File 'lib/generators/curate/curate_generator.rb', line 133 def run_migrations rake "db:migrate" end |
#run_required_generators ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/generators/curate/curate_generator.rb', line 25 def run_required_generators generate "blacklight --devise" remove_dir('app/views/devise') generate "hydra:head -f" generate "sufia:models:install#{[:force] ? ' -f' : ''}" generate "hydra:remote_identifier:install#{[:force] ? ' -f' : ''}" end |
#update_assets ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/generators/curate/curate_generator.rb', line 120 def update_assets insert_into_file 'app/assets/stylesheets/application.css', before: /^ *\*= +require_tree +\. *$/ do " *= require curate\n" end insert_into_file "app/assets/javascripts/application.js", :before => '//= require_tree .' do "//= require curate\n" end end |
#update_devise_route ⇒ Object
This enables our registrations controller to run the after_update_path_for hook.
92 93 94 95 96 |
# File 'lib/generators/curate/curate_generator.rb', line 92 def update_devise_route gsub_file 'config/routes.rb', /^\s+devise_for :users\s*$/ do %( devise_for :users, controllers: { sessions: :sessions, registrations: :registrations}\n\n) end end |