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



79
80
81
# File 'lib/generators/worthwhile/install_generator.rb', line 79

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

#add_helperObject



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

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



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

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



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

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



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

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



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

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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/worthwhile/install_generator.rb', line 57

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



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

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

#replace_blacklight_layoutObject



34
35
36
37
# File 'lib/generators/worthwhile/install_generator.rb', line 34

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
18
19
20
21
# 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"

  # TODO this should probably move to the hydra:head generator because it installs the gem
  say_status("warning", "GENERATING RSPEC-RAILS", :yellow)
  generate 'rspec:install'

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