hydra-head 3.1.0.pre5 → 3.1.0.rc1

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 (44) hide show
  1. data/HISTORY.textile +14 -1
  2. data/app/helpers/application_helper.rb +1 -166
  3. data/app/helpers/article_metadata_helper.rb +2 -78
  4. data/app/helpers/blacklight_helper.rb +2 -195
  5. data/app/helpers/downloads_helper.rb +3 -18
  6. data/app/helpers/generic_content_objects_helper.rb +2 -14
  7. data/app/helpers/hydra/application_helper_behavior.rb +10 -0
  8. data/app/helpers/hydra/article_metadata_helper_behavior.rb +82 -0
  9. data/app/helpers/hydra/blacklight_helper_behavior.rb +203 -0
  10. data/app/helpers/hydra/downloads_helper_behavior.rb +21 -0
  11. data/app/helpers/hydra/generic_content_objects_helper_behavior.rb +16 -0
  12. data/app/helpers/hydra/hydra_assets_helper_behavior.rb +66 -0
  13. data/app/helpers/hydra/hydra_djatoka_helper_behavior.rb +23 -0
  14. data/app/helpers/hydra/hydra_fedora_metadata_helper_behavior.rb +349 -0
  15. data/app/helpers/hydra/hydra_helper_behavior.rb +184 -0
  16. data/app/helpers/hydra/hydra_uploader_helper_behavior.rb +18 -0
  17. data/app/helpers/hydra/inline_editable_metadata_helper_behavior.rb +15 -0
  18. data/app/helpers/hydra/javascript_includes_helper_behavior.rb +91 -0
  19. data/app/helpers/hydra/personalization_helper_behavior.rb +44 -0
  20. data/app/helpers/hydra/release_process_helper_behavior.rb +32 -0
  21. data/app/helpers/hydra_assets_helper.rb +2 -64
  22. data/app/helpers/hydra_djatoka_helper.rb +3 -22
  23. data/app/helpers/hydra_fedora_metadata_helper.rb +2 -347
  24. data/app/helpers/hydra_helper.rb +2 -182
  25. data/app/helpers/hydra_uploader_helper.rb +2 -16
  26. data/app/helpers/inline_editable_metadata_helper.rb +3 -14
  27. data/app/helpers/javascript_includes_helper.rb +2 -89
  28. data/app/helpers/personalization_helper.rb +2 -42
  29. data/app/helpers/release_process_helper.rb +2 -30
  30. data/lib/blacklight/blacklight_helper_behavior.rb +612 -0
  31. data/lib/hydra-head/version.rb +1 -1
  32. data/lib/railties/hydra-fixtures.rake +0 -1
  33. data/tasks/hydra-head.rake +1 -2
  34. data/test_support/features/step_definitions/edit_metadata_steps.rb +0 -1
  35. data/{spec → test_support/spec}/controllers/catalog_valid_html_spec.rb +1 -11
  36. data/test_support/spec/helpers/blacklight_helper_spec.rb +6 -2
  37. data/test_support/spec/spec_helper.rb +5 -3
  38. metadata +23 -14
  39. data/lib/hydra/fixture_loader.rb +0 -48
  40. data/lib/stanford/searchworks_helper.rb +0 -1338
  41. data/lib/stanford/solr_helper.rb +0 -108
  42. data/lib/stanford_blacklight_extensions.rb +0 -6
  43. data/spec-rails2/helpers/hydra_fedora_metadata_helper_spec.rb +0 -219
  44. data/spec-rails2/spec_helper.rb +0 -88
