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

#add_sufia_assetsObject



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


29
30
31
# File 'lib/generators/sufia/install_generator.rb', line 29

def banner
  say_status("info", "GENERATING SUFIA", :blue)
end

#catalog_controllerObject



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_helperObject



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_routesObject

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_behaviorObject

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_behaviorObject

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_abilitiesObject



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_statsObject



113
114
115
# File 'lib/generators/sufia/install_generator.rb', line 113

def install_admin_stats
  generate "sufia:admin_stat"
end


109
110
111
# File 'lib/generators/sufia/install_generator.rb', line 109

def install_blacklight_gallery
  generate "blacklight_gallery:install"
end

#install_sufia_600Object



105
106
107
# File 'lib/generators/sufia/install_generator.rb', line 105

def install_sufia_600
  generate "sufia:upgrade600"
end

#remove_blacklight_scssObject



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_generatorsObject



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_configObject



75
76
77
# File 'lib/generators/sufia/install_generator.rb', line 75

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