blacklight 3.0.0 → 3.1.0

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 (30) hide show
  1. data/VERSION +1 -1
  2. data/app/helpers/blacklight_helper.rb +2 -215
  3. data/app/helpers/facets_helper.rb +114 -0
  4. data/app/helpers/html_head_helper.rb +103 -0
  5. data/app/views/catalog/_document.html.erb +0 -2
  6. data/app/views/catalog/show.html.erb +0 -1
  7. data/app/views/kaminari/blacklight/_paginator.html.erb +1 -1
  8. data/lib/blacklight.rb +1 -0
  9. data/lib/blacklight/catalog.rb +0 -22
  10. data/lib/blacklight/kaminari_relevant_pages_patch.rb +37 -0
  11. data/lib/blacklight/routes.rb +0 -1
  12. data/lib/blacklight/solr/document.rb +3 -3
  13. data/lib/blacklight/solr_helper.rb +2 -2
  14. data/lib/generators/blacklight/assets_generator.rb +1 -1
  15. data/lib/generators/blacklight/templates/config/blacklight_config.rb +7 -13
  16. data/lib/railties/blacklight_rspec.rake +3 -1
  17. data/test_support/bin/run-tests.sh +64 -0
  18. data/test_support/bin/test.sh +12 -4
  19. data/test_support/features/step_definitions/search_steps.rb +0 -4
  20. data/test_support/features/support/paths.rb +0 -9
  21. data/test_support/spec/controllers/catalog_controller_spec.rb +0 -45
  22. data/test_support/spec/helpers/blacklight_helper_spec.rb +2 -174
  23. data/test_support/spec/helpers/facets_helper_spec.rb +100 -0
  24. data/test_support/spec/helpers/html_head_helper_spec.rb +90 -0
  25. data/test_support/spec/helpers/solr_helper_spec.rb +1 -1
  26. metadata +85 -120
  27. data/app/views/catalog/_unapi_microformat.html.erb +0 -1
  28. data/app/views/catalog/unapi.xml.builder +0 -6
  29. data/test_support/features/unapi.feature +0 -30
  30. data/test_support/spec/views/catalog/unapi.xml.builder_spec.rb +0 -46
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.0
@@ -6,111 +6,14 @@
6
6
  module BlacklightHelper
7
7
  include HashAsHiddenFields
8
8
  include RenderConstraintsHelper
9
+ include HtmlHeadHelper
10
+ include FacetsHelper
9
11
 
10
12
 
11
13
  def application_name
12
14
  'Blacklight'
13
15
  end
14
16
 
