Class: Sufia::Install

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

Instance Method Summary collapse

Instance Method Details

#catalog_controllerObject



47
48
49
# File 'lib/generators/sufia/install_generator.rb', line 47

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

#copy_helperObject



51
52
53
# File 'lib/generators/sufia/install_generator.rb', line 51

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

#inject_routesObject

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



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/generators/sufia/install_generator.rb', line 64

def inject_routes
  gsub_file 'config/routes.rb', 'root :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_behaviorObject

Add behaviors to the application controller



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/sufia/install_generator.rb', line 33

def inject_sufia_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# Adds Sufia behaviors into the application controller \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_behaviorObject

Add behaviors to the SolrDocument model



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/generators/sufia/install_generator.rb', line 77

def inject_sufia_solr_document_behavior
  file_path = "app/models/solr_document.rb"
  if File.exists?(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_abilitiesObject



26
27
28
29
30
# File 'lib/generators/sufia/install_generator.rb', line 26

def insert_abilities
  insert_into_file 'app/models/ability.rb', after: /Hydra::Ability/ do
    "\n  include Sufia::Ability\n"
  end
end

#remove_blacklight_scssObject



55
56
57
# File 'lib/generators/sufia/install_generator.rb', line 55

def remove_blacklight_scss
  remove_file 'app/assets/stylesheets/blacklight.css.scss'
end

#run_required_generatorsObject



20
21
22
23
24
# File 'lib/generators/sufia/install_generator.rb', line 20

def run_required_generators
  generate "blacklight:install --devise"
  generate "hydra:head -f"
  generate "sufia:models:install"
end

#tinymce_configObject



59
60
61
# File 'lib/generators/sufia/install_generator.rb', line 59

def tinymce_config
  copy_file "config/tinymce.yml", "config/tinymce.yml"
end