hydra-core 5.0.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +5 -0
  3. data/app/helpers/blacklight_helper.rb +4 -0
  4. data/app/helpers/facets_helper.rb +4 -0
  5. data/app/helpers/hydra/blacklight_helper_behavior.rb +36 -0
  6. data/app/helpers/hydra/facets_helper_behavior.rb +25 -0
  7. data/app/models/hydra/datastream/properties.rb +24 -0
  8. data/app/models/mods_asset.rb +25 -0
  9. data/app/views/_flash_msg.html.erb +5 -0
  10. data/app/views/catalog/_citation.html.erb +11 -0
  11. data/app/views/catalog/_constraints_element.html.erb +34 -0
  12. data/app/views/catalog/_delete_partials/_default.html.erb +22 -0
  13. data/app/views/catalog/_edit_partials/_default.html.erb +57 -0
  14. data/app/views/catalog/_edit_partials/_default_details.html.erb +13 -0
  15. data/app/views/catalog/_facets.html.erb +37 -0
  16. data/app/views/catalog/_home.html.erb +6 -0
  17. data/app/views/catalog/_home_text.html.erb +4 -0
  18. data/app/views/catalog/_index_partials/_default.html.erb +20 -0
  19. data/app/views/catalog/_index_partials/_default_details.html.erb +14 -0
  20. data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -0
  21. data/app/views/catalog/_show_partials/_default.html.erb +21 -0
  22. data/app/views/catalog/_show_partials/_default_details.html.erb +15 -0
  23. data/app/views/catalog/_show_partials/_facets.html.erb +52 -0
  24. data/app/views/catalog/_sms_form.html.erb +21 -0
  25. data/app/views/catalog/_sort_and_per_page.html.erb +23 -0
  26. data/app/views/catalog/_uva_tabs.html.erb +10 -0
  27. data/app/views/catalog/about.html.erb +0 -0
  28. data/app/views/catalog/show.html.erb +40 -0
  29. data/app/views/layouts/hydra-head.html.erb +47 -0
  30. data/config/jetty.yml +6 -0
  31. data/config/locales/hydra.en.yml +7 -0
  32. data/hydra-core.gemspec +40 -0
  33. data/lib/application_helper.rb +3 -0
  34. data/lib/generators/hydra/assets_generator.rb +50 -0
  35. data/lib/generators/hydra/cucumber_support_generator.rb +29 -0
  36. data/lib/generators/hydra/head_generator.rb +160 -0
  37. data/lib/generators/hydra/hyhead_fixtures_generator.rb +27 -0
  38. data/lib/generators/hydra/templates/catalog_controller.rb +162 -0
  39. data/lib/generators/hydra/templates/config/fedora.yml +14 -0
  40. data/lib/generators/hydra/templates/config/initializers/action_dispatch_http_upload_monkey_patch.rb +12 -0
  41. data/lib/generators/hydra/templates/config/initializers/hydra_config.rb +39 -0
  42. data/lib/generators/hydra/templates/config/role_map_cucumber.yml +10 -0
  43. data/lib/generators/hydra/templates/config/role_map_development.yml +12 -0
  44. data/lib/generators/hydra/templates/config/role_map_production.yml +2 -0
  45. data/lib/generators/hydra/templates/config/role_map_test.yml +15 -0
  46. data/lib/generators/hydra/templates/config/solr.yml +10 -0
  47. data/lib/generators/hydra/templates/config/solr_mappings.yml +22 -0
  48. data/lib/generators/hydra/templates/fedora_conf/conf/development/fedora.fcfg +946 -0
  49. data/lib/generators/hydra/templates/fedora_conf/conf/test/fedora.fcfg +946 -0
  50. data/lib/generators/hydra/templates/solr_conf/conf/schema.xml +692 -0
  51. data/lib/generators/hydra/templates/solr_conf/conf/solrconfig.xml +1887 -0
  52. data/lib/generators/hydra/templates/solr_conf/solr.xml +35 -0
  53. data/lib/hydra-core.rb +1 -0
  54. data/lib/hydra-head.rb +27 -0
  55. data/lib/hydra-head/engine.rb +14 -0
  56. data/lib/hydra-head/routes.rb +90 -0
  57. data/lib/hydra-head/version.rb +4 -0
  58. data/lib/hydra.rb +30 -0
  59. data/lib/hydra/catalog.rb +11 -0
  60. data/lib/hydra/controller.rb +25 -0
  61. data/lib/hydra/controller/controller_behavior.rb +39 -0
  62. data/lib/hydra/controller/repository_controller_behavior.rb +78 -0
  63. data/lib/hydra/controller/upload_behavior.rb +139 -0
  64. data/lib/hydra/global_configurable.rb +46 -0
  65. data/lib/hydra/model_methods.rb +109 -0
  66. data/lib/hydra/model_mixins/common_metadata.rb +25 -0
  67. data/lib/hydra/model_mixins/solr_document_extension.rb +24 -0
  68. data/lib/hydra/models/file_asset.rb +76 -0
  69. data/lib/hydra/repository_controller.rb +28 -0
  70. data/lib/hydra/solr.rb +9 -0
  71. data/lib/railties/active-fedora.rake +1 -0
  72. data/lib/railties/hydra-fixtures.rake +50 -0
  73. data/lib/railties/hydra_jetty.rake +53 -0
  74. data/spec/.gitignore +1 -0
  75. data/spec/controllers/catalog_controller_spec.rb +101 -0
  76. data/spec/controllers/catalog_valid_html_spec.rb +114 -0
  77. data/spec/factories.rb +11 -0
  78. data/spec/helpers/blacklight_helper_spec.rb +15 -0
  79. data/spec/helpers/facets_helper_spec.rb +15 -0
  80. data/spec/lib/catalog_spec.rb +16 -0
  81. data/spec/lib/global_configurable_spec.rb +98 -0
  82. data/spec/lib/model_methods_spec.rb +29 -0
  83. data/spec/lib/repository_controller_behavior_spec.rb +28 -0
  84. data/spec/models/mods_asset_spec.rb +21 -0
  85. data/spec/models/solr_document_spec.rb +17 -0
  86. data/spec/models/user_spec.rb +32 -0
  87. data/spec/rcov.opts +3 -0
  88. data/spec/spec.opts +4 -0
  89. data/spec/spec_helper.rb +26 -0
  90. data/spec/support/Gemfile +12 -0
  91. data/spec/support/app/models/generic_content.rb +23 -0
  92. data/spec/support/app/models/sample.rb +33 -0
  93. data/spec/support/app/models/solr_document.rb +5 -0
  94. data/spec/support/db/migrate/20111101221803_create_searches.rb +16 -0
  95. data/spec/support/lib/generators/test_app_generator.rb +33 -0
  96. data/spec/support/matchers/helper_matcher.rb +14 -0
  97. data/spec/support/matchers/solr_matchers.rb +60 -0
  98. data/spec/support/spec/fixtures/hydra_test_generic_content.foxml.xml +138 -0
  99. data/spec/support/spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml +234 -0
  100. data/spec/unit/hydra-head-engine_spec.rb +8 -0
  101. data/spec/unit/hydra-head_spec.rb +8 -0
  102. data/tasks/hydra-head-fixtures.rake +58 -0
  103. data/tasks/hydra_jetty.rake +53 -0
  104. data/tasks/rspec.rake +53 -0
  105. metadata +469 -0