@@ -1,7 +1,20 @@
1
+ h3. 3.1.0
2
+ * Updated to ActiveFedora 3.1.1
3
+ * Update rake tasks to leverage jettywrapper
4
+ * Don't fork processes to run tests
5
+ * Refactor helpers, so that applications can easily override them
6
+
7
+ h3. 3.0.1
8
+
9
+ * generator has the correct solr config files
10
+ * reverted back to using object_type_facet for "Format" facet. This is instead of using active_fedora_model_s, which made some cucumber tests unstable because active_fedora_model_s is populated inconsistently by ActiveFedora (really we should deprecate that solr field)
11
+
12
+ h2. 3.0.0: Upgrade to Rails 3
13
+
1
14
  h3. 0.0.1
2
15
 
3
16
  Pulled plugin code from Hydrus
4
17
  * Javascript disabled, progressive enhancement set up
5
18
  * Better Cucumber Coverage
6
19
 
7
- h3. 0.0.0
20
+ h3. 0.0.0
@@ -1,168 +1,3 @@
1
- require "hydra_helper"
2
1
  module ApplicationHelper
3
- include Stanford::SearchworksHelper
4
- #include Stanford::SolrHelper # this is already included by the SearchworksHelper
5
- include HydraHelper
6
-
7
- def application_name
8
- 'A Hydra Head'
9
- end
10
-
11
- def get_data_with_linked_label(doc, label, field_string, opts={})
12
-
13
- (opts[:default] and !doc[field_string]) ? field = opts[:default] : field = doc[field_string]
14
- delim = opts[:delimiter] ? opts[:delimiter] : "<br/>"
15
- if doc[field_string]
16
- text = "<dt>#{label}</dt><dd>"
17
- if field.respond_to?(:each)
18
- text += field.map do |l|
19
- linked_label(l, field_string)
20
- end.join(delim)
21
- else
22
- text += linked_label(field, field_string)
23
- end
24
- text += "</dd>"
25
- text
26
- end
27
- end
28
-
29
- def linked_label(field, field_string)
30
- link_to(field, add_facet_params(field_string, field).merge!({"controller" => "catalog", :action=> "index"}))
31
- end
32
-
33
- # currently only used by the render_document_partial helper method (below)
34
- def document_partial_name(document)
35
- if !document[Blacklight.config[:show][:display_type]].nil?
36
- return document[Blacklight.config[:show][:display_type]].first.gsub("info:fedora/afmodel:","").underscore.pluralize
37
- else
38
- return nil
39
- end
40
- end
41
-
42
- # Overriding Blacklight's render_document_partial
43
- # given a doc and action_name, this method attempts to render a partial template
44
- # based on the value of doc[:format]
45
- # if this value is blank (nil/empty) the "default" is used
46
- # if the partial is not found, the "default" partial is rendered instead
47
- def render_document_partial(doc, action_name, locals={})
48
- format = document_partial_name(doc)
49
- begin
50
- Rails.logger.debug("attempting to render #{format}/_#{action_name}")
51
- render :partial=>"#{format}/#{action_name}", :locals=>{:document=>doc}.merge(locals)
52
- rescue ActionView::MissingTemplate
53
- Rails.logger.debug("rendering default partial catalog/_#{action_name}_partials/default")
54
- render :partial=>"catalog/_#{action_name}_partials/default", :locals=>{:document=>doc}.merge(locals)
55
- end
56
- end
57
-
58
- ###
59
- ### Overrides pulled in from Libra
60
- ###
61
-
62
- def render_facet_value(facet_solr_field, item, options ={})
63
- if item.is_a? Array
64
- link_to_unless(options[:suppress_link], item[0], add_facet_params_and_redirect(facet_solr_field, item[0]), :class=>"facet_select") + " (" + format_num(item[1]) + ")"
65
- else
66
- link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select") + " (" + format_num(item.hits) + ")"
67
- end
68
- end
69
-
70
- # Removing the [remove] link from the default selected facet display
71
- def render_selected_facet_value(facet_solr_field, item)
72
- '<span class="selected">' +
73
- render_facet_value(facet_solr_field, item, :suppress_link => true) +
74
- '</span>'
75
- end
76
-
77
- def render_complex_facet_value(facet_solr_field, item, options ={})
78
- link_to_unless(options[:suppress_link], format_item_value(item.value), add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select") + " (" + format_num(item.hits) + ")"
79
- end
80
-
81
- def render_journal_facet_value(facet_solr_field, item, options ={})
82
-
83
- val = item.value.strip.length > 12 ? item.value.strip[0..12].concat("...") : item.value.strip
84
- link_to_unless(options[:suppress_link], val, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select") + " (" + format_num(item.hits) + ")"
85
- end
86
-
87
- def render_complex_facet_image(facet_solr_field, item, options = {})
88
- computing_id = extract_computing_id(item.value)
89
- if File.exists?("#{Rails.root}/public/images/faculty_images/#{computing_id}.jpg")
90
- img = image_tag "/images/faculty_images/#{computing_id}.jpg", :width=> "100", :alt=>"#{item.value}"
91
- else
92
- img = image_tag "/plugin_assets/hydra-head/images/default_thumbnail.gif", :width=>"100", :alt=>"#{item.value}"
93
- end
94
- link_to_unless(options[:suppress_link], img, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select facet_image")
95
- end
96
-
97
- def render_journal_image(facet_solr_field, item, options = {})
98
- if File.exists?("#{Rails.root}/public/images/journal_images/#{item.value.strip.downcase.gsub(/\s+/,'_')}.jpg")
99
- img = image_tag "/images/journal_images/#{item.value.strip.downcase.gsub(/\s+/,'_')}.jpg", :width => "100"
100
- else
101
- img = image_tag "/plugin_assets/hydra-head/images/default_thumbnail.gif", :width=>"100", :alt=>"#{item.value}"
102
- end
103
-
104
- link_to_unless(options[:suppress_link], img, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select")
105
- end
106
-
107
- def get_randomized_display_items items
108
- clean_items = items.each.inject([]) do |array, item|
109
- array << item unless item.value.strip.blank?
110
- array
111
- end
112
-
113
- if clean_items.length < 6
114
- clean_items.sort_by {|item| item.value }
115
- else
116
- rdi = clean_items.sort_by {rand}.slice(0..5)
117
- return rdi.sort_by {|item| item.value.downcase}
118
- end
119
-
120
- end
121
-
122
- def extract_computing_id val
123
- cid = val.split(" ")[-1]
124
- cid[1..cid.length-2]
125
- end
126
-
127
- def format_item_value val
128
- begin
129
- last, f_c = val.split(", ")
130
- first = f_c.split(" (")[0]
131
- rescue
132
- return val.nil? ? "" : val
133
- end
134
- [last, "#{first[0..0]}."].join(", ")
135
- end
136
-
137
- # COPIED from vendor/plugins/blacklight/app/helpers/application_helper.rb
138
- # Used in catalog/facet action, facets.rb view, for a click
139
- # on a facet value. Add on the facet params to existing
140
- # search constraints. Remove any paginator-specific request
141
- # params, or other request params that should be removed
142
- # for a 'fresh' display.
143
- # Change the action to 'index' to send them back to
144
- # catalog/index with their new facet choice.
145
- def add_facet_params_and_redirect(field, value)
146
- new_params = add_facet_params(field, value)
147
-
148
- # Delete page, if needed.
149
- new_params.delete(:page)
150
-
151
- # Delete :qt, if needed - added to resolve NPE errors
152
- new_params.delete(:qt)
153
-
154
- # Delete any request params from facet-specific action, needed
155
- # to redir to index action properly.
156
- Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key|
157
- new_params.delete(paginator_key)
158
- end
159
- new_params.delete(:id)
160
-
161
- # Force action to be index.
162
- new_params[:action] = "index"
163
-
164
- new_params
165
- end
166
-
167
-
2
+ include Hydra::ApplicationHelperBehavior
168
3
  end
@@ -1,80 +1,4 @@
1
- # This was CatalogHelper in the rails2 version of hydra-head
2
1
  module ArticleMetadataHelper
3
-
4
- def format_date date
5
- date.strftime("%b. %e, %Y")
6
- end
7
-
8
-
9
- def depositor_string depositor=nil
10
- "#{depositor}" unless depositor.nil?
11
- end
12
- def get_children pid
13
- par = solr_facet_params(:is_part_of_s)
14
- query="_query_:\"{!dismax qf=$qf_dismax pf=$pf_dismax}is_part_of_s:info\\:fedora/#{pid.gsub(":",'\:')}\""
15
- # start query of with user supplied query term
16
- #q << "_query_:\"{!dismax qf=$qf_dismax pf=$pf_dismax}#{user_query}\""
17
- (response, document_list) = get_search_results( :q=>query )
18
- par.inspect
19
- end
20
-
21
- def author_list(doc)
22
- get_persons_from_roles(doc,['author','collaborator','creator','contributor']).map {|person| format_person_string(person[:first],person[:last],person[:institution])}
23
- end
24
-
25
- def researcher_list(doc)
26
- get_persons_from_roles(doc,['research team head']).map {|person| format_person_string(person[:first],person[:last],person[:institution])}
27
- end
28
-
29
- def get_persons_from_roles(doc,roles,opts={})
30
- i = 0
31
- persons =[]
32
- while i < 10
33
- persons_roles = [] # reset the array
34
- persons_roles = doc["person_#{i}_role_t"].map{|w|w.strip.downcase} unless doc["person_#{i}_role_t"].nil?
35
- if persons_roles and (persons_roles & roles).length > 0
36
- persons << {:first => doc["person_#{i}_first_name_t"], :last=> doc["person_#{i}_last_name_t"], :institution => doc["person_#{i}_institution_t"]}
37
- end
38
- i += 1
39
- end
40
- return persons
41
- end
42
-
43
- def format_person_string first_name, last_name, affiliation, opt={}
44
- full_name = [first_name, last_name].join(" ").strip
45
- affiliation = affiliation.nil? ? "" : "(#{affiliation})"
46
- [full_name, affiliation].join(" ").concat(";")
47
- end
48
-
49
- def journal_info(doc)
50
- title = doc.get(:journal_title_info_main_title_t)
51
- pub_date = doc.get(:journal_issue_publication_date_t)
52
- volume = doc.get(:journal_issue_volume_t)
53
- issue = doc.get(:journal_issue_volume_t)
54
- start_page = doc.get(:journal_issue_pages_start_t)
55
- end_page = doc.get(:journal_issue_end_page_t)
56
- journal_info = "#{title}. #{pub_date}; #{volume} ( #{issue} ): #{start_page} - #{end_page}"
57
- journal_info = "" if journal_info.match(/^\.\s+;\s+\(\s+\)\:\s+-\s*$/)
58
- journal_info
59
- end
60
-
61
- def short_abstract(doc,max=250)
62
- abstract = doc.get(:abstract_t)
63
- if abstract.blank?
64
- return ""
65
- elsif abstract.length < max
66
- return abstract
67
- else
68
- return abstract[0..max].strip.concat("...")
69
- end
70
- end
71
-
72
- def admin_info(doc)
73
- info =<<-EOS
74
- Deposited: #{format_date(DateTime.parse(doc.get(:system_create_dt)).to_time)}
75
- | By: #{depositor_string(doc.get(:depositor_t))}
76
- | Status: Created
77
- EOS
78
- end
79
-
2
+ include Hydra::ArticleMetadataHelperBehavior
80
3
  end
4
+
@@ -1,197 +1,4 @@
1
- require "hydra_helper"
2
-
3
1
  module BlacklightHelper
4
- require "#{Blacklight.root}/app/helpers/blacklight_helper"
5
- #include Stanford::SearchworksHelper
6
- #include Stanford::SolrHelper # this is already included by the SearchworksHelper
7
- include HydraHelper
8
-
9
- def application_name
10
- 'A Hydra Head'
11
- end
12
-
13
- def get_data_with_linked_label(doc, label, field_string, opts={})
14
-
15
- (opts[:default] and !doc[field_string]) ? field = opts[:default] : field = doc[field_string]
16
- delim = opts[:delimiter] ? opts[:delimiter] : "<br/>"
17
- if doc[field_string]
18
- text = "<dt>#{label}</dt><dd>"
19
- if field.respond_to?(:each)
20
- text += field.map do |l|
21
- linked_label(l, field_string)
22
- end.join(delim)
23
- else
24
- text += linked_label(field, field_string)
25
- end
26
- text += "</dd>"
27
- text
28
- end
29
- end
30
-
31
- def linked_label(field, field_string)
32
- link_to(field, add_facet_params(field_string, field).merge!({"controller" => "catalog", :action=> "index"}))
33
- end
34
- def link_to_document(doc, opts={:label=>Blacklight.config[:index][:show_link].to_sym, :counter => nil,:title => nil})
35
- label = case opts[:label]
36
- when Symbol
37
- doc.fetch(opts[:label], "")
38
- when String
39
- opts[:label]
40
- else
41
- raise 'Invalid label argument'
42
- end
43
-
44
- if label.blank?
45
- label = doc[:id]
46
- end
47
-
48
- link_to_with_data(label, catalog_path(doc[:id]), {:method => :put, :data => {:counter => opts[:counter]},:title=>opts[:title]})
49
- end
50
-
51
- # currently only used by the render_document_partial helper method (below)
52
- def document_partial_name(document)
53
- if !document[Blacklight.config[:show][:display_type]].nil?
54
- return document[Blacklight.config[:show][:display_type]].first.gsub("info:fedora/afmodel:","").underscore.pluralize
55
- else
56
- return nil
57
- end
58
- end
59
-
60
- # Overriding Blacklight's render_document_partial
61
- # given a doc and action_name, this method attempts to render a partial template
62
- # based on the value of doc[:format]
63
- # if this value is blank (nil/empty) the "default" is used
64
- # if the partial is not found, the "default" partial is rendered instead
65
- def render_document_partial(doc, action_name, locals={})
66
- format = document_partial_name(doc)
67
- begin
68
- Rails.logger.debug("attempting to render #{format}/_#{action_name}")
69
- render :partial=>"#{format}/#{action_name}", :locals=>{:document=>doc}.merge(locals)
70
- rescue ActionView::MissingTemplate
71
- Rails.logger.debug("rendering default partial catalog/_#{action_name}_partials/default")
72
- render :partial=>"catalog/_#{action_name}_partials/default", :locals=>{:document=>doc}.merge(locals)
73
- end
74
- end
75
-
76
- ###
77
- ### Overrides pulled in from Libra
78
- ###
79
-
80
- def render_facet_value(facet_solr_field, item, options ={})
81
- if item.is_a? Array
82
- link_to_unless(options[:suppress_link], item[0], add_facet_params_and_redirect(facet_solr_field, item[0]), :class=>"facet_select") + " (" + format_num(item[1]) + ")"
83
- else
84
- link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select") + " (" + format_num(item.hits) + ")"
85
- end
86
- end
87
-
88
- def render_complex_facet_value(facet_solr_field, item, options ={})
89
- link_to_unless(options[:suppress_link], format_item_value(item.value), add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select") + " (" + format_num(item.hits) + ")"
90
- end
91
-
92
- def render_journal_facet_value(facet_solr_field, item, options ={})
93
-
94
- val = item.value.strip.length > 12 ? item.value.strip[0..12].concat("...") : item.value.strip
95
- link_to_unless(options[:suppress_link], val, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select") + " (" + format_num(item.hits) + ")"
96
- end
97
-
98
- def render_complex_facet_image(facet_solr_field, item, options = {})
99
- computing_id = extract_computing_id(item.value)
100
- if File.exists?("#{Rails.root}/public/images/faculty_images/#{computing_id}.jpg")
101
- img = image_tag "/images/faculty_images/#{computing_id}.jpg", :width=> "100", :alt=>"#{item.value}"
102
- else
103
- img = image_tag "/plugin_assets/hydra-head/images/default_thumbnail.gif", :width=>"100", :alt=>"#{item.value}"
104
- end
105
- link_to_unless(options[:suppress_link], img, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select facet_image")
106
- end
107
-
108
- def render_journal_image(facet_solr_field, item, options = {})
109
- if File.exists?("#{Rails.root}/public/images/journal_images/#{item.value.strip.downcase.gsub(/\s+/,'_')}.jpg")
110
- img = image_tag "/images/journal_images/#{item.value.strip.downcase.gsub(/\s+/,'_')}.jpg", :width => "100"
111
- else
112
- img = image_tag "/plugin_assets/hydra-head/images/default_thumbnail.gif", :width=>"100", :alt=>"#{item.value}"
113
- end
114
-
115
- link_to_unless(options[:suppress_link], img, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select")
116
- end
117
-
118
- def get_randomized_display_items items
119
- clean_items = items.each.inject([]) do |array, item|
120
- array << item unless item.value.strip.blank?
121
- array
122
- end
123
-
124
- if clean_items.length < 6
125
- clean_items.sort_by {|item| item.value }
126
- else
127
- rdi = clean_items.sort_by {rand}.slice(0..5)
128
- return rdi.sort_by {|item| item.value.downcase}
129
- end
130
-
131
- end
132
-
133
- def extract_computing_id val
134
- cid = val.split(" ")[-1]
135
- cid[1..cid.length-2]
136
- end
137
-
138
- def format_item_value val
139
- begin
140
- last, f_c = val.split(", ")
141
- first = f_c.split(" (")[0]
142
- rescue
143
- return val.nil? ? "" : val
144
- end
145
- [last, "#{first[0..0]}."].join(", ")
146
- end
147
-
148
- def render_head_content
149
- render_stylesheet_includes +
150
- render_js_includes +
151
- render_extra_head_content_without_unapi +
152
- content_for(:head)
153
- end
154
-
155
- def render_extra_head_content_without_unapi
156
- remove_unapi!
157
- render_extra_head_content
158
- end
159
-
160
- # rel="unapi-server" is not HTML5 valid. Need to see if there is a way to do that properly while still validating.
161
- def remove_unapi!
162
- extra_head_content.delete_if do |ehc|
163
- ehc.include?("unapi-server")
164
- end
165
- end
166
-
167
- # COPIED from vendor/plugins/blacklight/app/helpers/application_helper.rb
168
- # Used in catalog/facet action, facets.rb view, for a click
169
- # on a facet value. Add on the facet params to existing
170
- # search constraints. Remove any paginator-specific request
171
- # params, or other request params that should be removed
172
- # for a 'fresh' display.
173
- # Change the action to 'index' to send them back to
174
- # catalog/index with their new facet choice.
175
- def add_facet_params_and_redirect(field, value)
176
- new_params = add_facet_params(field, value)
177
-
178
- # Delete page, if needed.
179
- new_params.delete(:page)
180
-
181
- # Delete :qt, if needed - added to resolve NPE errors
182
- new_params.delete(:qt)
183
-
184
- # Delete any request params from facet-specific action, needed
185
- # to redir to index action properly.
186
- Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key|
187
- new_params.delete(paginator_key)
188
- end
189
- new_params.delete(:id)
190
-
191
- # Force action to be index.
192
- new_params[:action] = "index"
193
-
194
- new_params
195
- end
196
-
2
+ include Hydra::BlacklightHelperBehavior
197
3
  end
4
+