15
- ##
16
- # This method should be included in any Blacklight layout, including
17
- # custom ones. It will output results of #render_js_includes,
18
- # #render_stylesheet_includes, and all the content of
19
- # current_controller#extra_head_content.
20
- #
21
- # Uses controller methods #extra_head_content, #javascript_includes,
22
- # and #stylesheet_links to find content. Tolerates it if those
23
- # methods don't exist, silently skipping.
24
- #
25
- # By a layout outputting this in html HEAD, it provides an easy way for
26
- # local config or extra plugins to add HEAD content.
27
- #
28
- # Add your own css or remove the defaults by simply editing
29
- # controller.stylesheet_links, controller.javascript_includes,
30
- # or controller.extra_head_content.
31
- #
32
- #
33
- #
34
- # in an initializer or other startup file (plugin init.rb?):
35
- #
36
- # == Apply to all actions in all controllers:
37
- #
38
- # ApplicationController.before_filter do |controller|
39
- # # remove default jquery-ui theme.
40
- # controller.stylesheet_links.each do |args|
41
- # args.delete_if {|a| a =~ /^|\/jquery-ui-[\d.]+\.custom\.css$/ }
42
- # end
43
- #
44
- # # add in a different jquery-ui theme, or any other css or what have you
45
- # controller.stylesheet_links << 'my_css.css'
46
- #
47
- # controller.javascript_includes << "my_local_behaviors.js"
48
- #
49
- # controller.extra_head_content << '<link rel="something" href="something">'
50
- # end
51
- #
52
- # == Apply to a particular action in a particular controller:
53
- #
54
- # CatalogController.before_filter :only => :show |controller|
55
- # controller.extra_head_content << '<link rel="something" href="something">'
56
- # end
57
- #
58
- # == Or in a view file that wants to add certain header content? no problem:
59
- #
60
- # <% stylesheet_links << "mystylesheet.css" %>
61
- # <% javascript_includes << "my_js.js" %>
62
- # <% extra_head_content << capture do %>
63
- # <%= tag :link, { :href => some_method_for_something, :rel => "alternate" } %>
64
- # <% end %>
65
- #
66
- # == Full power of javascript_include_tag and stylesheet_link_tag
67
- # Note that the elements added to stylesheet_links and javascript_links
68
- # are arguments to Rails javascript_include_tag and stylesheet_link_tag
69
- # respectively, you can pass complex arguments. eg:
70
- #
71
- # stylesheet_links << ["stylesheet1.css", "stylesheet2.css", {:cache => "mykey"}]
72
- # javascript_includes << ["myjavascript.js", {:plugin => :myplugin} ]
73
- def render_head_content
74
- render_stylesheet_includes +
75
- render_js_includes +
76
- render_extra_head_content
77
- end
78
-
79
- ##
80
- # Assumes controller has a #stylesheet_link_tag method, array with
81
- # each element being a set of arguments for stylesheet_link_tag
82
- # See #render_head_content for instructions on local code or plugins
83
- # adding stylesheets.
84
- def render_stylesheet_includes
85
- return "".html_safe unless respond_to?(:stylesheet_links)
86
-
87
- stylesheet_links.uniq.collect do |args|
88
- stylesheet_link_tag(*args)
89
- end.join("\n").html_safe
90
- end
91
-
92
-
93
- ##
94
- # Assumes controller has a #js_includes method, array with each
95
- # element being a set of arguments for javsascript_include_tag.
96
- # See #render_head_content for instructions on local code or plugins
97
- # adding js files.
98
- def render_js_includes
99
- return "".html_safe unless respond_to?(:javascript_includes)
100
-
101
- javascript_includes.uniq.collect do |args|
102
- javascript_include_tag(*args)
103
- end.join("\n").html_safe
104
- end
105
-
106
- ##
107
- # Assumes controller has a #extra_head_content method
108
- #
109
- def render_extra_head_content
110
- return "".html_safe unless respond_to?(:extra_head_content)
111
-
112
- extra_head_content.join("\n").html_safe
113
- end
114
17
 
115
18
  # Create <link rel="alternate"> links from a documents dynamically
116
19
  # provided export formats. Currently not used by standard BL layouts,
@@ -158,27 +61,6 @@ module BlacklightHelper
158
61
  @extra_body_classes ||= ['blacklight-' + controller.controller_name, 'blacklight-' + [controller.controller_name, controller.action_name].join('-')]
159
62
  end
160
63
 
161
- #
162
- # Blacklight.config based helpers ->
163
- #
164
-
165
- # used in the catalog/_facets partial
166
- def facet_field_labels
167
- Blacklight.config[:facet][:labels]
168
- end
169
-
170
- # used in the catalog/_facets partial
171
- def facet_field_names
172
- Blacklight.config[:facet][:field_names]
173
- end
174
-
175
- # used in the catalog/_facets partial and elsewhere
176
- # Renders a single section for facet limit with a specified
177
- # solr field used for faceting. Can be over-ridden for custom
178
- # display on a per-facet basis.
179
- def render_facet_limit(solr_field)
180
- render( :partial => "catalog/facet_limit", :locals => {:solr_field =>solr_field })
181
- end
182
64
 
183
65
  def render_document_list_partial options={}
184
66
  render :partial=>'catalog/document_list'
@@ -322,96 +204,6 @@ module BlacklightHelper
322
204
  link_to(raw(render_search_to_s(params)), catalog_index_path(params)).html_safe
323
205
  end
324
206
 
