Class: SufiaGenerator

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

Instance Method Summary collapse

Instance Method Details

#catalog_controllerObject



40
41
42
# File 'lib/generators/sufia/sufia_generator.rb', line 40

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

#inject_routesObject

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



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/generators/sufia/sufia_generator.rb', line 46

def inject_routes
  routing_code = "Hydra::BatchEdit.add_routes(self)"
  sentinel = /HydraHead.add_routes\(self\)/
  inject_into_file 'config/routes.rb', "\n  #{routing_code}\n", { :after => sentinel, :verbose => false }

  routing_code = "\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"
  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



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/sufia/sufia_generator.rb', line 25

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 :search_layout"
  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

#run_required_generatorsObject



18
19
20
21
22
# File 'lib/generators/sufia/sufia_generator.rb', line 18

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