Skip to content

Commit 6825172

Browse files
committed
Merge pull request #673 from projectblacklight/4.x-deprecations
4.x deprecations and backports from 5.x
2 parents a4f1468 + da9540b commit 6825172

31 files changed

+272
-101
lines changed

app/assets/javascripts/blacklight/blacklight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@
6060
};
6161
*/
6262

63-
$('.no-js').removeClass('no-js')
63+
$('.no-js').removeClass('no-js').addClass('js');

app/helpers/blacklight/blacklight_helper_behavior.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Methods added to this helper will be available to all templates in the hosting application
55
#
66
module Blacklight::BlacklightHelperBehavior
7+
8+
extend Deprecation
9+
self.deprecation_horizon = 'Blacklight 5.x'
10+
711
include HashAsHiddenFieldsHelper
812
include RenderConstraintsHelper
913
include HtmlHeadHelper
@@ -61,14 +65,15 @@ def render_body_class
6165
# collection of items to be rendered in the @sidebar
6266
# @deprecated
6367
def sidebar_items
64-
ActiveSupport::Deprecation.warn("#sidebar_items helper is deprecated, and should be replaced by overriding the appropriate partial")
6568
@sidebar_items ||= []
6669
end
70+
deprecation_deprecate :sidebar_items
6771

6872
# collection of items to be rendered in the @topbar
6973
def topbar_items
7074
@topbar_items ||= []
7175
end
76+
deprecation_deprecate :topbar_items
7277

7378
def render_search_bar
7479
render :partial=>'catalog/search_form'
@@ -121,6 +126,7 @@ def should_render_index_field? document, solr_field
121126
# Field keys for the index fields
122127
# @deprecated
123128
def index_field_names document=nil
129+
Deprecation.warn(self, "#index_field_names helper is deprecated, and should be replaced by overriding the appropriate partial")
124130
index_fields(document).keys
125131
end
126132

@@ -129,6 +135,8 @@ def index_field_names document=nil
129135
# @deprecated
130136
def index_field_labels document=nil
131137
# XXX DEPRECATED
138+
Deprecation.warn(self, "#index_field_labels helper is deprecated, and should be replaced by overriding the appropriate partial")
139+
132140
Hash[*index_fields(document).map { |key, field| [key, field.label] }.flatten]
133141
end
134142

@@ -255,6 +263,8 @@ def document_show_fields document=nil
255263
# @deprecated
256264
def document_show_field_labels document=nil
257265
# XXX DEPRECATED
266+
Deprecation.warn(self, "#document_show_field_labels helper is deprecated, and should be replaced by overriding the appropriate partial")
267+
258268
Hash[*document_show_fields(document).map { |key, field| [key, field.label] }.flatten]
259269
end
260270

@@ -609,8 +619,8 @@ def render_endnote_texts(documents)
609619
##
610620
# Should we render a grouped response (because the response
611621
# contains a grouped response instead of the normal response)
612-
def render_grouped_response?
613-
return @response.grouped?
622+
def render_grouped_response? response = @response
623+
return response.grouped?
614624
end
615625

616626
##

app/helpers/blacklight/catalog_helper_behavior.rb

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# -*- encoding : utf-8 -*-
22
module Blacklight::CatalogHelperBehavior
33

4+
extend Deprecation
5+
self.deprecation_horizon = 'Blacklight 5.x'
6+
47
# Pass in an RSolr::Response (or duck-typed similar) object,
58
# it translates to a Kaminari-paginatable
69
# object, with the keys Kaminari views expect.
@@ -25,11 +28,7 @@ def format_num(num); number_with_delimiter(num) end
2528
#
2629
# Pass in an RSolr::Response. Displays the "showing X through Y of N" message.
2730
def render_pagination_info(response, options = {})
28-
# TODO: i18n the entry_name
29-
entry_name = options[:entry_name]
30-
entry_name ||= response.docs.first.class.name.underscore.sub('_', ' ') unless response.docs.empty?
31-
entry_name ||= t('blacklight.entry_name.default')
32-
31+
entry_name = options[:entry_name] || t('blacklight.entry_name.default')
3332

