Class: Hyrax::Install

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/hyrax/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#catalog_controllerObject


81
82
83
# File 'lib/generators/hyrax/install_generator.rb', line 81

def catalog_controller
  copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
end

#configure_usage_statsObject


111
112
113
# File 'lib/generators/hyrax/install_generator.rb', line 111

def configure_usage_stats
  copy_file 'config/analytics.yml', 'config/analytics.yml'
end

#copy_helperObject


136
137
138
# File 'lib/generators/hyrax/install_generator.rb', line 136

def copy_helper
  copy_file 'hyrax_helper.rb', 'app/helpers/hyrax_helper.rb'
end

#create_workflowObject


98
99
100
101
# File 'lib/generators/hyrax/install_generator.rb', line 98

def create_workflow
  template('workflow.json.erb', "config/workflows/default_workflow.json")
  template('mediated_deposit_workflow.json.erb', "config/workflows/mediated_deposit_workflow.json")
end

#datatablesObject


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/generators/hyrax/install_generator.rb', line 161

def datatables
  javascript_manifest = 'app/assets/javascripts/application.js'
  # Generator is broken https://github.com/rweng/jquery-datatables-rails/issues/225
  # generate 'jquery:datatables:install bootstrap3'
  insert_into_file javascript_manifest, after: /jquery.?\n/ do
    "//= require jquery_ujs\n" \
    "//= require dataTables/jquery.dataTables\n" \
    "//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap\n"
  end

  # This is only necessary for Rails 5.1 and hopefully is temporary.
  # There was some trouble getting the file-manager javascript (remote forms) to work well
  # with rails-ujs. Note jquery_ujs was added to the block above (after jQuery)
  gsub_file javascript_manifest, 'require rails-ujs', ''

  insert_into_file 'app/assets/stylesheets/application.css', before: ' *= require_self' do
    " *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap\n"
  end
end

#health_checkObject


185
186
187
# File 'lib/generators/hyrax/install_generator.rb', line 185

def health_check
  generate 'hyrax:health_check' unless options[:'skip-health-check']
end

#inject_abilityObject

we're going to inject this into the local app, so that it's easy to disable.


116
117
118
119
120
121
# File 'lib/generators/hyrax/install_generator.rb', line 116

def inject_ability
  inject_into_file 'app/models/ability.rb', after: /Hydra::Ability\s*\n/ do
    "  include Hyrax::Ability\n"\
    "  self.ability_logic += [:everyone_can_create_curation_concerns]\n\n"
  end
end

#inject_hyrax_application_controller_behaviorObject

Add behaviors to the application controller


124
125
126
127
128
129
130
131
132
133
134
# File 'lib/generators/hyrax/install_generator.rb', line 124

def inject_hyrax_application_controller_behavior
  file_path = "app/controllers/application_controller.rb"
  if File.exist?(file_path)
    insert_into_file file_path, after: /Hydra::Controller::ControllerBehavior\s*\n/ do
      "\n  # Adds Hyrax behaviors into the application controller" \
      "\n  include Hyrax::Controller\n"
    end
  else
    puts "     \e[31mFailure\e[0m  Could not find #{file_path}.  To add Hyrax behaviors to your Controllers, you must include the Hyrax::Controller module in the Controller class definition."
  end
end

#inject_routesObject

The engine routes have to come after the devise routes so that /users/sign_in will work


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/generators/hyrax/install_generator.rb', line 68

def inject_routes
  # Remove root route that was added by blacklight generator
  gsub_file 'config/routes.rb', /root (:to =>|to:) "catalog#index"/, ''

  inject_into_file 'config/routes.rb', after: /devise_for :users\s*\n/ do
    "  mount Qa::Engine => '/authorities'\n"\
    "  mount Hyrax::Engine, at: '/'\n"\
    "  resources :welcome, only: 'index'\n"\
    "  root 'hyrax/homepage#index'\n"\
    "  curation_concerns_basic_routes\n"\
  end
end

#inject_skip_blacklilght_flash_discardingObject

Blacklight::Controller will by default add an after_action filter to discard all flash messages on xhr requests. This has caused problems when we perform a post-redirect-get cycle using xhr and turbolinks. This injector will modify the generated ApplicationController to skip this action. TODO: This may be removed in Blacklight 7.x, so we'll likely need to remove this after updating.