@@ -0,0 +1,21 @@
1
+ <% carriers =
2
+ {
3
+ 'Please select your carrier' => '',
4
+ 'AT&T' => 'att',
5
+ 'Verizon' => 'verizon',
6
+ 'T Mobile' => 'tmobile',
7
+ 'Sprint' => 'sprint',
8
+ 'Nextel' => 'nextel',
9
+ 'Virgin Mobile' => 'vmobile',
10
+ 'Alltel' => 'alltel',
11
+ 'Cricket' => 'cricket'
12
+ }
13
+ %>
14
+ <h1>SMS This</h1>
15
+ <%= form_tag url_for(:action => 'send_email_record', :style => 'sms'), :id => 'sms_form', :method => :post do %>
16
+ <%= label_tag(:to, "Phone Number:") %><br/>
17
+ <%= text_field_tag :sms_to %><br/>
18
+ <%= label_tag(:carrier, "Carrier:") %><br/>
19
+ <%= select_tag(:carrier, options_for_select(carriers, '')) %><br/>
20
+ <%= submit_tag "Send" %>
21
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <div id="sortAndPerPage">
2
+ <% unless @response.response['numFound'] < 2 %>
3
+ <%= form_tag catalog_index_path, :method=>:get, :class=>'per_page' do %>
4
+ <%= label_tag(:per_page, "Show") %>
5
+ <%= select_tag(:per_page, options_for_select(['10', '20', '50', '100'], h(params[:per_page])), :title => "Number of results to display per page", :onchange => 'this.form.submit()') %>
6
+ per page
7
+ <%= search_as_hidden_fields(:omit_keys => [:page, :per_page]) %>
8
+
9
+ <noscript><%= submit_tag 'update' %></noscript>
10
+ <% end %>
11
+
12
+ <%= form_tag catalog_index_path, :method=>:get, :class=>'sort', :id => "sort_form" do %>
13
+ <%= label_tag 'sort', 'Sort by' %>
14
+ <%= select_tag(:sort, options_for_select(sort_fields, h(params[:sort])), :onchange => 'this.form.submit()') %>
15
+
16
+ <%= search_as_hidden_fields(:omit_keys => [:page, :sort]) %>
17
+
18
+ <noscript><%= submit_tag 'sort results' %></noscript>
19
+ <% end %>
20
+ <% end %>
21
+
22
+
23
+ </div>
@@ -0,0 +1,10 @@
1
+ <ul>
2
+ <li>
3
+ <% display_class = (!params[:home_context] || params[:home_context]=='authors') ? 'class="selected"' : '' %>
4
+ <a <%= display_class %> href="/catalog?home_context=authors">Authors</a>
5
+ </li>
6
+ <li>
7
+ <% display_class = params[:home_context]=='journals' ? 'class="selected"' : '' %>
8
+ <a <%= display_class %> href="/catalog?home_context=journals">Journals</a>
9
+ </li>
10
+ </ul>
File without changes
@@ -0,0 +1,40 @@
1
+ <%-
2
+ doc_title = (document_show_html_title.nil? || document_show_html_title.empty?) ? @document[:id] : document_show_html_title.first
3
+ @page_title = "#{doc_title} - #{application_name}"
4
+ -%>
5
+ <div id="showHead">
6
+ <div id="showUtils">
7
+ <span class="back_to_cat"><%= link_back_to_catalog :label=>'← Return to search results' %></span>
8
+ <%- if @previous_document || @next_document -%>
9
+ <div id="previousNextDocument">
10
+ <span class="previous"><%= link_to_previous_document(@previous_document) %></span>
11
+ <%- end -%>
12
+ <%- if session[:search][:counter].to_i > 0 -%>
13
+ <span class="result-num">
14
+ <%= session[:search][:counter].to_i %> of <%= format_num(session[:search][:total]) %>
15
+ </span>
16
+ <%- end -%>
17
+ <%- if @previous_document || @next_document -%>
18
+ <span class="next"><%= link_to_next_document(@next_document)%></span>
19
+ </div>
20
+ <%- end -%>
21
+ <%- if can?(:edit, @document) && controller.action_name != "delete" -%>
22
+ <span class="edit-browse">
23
+ <%= edit_and_browse_links %>
24
+ </span>
25
+ <%- end -%>
26
+ </div>
27
+ </div>
28
+ <div id="document" class="<%= controller.action_name == "edit" ? "document_edit" : "document_show" %> <%= "combined_document_view" if session[:scripts] %>">
29
+ <div id="<%= format_pid(@document[:id]) %>">
30
+ <%= "<h1>Add Your Work</h1>".html_safe if controller.action_name == "edit" %>
31
+ <div class="document">
32
+ <%= render_document_partial @document, params["action"] %>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ <% if controller.action_name == "edit" %>
37
+ <div class="delete-asset">
38
+ <%= button_to("Delete This Item", {:action => :destroy, :controller => :"hydra/assets", :id => @document_fedora.pid}, :data => { :confirm => 'Are you sure?' }, :method => :delete )%>
39
+ </div>
40
+ <% end %>
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= h(@page_title || application_name) %></title>
6
+ <link href="<%= opensearch_catalog_url(:format => 'xml') %>" title="<%= application_name%>" type="application/opensearchdescription+xml" rel="search"/>
7
+ <%= favicon_link_tag asset_path('favicon.ico') %>
8
+ <%= stylesheet_link_tag "application" %>
9
+ <%= javascript_include_tag "application" %>
10
+ <%= csrf_meta_tags %>
11
+ <%= raw(render_head_content) %>
12
+ </head>
13
+
14
+ <body class="<%= render_body_class %>">
15
+ <div id="page">
16
+
17
+ <div id="hd">
18
+ <div id="user_util_links">
19
+ <%= render :partial => '/user_util_links' %>
20
+ </div>
21
+ </div>
22
+
23
+ <div id="bd">
24
+ <div id="main">
25
+ <div id="main_container">
26
+ <%= render :partial=>'/flash_msg' %>
27
+ <%= yield %>
28
+ </div>
29
+ </div>
30
+ <div id="sidebar"><%= sidebar_items.join('').html_safe %></div>
31
+ </div>
32
+
33
+
34
+ <div id="ft">
35
+ <div class="contact_info"></div>
36
+ <div class="aux_links"> </div>
37
+ <div id="footer_notices">
38
+ <div id="bottom_text">
39
+ <div id="hydra_logo"><%= image_tag('hydra/powered_by_hydra.png', :width => 80, :height => 50, :alt => "Hydra logo") %></div>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+
45
+ </body>
46
+
47
+ </html>
@@ -0,0 +1,6 @@
1
+ default:
2
+ jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8983 %>
3
+ startup_wait: 30
4
+ java_opts:
5
+ - "-Xmx256m"
6
+ - "-XX:MaxPermSize=128m"
@@ -0,0 +1,7 @@
1
+ en:
2
+ date:
3
+ formats:
4
+ hydra: "%b. %e, %Y"
5
+ time:
6
+ formats:
7
+ hydra: "%b. %e, %Y"
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ version = File.read(File.expand_path("../../HYDRA_VERSION", __FILE__)).strip
3
+
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Matt Zumwalt, Bess Sadler, Julie Meloni, Naomi Dushay, Jessie Keck, John Scofield, Justin Coyne & many more. See https://github.com/projecthydra/hydra-head/contributors"]
7
+ gem.email = ["hydra-tech@googlegroups.com"]
8
+ gem.homepage = "http://projecthydra.org"
9
+ gem.summary = %q{Hydra-Head Rails Engine (requires Rails3) }
10
+ gem.description = %q{Hydra-Head is a Rails Engine containing the core code for a Hydra application. The full hydra stack includes: Blacklight, Fedora, Solr, active-fedora, solrizer, and om}
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "hydra-core"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = version
18
+ # gem.required_ruby_version = '>= 1.9.3'
19
+
20
+
21
+ gem.add_dependency "rails", '~>3.2.3'
22
+ gem.add_dependency "blacklight", '~>3.4'
23
+ gem.add_dependency "devise"
24
+ gem.add_dependency "active-fedora", '~>4.1'
25
+ gem.add_dependency 'RedCloth', '=4.2.9'
26
+ gem.add_dependency 'block_helpers'
27
+ gem.add_dependency 'sanitize'
28
+ gem.add_dependency 'hydra-mods', ">= 0.0.5"
29
+ gem.add_dependency 'deprecation', ">= 0.0.5"
30
+ gem.add_dependency 'jquery-rails'
31
+ gem.add_dependency 'hydra-access-controls', version
32
+
33
+ gem.add_development_dependency 'sqlite3'
34
+ gem.add_development_dependency 'yard'
35
+ gem.add_development_dependency 'jettywrapper', ">=1.3.1"
36
+ gem.add_development_dependency 'rspec-rails'
37
+ gem.add_development_dependency 'cucumber-rails', '>=1.2.0'
38
+ gem.add_development_dependency 'factory_girl_rails', '<2.0.0' #>=2.0.0 requires ruby 1.9
39
+ gem.add_development_dependency 'solrizer-fedora', '>=2.1.0'
40
+ end
@@ -0,0 +1,3 @@
1
+ # Needed for testing
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,50 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # Copy Blacklight assets to public folder in current app.
3
+ # If you want to do this on application startup, you can
4
+ # add this next line to your one of your environment files --
5
+ # generally you'd only want to do this in 'development', and can
6
+ # add it to environments/development.rb:
7
+ # require File.join(Hydra.root, "lib", "generators", "hydra", "assets_generator.rb")
8
+ # Hydra::Assets.start(["--force", "--quiet"])
9
+
10
+
11
+ # Need the requires here so we can call the generator from environment.rb
12
+ # as suggested above.
13
+ require 'rails/generators'
14
+ require 'rails/generators/base'
15
+ module Hydra
16
+ class AssetsGenerator < Rails::Generators::Base
17
+ source_root File.expand_path('../templates', __FILE__)
18
+
19
+ def assets
20
+ if use_asset_pipeline?
21
+ insert_into_file "app/assets/stylesheets/application.css", :after => " *= require_self" do
22
+ %q{
23
+ *
24
+ * Required by Hydra
25
+ *= require 'hydra/styles'
26
+ }
27
+ end
28
+
29
+ insert_into_file "app/assets/javascripts/application.js", :after => "//= require jquery_ujs" do
30
+ %q{
31
+ // Required by Hydra
32
+ //= require 'jquery.ui.datepicker.js'
33
+ }
34
+ end
35
+ directory("../../../../app/assets/images/blacklight", "public/images/blacklight")
36
+ else
37
+ # directories are relative to the source_root
38
+ directory("../../../../assets/images", "public/images")
39
+ directory("../../../../assets/stylesheets", "public/stylesheets")
40
+ directory("../../../../assets/javascripts", "public/javascripts")
41
+ end
42
+ end
43
+
44
+ private
45
+ def use_asset_pipeline?
46
+ (Rails::VERSION::MAJOR >= 3 and Rails::VERSION::MINOR >= 1) and Rails.application.config.assets.enabled
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ module Hydra
6
+ class CucumberSupportGenerator < Rails::Generators::Base
7
+
8
+ source_root File.expand_path('../../../../test_support/features', __FILE__)
9
+
10
+ argument :features_dir, :type => :string , :default => "features"
11
+
12
+ desc """
13
+ This Generator copies Hydra's cucumber step definitions and paths into your application's features directory.
14
+ We have plans to provide the step definitions directly through the hydra-head gem without requiring this step of copying the files.
15
+ In the meantime, you need to copy the files in order to use them.
16
+
17
+ Defaults to assuming that your cucumber features live in a directory called \"features\". To pass in an alternative path to your features directory,
18
+
19
+ rails generate hydra:cucumber_support test_support/features
20
+
21
+ """
22
+
23
+ def copy_cucumber_support
24
+ directory("step_definitions", "#{features_dir}/step_definitions")
25
+ copy_file("support/paths.rb", "#{features_dir}/support/paths.rb")
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,160 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ module Hydra
6
+ class HeadGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ argument :model_name, :type => :string , :default => "user"
12
+
13
+ desc """
14
+ This generator makes the following changes to your application:
15
+ 1. Creates a database migration for superusers if they do not exist in /db/migrate
16
+ 2. Adds additional mime types to you application in the file '/config/initializers/mime_types.rb'
17
+ 3. Creates config/initializers/hydra_config.rb
18
+ 4. Creates config/fedora.yml and config/solr.yml which you may need to modify to tell the hydra head where to find fedora & solr
19
+ 5. Creates a number of role_map config files that are used in the placeholder user roles implementation
20
+ Enjoy building your Hydra Head!
21
+ """
22
+
23
+ #
24
+ # Config Files & Initializers
25
+ #
26
+
27
+ # Copy all files in templates/config directory to host config
28
+ def create_configuration_files
29
+ #CatalogController
30
+ copy_file "catalog_controller.rb", "app/controllers/catalog_controller.rb"
31
+
32
+ # Initializers
33
+ copy_file "config/initializers/hydra_config.rb", "config/initializers/hydra_config.rb"
34
+ copy_file "config/initializers/action_dispatch_http_upload_monkey_patch.rb", "config/initializers/action_dispatch_http_upload_monkey_patch.rb"
35
+
36
+ # Role Mappings
37
+ copy_file "config/role_map_cucumber.yml", "config/role_map_cucumber.yml"
38
+ copy_file "config/role_map_development.yml", "config/role_map_development.yml"
39
+ copy_file "config/role_map_production.yml", "config/role_map_production.yml"
40
+ copy_file "config/role_map_test.yml", "config/role_map_test.yml"
41
+
42
+ # Solr Mappings
43
+ copy_file "config/solr_mappings.yml", "config/solr_mappings.yml"
44
+
45
+ # Fedora & Solr YAML files
46
+ copy_file "config/fedora.yml", "config/fedora.yml"
47
+ copy_file "config/solr.yml", "config/solr.yml"
48
+
49
+ # Fedora & Solr Config files
50
+ directory "fedora_conf"
51
+ directory "solr_conf"
52
+ end
53
+
54
+ # Register mimetypes required by hydra-head
55
+ def add_mime_types
56
+ puts "Updating Mime Types"
57
+ insert_into_file "config/initializers/mime_types.rb", :before => 'Mime::Type.register_alias "text/plain", :refworks_marc_txt' do <<EOF
58
+ # Mime Types Added By Hydra Head:
59
+
60
+ # Mime::Type.register "text/html", :html
61
+ # Mime::Type.register "application/pdf", :pdf
62
+ # Mime::Type.register "image/jpeg2000", :jp2
63
+ Mime::Type.register_alias "text/html", :textile
64
+ Mime::Type.register_alias "text/html", :inline
65
+
66
+ EOF
67
+ end
68
+ end
69
+
70
+ #
71
+ # Static Assets
72
+ #
73
+ # Call external generator in AssetsGenerator, which copies static assets like stylesheets, javascript and images
74
+ # into the app's public directory
75
+ def copy_public_assets
76
+ generate "hydra:assets"
77
+ end
78
+
79
+ #
80
+ # Migrations
81
+ #
82
+
83
+ # Implement the required interface for Rails::Generators::Migration.
84
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
85
+ def self.next_migration_number(dirname)
86
+ unless @prev_migration_nr
87
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
88
+ else
89
+ @prev_migration_nr += 1
90
+ end
91
+ @prev_migration_nr.to_s
92
+ end
93
+
94
+ # Add Hydra behaviors to the user model
95
+ def inject_hydra_user_behavior
96
+ file_path = "app/models/#{model_name.underscore}.rb"
97
+ if File.exists?(file_path)
98
+ inject_into_class file_path, model_name.classify do
99
+ "# Connects this user object to Hydra behaviors. " +
100
+ "\n include Hydra::User\n"
101
+ end
102
+ else
103
+ puts " \e[31mFailure\e[0m Hydra requires a user object in order to apply access controls. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g hydra:head client"
104
+ end
105
+ end
106
+
107
+ # Add Hydra behaviors and Filters to CatalogController
108
+ def inject_hydra_catalog_behavior
109
+ puts "Adding Hydra behaviors to CatalogController"
110
+ controller_name = "catalog_controller"
111
+ file_path = "app/controllers/#{controller_name.underscore}.rb"
112
+ if File.exists?(file_path)
113
+ insert_into_file file_path, :after => 'include Blacklight::Catalog' do
114
+ "\n # Extend Blacklight::Catalog with Hydra behaviors (primarily editing)." +
115
+ "\n include Hydra::Controller::ControllerBehavior\n" +
116
+ "\n # These before_filters apply the hydra access controls" +
117
+ "\n before_filter :enforce_access_controls" +
118
+ "\n before_filter :enforce_viewing_context_for_show_requests, :only=>:show" +
119
+ "\n # This applies appropriate access controls to all solr queries" +
120
+ "\n CatalogController.solr_search_params_logic << :add_access_controls_to_solr_params" +
121
+ "\n # This filters out objects that you want to exclude from search results, like FileAssets" +
122
+ "\n CatalogController.solr_search_params_logic << :exclude_unwanted_models"
123
+
124
+ end
125
+ else
126
+ puts " \e[31mFailure\e[0m Could not find #{model_name.underscore}.rb. To add Hydra behaviors to your Blacklight::Catalog Controllers, you must include the Hydra::Controller::ControllerBehavior module in the Controller class definition. See the Hydra::Controller::ControllerBehavior section in the Hydra API Docs for more info."
127
+ end
128
+ end
129
+
130
+ # Inject call to HydraHead.add_routes in config/routes.rb
131
+ def inject_hydra_routes
132
+ insert_into_file "config/routes.rb", :after => 'Blacklight.add_routes(self)' do
133
+ "\n # Add Hydra routes. For options, see API docs for HydraHead.routes"
134
+ "\n HydraHead.add_routes(self)"
135
+ end
136
+ end
137
+
138
+ # Add Hydra to the application controller
139
+ def inject_hydra_controller_behavior
140
+ puts "Adding Hydra behaviors to ApplicationController"
141
+ controller_name = "ApplicationController"
142
+ file_path = "app/controllers/#{controller_name.underscore}.rb"
143
+ if File.exists?(file_path)
144
+ insert_into_file file_path, :after => 'include Blacklight::Controller' do
145
+ " \n# Adds Hydra behaviors into the application controller \n" +
146
+ " include Hydra::Controller::ControllerBehavior\n" +
147
+ " def layout_name\n" +
148
+ " 'hydra-head'\n" +
149
+ " end\n"
150
+ end
151
+ else
152
+ puts " \e[31mFailure\e[0m Could not find #{model_name.underscore}.rb. To add Hydra behaviors to your Blacklight::Catalog Controllers, you must include the Hydra::Controller::ControllerBehavior module in the Controller class definition. See the Hydra::Controller::ControllerBehavior section in the Hydra API Docs for more info."
153
+ end
154
+ end
155
+
156
+
157
+
158
+
159
+ end # HeadGenerator
160
+ end # Hydra