3433
end_num = if render_grouped_response?
3534
format_num(response.start + response.groups.length)
@@ -43,14 +42,56 @@ def render_pagination_info(response, options = {})
4342
else; t('blacklight.search.pagination_info.pages', :entry_name => entry_name.pluralize, :current_page => response.current_page, :num_pages => response.total_pages, :start_num => format_num(response.start + 1) , :end_num => end_num, :total_num => response.total_count, :count => response.total_pages).html_safe
4443
end
4544
end
45+
deprecation_deprecate :render_pagination_info
46+
47+
# Override the Kaminari page_entries_info helper with our own, blacklight-aware
48+
# implementation
49+
#
50+
# Pass in an RSolr::Response. Displays the "showing X through Y of N" message.
51+
52+
def page_entries_info(collection, options = {})
53+
entry_name = if options[:entry_name]
54+
options[:entry_name]
55+
elsif collection.respond_to? :model # DataMapper
56+
collection.model.model_name.humanize.downcase
57+
elsif collection.respond_to? :model_name and !collection.model_name.nil? # AR, Blacklight::PaginationMethods
58+
collection.model_name.humanize.downcase
59+
elsif collection.is_a?(::Kaminari::PaginatableArray)
60+
'entry'
61+
else
62+
t('blacklight.entry_name.default')
63+
end
64+
65+
entry_name = entry_name.pluralize unless collection.total_count == 1
66+
67+
# grouped response objects need special handling
68+
end_num = if collection.respond_to? :groups and render_grouped_response? collection
69+
collection.groups.length
70+
else
71+
collection.limit_value
72+
end
73+
74+
end_num = if collection.offset_value + end_num <= collection.total_count
75+
format_num(collection.offset_value + end_num)
76+
else
77+
format_num(collection.total_count)
78+
end
79+
80+
case collection.total_count
81+
when 0; t('blacklight.search.pagination_info.no_items_found', :entry_name => entry_name ).html_safe
82+
when 1; t('blacklight.search.pagination_info.single_item_found', :entry_name => entry_name).html_safe
83+
else; t('blacklight.search.pagination_info.pages', :entry_name => entry_name, :current_page => collection.current_page, :num_pages => collection.total_pages, :start_num => format_num(collection.offset_value + 1) , :end_num => end_num, :total_num => collection.total_count, :count => collection.total_pages).html_safe
84+
end
85+
end
86+
4687

4788
def document_counter_with_offset idx
4889
unless render_grouped_response?
4990
idx + 1 + @response.params[:start].to_i
5091
end
5192
end
5293

53-
# Like #render_pagination_info above, but for an individual
94+
# Like #page_entries_info above, but for an individual
5495
# item show page. Displays "showing X of Y items" message. Actually takes
5596
# data from session though (not a great design).
5697
# Code should call this method rather than interrogating session directly,

app/helpers/blacklight/facets_helper_behavior.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module Blacklight::FacetsHelperBehavior
22

3+
extend Deprecation
4+
self.deprecation_horizon = 'Blacklight 5.x'
5+
6+
37
include Blacklight::Facet
48

59
# used in the catalog/_facets partial
@@ -31,7 +35,7 @@ def render_facet_partials fields = facet_field_names, options = {}
3135
#
3236
def render_facet_limit(display_facet, options = {})
3337
if display_facet.is_a? String or display_facet.is_a? Symbol
34-
$stderr.puts "DEPRECATION WARNING: Blacklight::FacetsHelper#render_facet_limit: use #render_facet_partials to render facets by field name"
38+
Deprecation.warn(self, "Blacklight::FacetsHelper#render_facet_limit: use #render_facet_partials to render facets by field name")
3539
return render_facet_partials([display_facet])
3640
end
3741
return if not should_render_facet?(display_facet)

