Class: Worthwhile::Install

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

Instance Method Summary collapse

Instance Method Details

#add_config_fileObject



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

def add_config_file
  copy_file "worthwhile_config.rb", "config/initializers/worthwhile_config.rb"
end

#add_helperObject



70
71
72
73
# File 'lib/generators/worthwhile/install_generator.rb', line 70

def add_helper
  copy_file "worthwhile_helper.rb", "app/helpers/worthwhile_helper.rb"
  #inject_into_class 'app/helpers/application_helper.rb', ApplicationHelper, "  include WorthwhileHelper"
end

#assetsObject



65
66
67
68
# File 'lib/generators/worthwhile/install_generator.rb', line 65

def assets
  copy_file "worthwhile.css.scss", "app/assets/stylesheets/worthwhile.css.scss"
  copy_file "worthwhile.js", "app/assets/javascripts/worthwhile.js"
end

#inject_abilityObject



45
46
47
48
49
50
# File 'lib/generators/worthwhile/install_generator.rb', line 45

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

#inject_application_controller_behaviorObject



24
25
26
27
28
# File 'lib/generators/worthwhile/install_generator.rb', line 24

def inject_application_controller_behavior
  inject_into_file 'app/controllers/application_controller.rb', :after => /Blacklight::Controller\s*\n/ do
    "  include Worthwhile::ApplicationControllerBehavior\n"
  end
end

#inject_routesObject



35
36
37
38
39
40
41
42
43
# File 'lib/generators/worthwhile/install_generator.rb', line 35

def inject_routes
  inject_into_file 'config/routes.rb', :after => /devise_for :users\s*\n/ do
    "  mount Hydra::Collections::Engine => '/'\n"\
    "  mount Worthwhile::Engine, at: '/'\n"\
    "  worthwhile_collections\n"\
    "  worthwhile_curation_concerns\n"\
    "  worthwhile_embargo_management\n"\
  end
end

#inject_solr_document_behaviorObject

Add behaviors to the SolrDocument model



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/worthwhile/install_generator.rb', line 53

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

#remove_catalog_controllerObject



19
20
21
22
# File 'lib/generators/worthwhile/install_generator.rb', line 19

def remove_catalog_controller
  say_status("warning", "Removing Blacklight's generated CatalogController...", :yellow)
  remove_file('app/controllers/catalog_controller.rb')
end

#replace_blacklight_layoutObject



30
31
32
33
# File 'lib/generators/worthwhile/install_generator.rb', line 30

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

#run_blacklight_generatorObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/worthwhile/install_generator.rb', line 8

def run_blacklight_generator
  say_status("warning", "GENERATING BL", :yellow)
  generate 'blacklight:install', '--devise'

  say_status("warning", "GENERATING HYDRA-HEAD", :yellow)
  generate "hydra:head -f"

  say_status("warning", "GENERATING SUFIA", :yellow)
  generate "sufia:models:install#{options[:force] ? ' -f' : ''}"
end