325
- #
326
- # facet param helpers ->
327
- #
328
-
329
- # Standard display of a facet value in a list. Used in both _facets sidebar
330
- # partial and catalog/facet expanded list. Will output facet value name as
331
- # a link to add that to your restrictions, with count in parens.
332
- # first arg item is a facet value item from rsolr-ext.
333
- # options consist of:
334
- # :suppress_link => true # do not make it a link, used for an already selected value for instance
335
- def render_facet_value(facet_solr_field, item, options ={})
336
- (link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits)).html_safe
337
- end
338
-
339
- # Standard display of a SELECTED facet value, no link, special span
340
- # with class, and 'remove' button.
341
- def render_selected_facet_value(facet_solr_field, item)
342
- content_tag(:span, render_facet_value(facet_solr_field, item, :suppress_link => true), :class => "selected label") +
343
- link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove")
344
- end
345
-
346
- # Renders a count value for facet limits. Can be over-ridden locally
347
- # to change style, for instance not use parens. And can be called
348
- # by plugins to get consistent display.
349
- def render_facet_count(num)
350
- content_tag("span", "(" + format_num(num) + ")", :class => "count")
351
- end
352
-
353
- # adds the value and/or field to params[:f]
354
- # Does NOT remove request keys and otherwise ensure that the hash
355
- # is suitable for a redirect. See
356
- # add_facet_params_and_redirect
357
- def add_facet_params(field, value)
358
- p = params.dup
359
- p[:f] = (p[:f] || {}).dup # the command above is not deep in rails3, !@#$!@#$
360
- p[:f][field] = (p[:f][field] || []).dup
361
- p[:f][field].push(value)
362
- p
363
- end
364
-
365
- # Used in catalog/facet action, facets.rb view, for a click
366
- # on a facet value. Add on the facet params to existing
367
- # search constraints. Remove any paginator-specific request
368
- # params, or other request params that should be removed
369
- # for a 'fresh' display.
370
- # Change the action to 'index' to send them back to
371
- # catalog/index with their new facet choice.
372
- def add_facet_params_and_redirect(field, value)
373
- new_params = add_facet_params(field, value)
374
-
375
- # Delete page, if needed.
376
- new_params.delete(:page)
377
-
378
- # Delete any request params from facet-specific action, needed
379
- # to redir to index action properly.
380
- Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key|
381
- new_params.delete(paginator_key)
382
- end
383
- new_params.delete(:id)
384
-
385
- # Force action to be index.
386
- new_params[:action] = "index"
387
- new_params
388
- end
389
- # copies the current params (or whatever is passed in as the 3rd arg)
390
- # removes the field value from params[:f]
391
- # removes the field if there are no more values in params[:f][field]
392
- # removes additional params (page, id, etc..)
393
- def remove_facet_params(field, value, source_params=params)
394
- p = source_params.dup
395
- # need to dup the facet values too,
396
- # if the values aren't dup'd, then the values
397
- # from the session will get remove in the show view...
398
- p[:f] = p[:f].dup
399
- p[:f][field] = p[:f][field].nil? ? [] : p[:f][field].dup
400
- p.delete :page
401
- p.delete :id
402
- p.delete :counter
403
- p.delete :commit
404
- #return p unless p[field]
405
- p[:f][field] = p[:f][field] - [value]
406
- p[:f].delete(field) if p[:f][field].size == 0
407
- p
408
- end
409
-
410
- # true or false, depending on whether the field and value is in params[:f]
411
- def facet_in_params?(field, value)
412
- params[:f] and params[:f][field] and params[:f][field].include?(value)
413
- end
414
-
415
207
  #
416
208
  # shortcut for built-in Rails helper, "number_with_delimiter"
417
209
  #
@@ -602,9 +394,4 @@ module BlacklightHelper
602
394
  val
603
395
  end
604
396
 
605
-
606
- def render_document_unapi_microformat(document, options={})
607
- render(:partial=>'catalog/unapi_microformat', :locals => {:document=> document}.merge(options))
608
- end
609
-
610
397
  end