201
202
203
204
205
# File 'lib/generators/hyrax/install_generator.rb', line 201

def inject_skip_blacklilght_flash_discarding
  insert_into_file "app/controllers/application_controller.rb", after: "include Blacklight::Controller\n" do
    "  skip_after_action :discard_flash_if_xhr\n"
  end
end

#inject_solr_document_behaviorObject

Add behaviors to the SolrDocument model


86
87
88
89
90
91
92
93
94
95
96
# File 'lib/generators/hyrax/install_generator.rb', line 86

def inject_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 Hyrax behaviors to the SolrDocument.\n" \
        "  include Hyrax::SolrDocumentBehavior\n"
    end
  else
    puts "     \e[31mFailure\e[0m  Hyrax requires a SolrDocument object. This generators assumes that the model is defined in the file #{file_path}, which does not exist."
  end
end

#insert_builderObject


61
62
63
64
65
# File 'lib/generators/hyrax/install_generator.rb', line 61

def insert_builder
  insert_into_file 'app/models/search_builder.rb', after: /include Hydra::AccessControlsEnforcement/ do
    "\n  include Hyrax::SearchFilters\n"
  end
end

#install_assetsObject


144
145
146
# File 'lib/generators/hyrax/install_generator.rb', line 144

def install_assets
  generate "hyrax:assets"
end

154
155
156
157
158
159
# File 'lib/generators/hyrax/install_generator.rb', line 154

def install_blacklight_gallery
  generate "blacklight_gallery:install"
  # This was pulling in an extra copy of bootstrap, so we added the needed
  # includes to hyrax.scss
  remove_file 'app/assets/stylesheets/blacklight_gallery.css.scss'
end

#install_configObject


103
104
105
# File 'lib/generators/hyrax/install_generator.rb', line 103

def install_config
  generate "hyrax:config"
end

#install_mailboxerObject


107
108
109
# File 'lib/generators/hyrax/install_generator.rb', line 107

def install_mailboxer
  generate "mailboxer:install"
end

#noid_rails_database_minter_initializeObject


181
182
183
# File 'lib/generators/hyrax/install_generator.rb', line 181

def noid_rails_database_minter_initialize
  generate 'noid:rails:install'
end

#pin_browse_everythingObject

browse-everything 1.2.0 is not compatible with Ruby 2.5


39
40
41
42
43
44
45
# File 'lib/generators/hyrax/install_generator.rb', line 39

def pin_browse_everything
  return unless Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6')
  gem 'browse-everything', '~> 1.1.2'
  Bundler.with_clean_env do
    run "bundle update browse-everything"
  end
end

#qa_tablesObject


140
141
142
# File 'lib/generators/hyrax/install_generator.rb', line 140

def qa_tables
  generate 'qa:local:tables'
end

#replace_blacklight_layoutObject


56
57
58
59
# File 'lib/generators/hyrax/install_generator.rb', line 56

def replace_blacklight_layout
  gsub_file 'app/controllers/application_controller.rb', /layout 'blacklight'/,
            "include Hyrax::ThemedLayoutController\n  with_themed_layout '1_column'\n"
end

#riiif_image_serverObject


189
190
191
# File 'lib/generators/hyrax/install_generator.rb', line 189

def riiif_image_server
  generate 'hyrax:riiif' unless options[:'skip-riiif']
end

#run_required_generatorsObject


47
48
49
50
51
52
53
54
# File 'lib/generators/hyrax/install_generator.rb', line 47

def run_required_generators
  say_status('info', '[Hyrax] GENERATING BLACKLIGHT', :blue)
  generate 'blacklight:install --devise'
  say_status('info', '[Hyrax] GENERATING HYDRA-HEAD', :blue)
  generate 'hydra:head -f'
  generate "hyrax:models#{options[:force] ? ' -f' : ''}"
  generate 'browse_everything:config'
end

#universalviewer_filesObject


193
194
195
# File 'lib/generators/hyrax/install_generator.rb', line 193

def universalviewer_files
  rake('hyrax:universal_viewer:install')
end

#use_browser_validationsObject


148
149
150
151
152
# File 'lib/generators/hyrax/install_generator.rb', line 148

def use_browser_validations
  gsub_file 'config/initializers/simple_form.rb',
            /browser_validations = false/,
            'browser_validations = true'
end