app/helpers/blacklight/html_head_helper_behavior.rb

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module Blacklight::HtmlHeadHelperBehavior
2+
extend Deprecation
3+
self.deprecation_horizon = 'Blacklight 5.x'
4+
25
##
36
# This method should be included in any Blacklight layout, including
47
# custom ones. It will output results of #render_js_includes,
@@ -59,24 +62,30 @@ module Blacklight::HtmlHeadHelperBehavior
5962
# stylesheet_links << ["stylesheet1.css", "stylesheet2.css", {:cache => "mykey"}]
6063
# javascript_includes << ["myjavascript.js", {:plugin => :myplugin} ]
6164
def render_head_content
62-
render_stylesheet_includes +
63-
render_js_includes +
64-
render_extra_head_content +
65+
Deprecation.silence(Blacklight::HtmlHeadHelperBehavior) do
66+
render_stylesheet_includes +
67+
render_js_includes +
68+
render_extra_head_content
69+
end +
6570
content_for(:head)
6671
end
6772

73+
deprecation_deprecate :render_head_content
74+
6875
##
6976
# Assumes controller has a #stylesheet_link_tag method, array with
7077
# each element being a set of arguments for stylesheet_link_tag
7178
# See #render_head_content for instructions on local code or plugins
7279
# adding stylesheets.
7380
def render_stylesheet_includes
7481
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
82+
Deprecation.silence(Blacklight::LegacyControllerMethods) do
83+
stylesheet_links.uniq.collect do |args|
84+
stylesheet_link_tag(*args)
85+
end.join("\n").html_safe
86+
end
7987
end
88+
deprecation_deprecate :render_stylesheet_includes
8089

8190

8291
##
@@ -85,19 +94,25 @@ def render_stylesheet_includes
8594
# See #render_head_content for instructions on local code or plugins
8695
# adding js files.
8796
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
97+
return "".html_safe unless respond_to?(:javascript_includes)
98+
99+
Deprecation.silence(Blacklight::LegacyControllerMethods) do
100+
javascript_includes.uniq.collect do |args|
101+
javascript_include_tag(*args)
102+
end.join("\n").html_safe
103+
end
93104
end
105+
deprecation_deprecate :render_js_includes
94106

95107
##
96108
# Assumes controller has a #extra_head_content method
97109
#
98110
def render_extra_head_content
99111
return "".html_safe unless respond_to?(:extra_head_content)
100112

101-
extra_head_content.join("\n").html_safe
113+
Deprecation.silence(Blacklight::LegacyControllerMethods) do
114+
extra_head_content.join("\n").html_safe
115+
end
102116
end
117+
deprecation_deprecate :render_extra_head_content
103118
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<% if @response.total_pages > 1 %>
22
<%= paginate @response, :theme => :blacklight_compact %>
33
<% else %>
4-
<%= render_pagination_info(@response) %>
4+
<%= page_entries_info(@response) %>
55
<% end %>

app/views/catalog/facet.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
<% Deprecation.silence(Blacklight::BlacklightHelperBehavior) do -%>
12
<% sidebar_items << capture do %>
23
<p><%= link_back_to_catalog %></p>
34
<% end %>
5+
<% end %>
46

57
<div class="facet_pagination top">
68
<%= render :partial=>'facet_pagination' %>

app/views/catalog/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<% @page_title = t('blacklight.search.title', :application_name => application_name) %>
1515

1616

17-
<% extra_head_content << render_opensearch_response_metadata.html_safe %>
17+
<% Deprecation.silence(Blacklight::LegacyControllerMethods) { extra_head_content << render_opensearch_response_metadata.html_safe } %>
1818

1919
<%= render 'search_header' %>
2020

app/views/catalog/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
<% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name) %>
7-
<% extra_head_content << render_link_rel_alternates %>
7+
<% Deprecation.silence(Blacklight::LegacyControllerMethods) { extra_head_content << render_link_rel_alternates } %>
88

99
<%# this should be in a partial -%>
1010
<div id="document" class="<%= render_document_class %>">

app/views/kaminari/blacklight_compact/_paginator.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
Paginator now using the Bootstrap paginator class
1010
-%>
11-
<%- pagination_info_cache = render_pagination_info @response %>
11+
<%- pagination_info_cache = page_entries_info @response %>
1212

1313
<%= paginator.render do -%>
1414
<%= prev_page_tag %> | <%= pagination_info_cache %> | <%= next_page_tag %>

0 commit comments

Comments
 (0)