@@ -0,0 +1,114 @@
1
+ module FacetsHelper
2
+
3
+ #
4
+ # Blacklight.config based helpers ->
5
+ #
6
+
7
+ # used in the catalog/_facets partial
8
+ def facet_field_labels
9
+ Blacklight.config[:facet][:labels]
10
+ end
11
+
12
+ # used in the catalog/_facets partial
13
+ def facet_field_names
14
+ Blacklight.config[:facet][:field_names]
15
+ end
16
+
17
+ # used in the catalog/_facets partial and elsewhere
18
+ # Renders a single section for facet limit with a specified
19
+ # solr field used for faceting. Can be over-ridden for custom
20
+ # display on a per-facet basis.
21
+ def render_facet_limit(solr_field)
22
+ render( :partial => "catalog/facet_limit", :locals => {:solr_field =>solr_field })
23
+ end
24
+
25
+ #
26
+ # facet param helpers ->
27
+ #
28
+
29
+ # Standard display of a facet value in a list. Used in both _facets sidebar
30
+ # partial and catalog/facet expanded list. Will output facet value name as
31
+ # a link to add that to your restrictions, with count in parens.
32
+ # first arg item is a facet value item from rsolr-ext.
33
+ # options consist of:
34
+ # :suppress_link => true # do not make it a link, used for an already selected value for instance
35
+ def render_facet_value(facet_solr_field, item, options ={})
36
+ (link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits)).html_safe
37
+ end
38
+
39
+ # Standard display of a SELECTED facet value, no link, special span
40
+ # with class, and 'remove' button.
41
+ def render_selected_facet_value(facet_solr_field, item)
42
+ content_tag(:span, render_facet_value(facet_solr_field, item, :suppress_link => true), :class => "selected label") +
43
+ link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove")
44
+ end
45
+
46
+ # Renders a count value for facet limits. Can be over-ridden locally
47
+ # to change style, for instance not use parens. And can be called
48
+ # by plugins to get consistent display.
49
+ def render_facet_count(num)
50
+ content_tag("span", "(" + format_num(num) + ")", :class => "count")
51
+ end
52
+
53
+ # adds the value and/or field to params[:f]
54
+ # Does NOT remove request keys and otherwise ensure that the hash
55
+ # is suitable for a redirect. See
56
+ # add_facet_params_and_redirect
57
+ def add_facet_params(field, value)
58
+ p = params.dup
59
+ p[:f] = (p[:f] || {}).dup # the command above is not deep in rails3, !@#$!@#$
60
+ p[:f][field] = (p[:f][field] || []).dup
61
+ p[:f][field].push(value)
62
+ p
63
+ end
64
+
65
+ # Used in catalog/facet action, facets.rb view, for a click
66
+ # on a facet value. Add on the facet params to existing
67
+ # search constraints. Remove any paginator-specific request
68
+ # params, or other request params that should be removed
69
+ # for a 'fresh' display.
70
+ # Change the action to 'index' to send them back to
71
+ # catalog/index with their new facet choice.
72
+ def add_facet_params_and_redirect(field, value)
73
+ new_params = add_facet_params(field, value)
74
+
75
+ # Delete page, if needed.
76
+ new_params.delete(:page)
77
+
78
+ # Delete any request params from facet-specific action, needed
79
+ # to redir to index action properly.
80
+ Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key|
81
+ new_params.delete(paginator_key)
82
+ end
83
+ new_params.delete(:id)
84
+
85
+ # Force action to be index.
86
+ new_params[:action] = "index"
87
+ new_params
88
+ end
89
+ # copies the current params (or whatever is passed in as the 3rd arg)
90
+ # removes the field value from params[:f]
91
+ # removes the field if there are no more values in params[:f][field]
92
+ # removes additional params (page, id, etc..)
93
+ def remove_facet_params(field, value, source_params=params)
94
+ p = source_params.dup
95
+ # need to dup the facet values too,
96
+ # if the values aren't dup'd, then the values
97
+ # from the session will get remove in the show view...
98
+ p[:f] = (p[:f] || {}).dup
99
+ p[:f][field] = (p[:f][field] || []).dup
100
+ p.delete :page
101
+ p.delete :id
102
+ p.delete :counter
103
+ p.delete :commit
104
+ p[:f][field] = p[:f][field] - [value]
105
+ p[:f].delete(field) if p[:f][field].size == 0
106
+ p
107
+ end
108
+
109
+ # true or false, depending on whether the field and value is in params[:f]
110
+ def facet_in_params?(field, value)
111
+ params[:f] and params[:f][field] and params[:f][field].include?(value)
112
+ end
113
+
114
+ end
@@ -0,0 +1,103 @@
1
+ module HtmlHeadHelper
2
+ ##
3
+ # This method should be included in any Blacklight layout, including
4
+ # custom ones. It will output results of #render_js_includes,
5
+ # #render_stylesheet_includes, all the content of
6
+ # current_controller#extra_head_content as well as any content passed
7
+ # in any content_for(:head) blocks.
8
+ #
9
+ # Uses controller methods #extra_head_content, #javascript_includes,
10
+ # and #stylesheet_links to find content. Tolerates it if those
11
+ # methods don't exist, silently skipping.
12
+ #
13
+ # By a layout outputting this in html HEAD, it provides an easy way for
14
+ # local config or extra plugins to add HEAD content.
15
+ #
16
+ # Add your own css or remove the defaults by simply editing
17
+ # controller.stylesheet_links, controller.javascript_includes,
18
+ # or controller.extra_head_content.
19
+ #
20
+ #
21
+ #
22
+ # in an initializer or other startup file (plugin init.rb?):
23
+ #
24
+ # == Apply to all actions in all controllers:
25
+ #
26
+ # ApplicationController.before_filter do |controller|
27
+ # # remove default jquery-ui theme.
28
+ # controller.stylesheet_links.each do |args|
29
+ # args.delete_if {|a| a =~ /^|\/jquery-ui-[\d.]+\.custom\.css$/ }
30
+ # end
31
+ #
32
+ # # add in a different jquery-ui theme, or any other css or what have you
33
+ # controller.stylesheet_links << 'my_css.css'
34
+ #
35
+ # controller.javascript_includes << "my_local_behaviors.js"
36
+ #
37
+ # controller.extra_head_content << '<link rel="something" href="something">'
38
+ # end
39
+ #
40
+ # == Apply to a particular action in a particular controller:
41
+ #
42
+ # CatalogController.before_filter :only => :show |controller|
43
+ # controller.extra_head_content << '<link rel="something" href="something">'
44
+ # end
45
+ #
46
+ # == Or in a view file that wants to add certain header content? no problem:
47
+ #
48
+ # <% stylesheet_links << "mystylesheet.css" %>
49
+ # <% javascript_includes << "my_js.js" %>
50
+ # <% extra_head_content << capture do %>
51
+ # <%= tag :link, { :href => some_method_for_something, :rel => "alternate" } %>
52
+ # <% end %>
53
+ #
54
+ # == Full power of javascript_include_tag and stylesheet_link_tag
55
+ # Note that the elements added to stylesheet_links and javascript_links
56
+ # are arguments to Rails javascript_include_tag and stylesheet_link_tag
57
+ # respectively, you can pass complex arguments. eg:
58
+ #
59
+ # stylesheet_links << ["stylesheet1.css", "stylesheet2.css", {:cache => "mykey"}]
60
+ # javascript_includes << ["myjavascript.js", {:plugin => :myplugin} ]
61
+ def render_head_content
62
+ render_stylesheet_includes +
63
+ render_js_includes +
64
+ render_extra_head_content +
65
+ content_for(:head)
66
+ end
67
+
68
+ ##
69
+ # Assumes controller has a #stylesheet_link_tag method, array with
70
+ # each element being a set of arguments for stylesheet_link_tag
71
+ # See #render_head_content for instructions on local code or plugins
72
+ # adding stylesheets.
73
+ def render_stylesheet_includes
74
+ return "".html_safe unless respond_to?(:stylesheet_links)
75
+
76
+ stylesheet_links.uniq.collect do |args|
77
+ stylesheet_link_tag(*args)
78
+ end.join("\n").html_safe
79
+ end
80
+
81
+
82
+ ##
83
+ # Assumes controller has a #js_includes method, array with each
84
+ # element being a set of arguments for javsascript_include_tag.
85
+ # See #render_head_content for instructions on local code or plugins
86
+ # adding js files.
87
+ def render_js_includes
88
+ return "".html_safe unless respond_to?(:javascript_includes)
89
+
90
+ javascript_includes.uniq.collect do |args|
91
+ javascript_include_tag(*args)
92
+ end.join("\n").html_safe
93
+ end
94
+
95
+ ##
96
+ # Assumes controller has a #extra_head_content method
97
+ #
98
+ def render_extra_head_content
99
+ return "".html_safe unless respond_to?(:extra_head_content)
100
+
101
+ extra_head_content.join("\n").html_safe
102
+ end
103
+ end