blacklight 5.7.2 → 5.8.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -3
- data/Gemfile +1 -4
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +38 -1
- data/app/assets/stylesheets/blacklight/_facets.css.scss +10 -0
- data/app/assets/stylesheets/blacklight/_layout.css.scss +6 -0
- data/app/controllers/bookmarks_controller.rb +3 -163
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +18 -186
- data/app/helpers/blacklight/catalog_helper_behavior.rb +36 -2
- data/app/helpers/blacklight/component_helper_behavior.rb +77 -0
- data/app/helpers/blacklight/configuration_helper_behavior.rb +30 -21
- data/app/helpers/blacklight/render_partials_helper.rb +185 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +24 -3
- data/app/helpers/component_helper.rb +3 -0
- data/app/views/_user_util_links.html.erb +2 -15
- data/app/views/blacklight/nav/_bookmark.html.erb +4 -0
- data/app/views/blacklight/nav/_saved_searches.html.erb +1 -0
- data/app/views/blacklight/nav/_search_history.html.erb +1 -0
- data/app/views/bookmarks/_tools.html.erb +6 -9
- data/app/views/bookmarks/index.html.erb +1 -1
- data/app/views/catalog/_bookmark_control.html.erb +8 -8
- data/app/views/catalog/_constraints_element.html.erb +1 -1
- data/app/views/catalog/_document_action.html.erb +4 -0
- data/app/views/catalog/_email_form.html.erb +1 -1
- data/app/views/catalog/_facet_limit.html.erb +1 -1
- data/app/views/catalog/_index_header_default.html.erb +5 -6
- data/app/views/catalog/_per_page_widget.html.erb +3 -1
- data/app/views/catalog/_results_pagination.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +5 -8
- data/app/views/catalog/_show_more_like_this.html.erb +2 -2
- data/app/views/catalog/_show_tools.html.erb +5 -34
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/catalog/_sort_and_per_page.html.erb +2 -6
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/app/views/catalog/_zero_results.html.erb +2 -2
- data/app/views/catalog/citation.js.erb +1 -1
- data/app/views/catalog/email_sent.html.erb +2 -9
- data/app/views/catalog/email_success.html.erb +9 -0
- data/app/views/catalog/sms_sent.html.erb +2 -9
- data/app/views/catalog/sms_success.html.erb +9 -0
- data/app/views/kaminari/blacklight/_gap.html.erb +1 -1
- data/app/views/kaminari/blacklight/_page.html.erb +5 -1
- data/app/views/shared/_header_navbar.html.erb +1 -1
- data/config/locales/blacklight.en.yml +1 -1
- data/config/locales/blacklight.es.yml +1 -1
- data/config/locales/blacklight.fr.yml +1 -1
- data/config/locales/blacklight.pt-BR.yml +1 -1
- data/lib/blacklight.rb +3 -0
- data/lib/blacklight/base.rb +0 -1
- data/lib/blacklight/bookmarks.rb +135 -0
- data/lib/blacklight/catalog.rb +58 -77
- data/lib/blacklight/catalog/component_configuration.rb +99 -0
- data/lib/blacklight/configuration.rb +82 -4
- data/lib/blacklight/configuration/tool_config.rb +4 -0
- data/lib/blacklight/controller.rb +5 -1
- data/lib/blacklight/document_presenter.rb +17 -8
- data/lib/blacklight/request_builders.rb +136 -4
- data/lib/blacklight/routes.rb +5 -0
- data/lib/blacklight/solr_helper.rb +90 -208
- data/lib/blacklight/solr_repository.rb +69 -0
- data/lib/blacklight/token_based_user.rb +58 -0
- data/lib/blacklight/utils.rb +13 -1
- data/lib/generators/blacklight/install_generator.rb +6 -7
- data/spec/controllers/alternate_controller_spec.rb +19 -0
- data/spec/controllers/catalog_controller_spec.rb +89 -4
- data/spec/features/alternate_controller_spec.rb +0 -1
- data/spec/features/bookmarks_spec.rb +31 -6
- data/spec/features/search_results_spec.rb +11 -0
- data/spec/features/search_spec.rb +5 -0
- data/spec/helpers/blacklight_helper_spec.rb +49 -8
- data/spec/helpers/catalog_helper_spec.rb +56 -8
- data/spec/helpers/configuration_helper_spec.rb +5 -5
- data/spec/helpers/url_helper_spec.rb +15 -8
- data/spec/lib/blacklight/catalog/component_configuration_spec.rb +29 -0
- data/spec/lib/blacklight/configuration_spec.rb +15 -0
- data/spec/lib/blacklight/solr_helper_spec.rb +44 -104
- data/spec/lib/blacklight/solr_repository_spec.rb +113 -0
- data/spec/lib/utils_spec.rb +27 -0
- data/spec/views/_user_util_links.html.erb_spec.rb +6 -3
- data/spec/views/catalog/_show_sidebar.erb_spec.rb +8 -2
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +82 -0
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +15 -1
- data/tasks/blacklight.rake +25 -1
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e6abf19233b0973dff8cfaff353836ee5af69e6
|
4
|
+
data.tar.gz: ae4e3d469b37f1ae8f469470fb6e87e2976cb788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7244ed7c511e061c63bf949889671cbcfcfac42bafc87d98b95093dcd2d1596629be83fbec0fffe02715ebb23fbd9ac626fcd35d3fd59b06e1b488eb412cc206
|
7
|
+
data.tar.gz: a3f3d9b2ccb72941967790c380735dabceff82c4bf5eb22a885771ceeda226d60cc7ac86a81e90136decdcce537ffbdd48adc43b095b7cd956c13a559f3ebc2f
|
data/.travis.yml
CHANGED
@@ -15,9 +15,7 @@ matrix:
|
|
15
15
|
- rvm: jruby
|
16
16
|
env: "RAILS_VERSION=4.1.7 JRUBY_OPTS=\"-J-Xms512m -J-Xmx1024m\""
|
17
17
|
- rvm: 2.1.4
|
18
|
-
env: "RAILS_VERSION=4.2.0.
|
19
|
-
allow_failures:
|
20
|
-
- env: "RAILS_VERSION=4.2.0.beta4"
|
18
|
+
env: "RAILS_VERSION=4.2.0.rc1"
|
21
19
|
|
22
20
|
before_install:
|
23
21
|
- gem install bundler
|
data/Gemfile
CHANGED
@@ -22,11 +22,8 @@ if File.exists?(file)
|
|
22
22
|
else
|
23
23
|
gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
|
24
24
|
|
25
|
-
# explicitly include sass-rails to get compatible sprocket dependencies
|
26
25
|
if ENV['RAILS_VERSION'] and ENV['RAILS_VERSION'] =~ /^4.2/
|
27
|
-
gem 'sass-rails', ">= 5.0.0.beta1"
|
28
26
|
gem 'responders', "~> 2.0"
|
29
|
-
else
|
30
|
-
gem 'sass-rails'
|
31
27
|
end
|
28
|
+
gem 'sass-rails'
|
32
29
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.8.0
|
@@ -52,7 +52,25 @@ span.constraints-label {
|
|
52
52
|
{
|
53
53
|
.constraint-value {
|
54
54
|
cursor: default;
|
55
|
-
|
55
|
+
text-overflow: ellipsis;
|
56
|
+
overflow: hidden;
|
57
|
+
|
58
|
+
@media (max-width: $screen-xs-max) {
|
59
|
+
max-width: $screen-xs-min / 2;
|
60
|
+
}
|
61
|
+
|
62
|
+
@media (min-width: $screen-sm-min) and (max-width: $screen-sm-max) {
|
63
|
+
max-width: $screen-sm-min / 2;
|
64
|
+
}
|
65
|
+
|
66
|
+
@media (min-width: $screen-md-min) and (max-width: $screen-md-max) {
|
67
|
+
max-width: $screen-md-min / 2;
|
68
|
+
}
|
69
|
+
|
70
|
+
@media (min-width: $screen-lg-min) {
|
71
|
+
max-width: $screen-lg-min / 2;
|
72
|
+
}
|
73
|
+
|
56
74
|
&:hover, &:active {
|
57
75
|
background-color: $btn-default-bg;
|
58
76
|
border-color: $btn-default-border;
|
@@ -190,3 +208,22 @@ label.toggle_bookmark
|
|
190
208
|
@extend .sr-only;
|
191
209
|
}
|
192
210
|
}
|
211
|
+
|
212
|
+
#sort-dropdown .dropdown-toggle, #per_page-dropdown .dropdown-toggle {
|
213
|
+
color: $link-color;
|
214
|
+
|
215
|
+
.caret {
|
216
|
+
color: $text-color;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
.search-input-group {
|
222
|
+
width: 80%;
|
223
|
+
}
|
224
|
+
|
225
|
+
@media (max-width: $screen-sm-min) {
|
226
|
+
.search-input-group {
|
227
|
+
width: auto;
|
228
|
+
}
|
229
|
+
}
|
@@ -1,166 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
# take the Solr document ID as the :id, NOT the id of the actual Bookmark action.
|
4
|
-
class BookmarksController < CatalogController
|
2
|
+
class BookmarksController < CatalogController
|
5
3
|
|
6
|
-
|
7
|
-
# Give Bookmarks access to the CatalogController configuration
|
8
|
-
include Blacklight::Configurable
|
9
|
-
include Blacklight::SolrHelper
|
4
|
+
include Blacklight::Bookmarks
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
rescue_from Blacklight::Exceptions::ExpiredSessionToken do
|
14
|
-
head :unauthorized
|
15
|
-
end
|
16
|
-
|
17
|
-
# Blacklight uses #search_action_url to figure out the right URL for
|
18
|
-
# the global search box
|
19
|
-
def search_action_url *args
|
20
|
-
catalog_index_url *args
|
21
|
-
end
|
22
|
-
|
23
|
-
before_filter :verify_user
|
24
|
-
|
25
|
-
def index
|
26
|
-
@bookmarks = token_or_current_or_guest_user.bookmarks
|
27
|
-
bookmark_ids = @bookmarks.collect { |b| b.document_id.to_s }
|
28
|
-
|
29
|
-
@response, @document_list = get_solr_response_for_document_ids(bookmark_ids)
|
30
|
-
|
31
|
-
respond_to do |format|
|
32
|
-
format.html { }
|
33
|
-
format.rss { render :layout => false }
|
34
|
-
format.atom { render :layout => false }
|
35
|
-
format.json do
|
36
|
-
render json: render_search_results_as_json
|
37
|
-
end
|
38
|
-
|
39
|
-
additional_response_formats(format)
|
40
|
-
document_export_formats(format)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def update
|
46
|
-
create
|
47
|
-
end
|
48
|
-
|
49
|
-
# For adding a single bookmark, suggest use PUT/#update to
|
50
|
-
# /bookmarks/$docuemnt_id instead.
|
51
|
-
# But this method, accessed via POST to /bookmarks, can be used for
|
52
|
-
# creating multiple bookmarks at once, by posting with keys
|
53
|
-
# such as bookmarks[n][document_id], bookmarks[n][title].
|
54
|
-
# It can also be used for creating a single bookmark by including keys
|
55
|
-
# bookmark[title] and bookmark[document_id], but in that case #update
|
56
|
-
# is simpler.
|
57
|
-
def create
|
58
|
-
if params[:bookmarks]
|
59
|
-
@bookmarks = params[:bookmarks]
|
60
|
-
else
|
61
|
-
@bookmarks = [{ document_id: params[:id], document_type: blacklight_config.solr_document_model.to_s }]
|
62
|
-
end
|
63
|
-
|
64
|
-
current_or_guest_user.save! unless current_or_guest_user.persisted?
|
65
|
-
|
66
|
-
success = @bookmarks.all? do |bookmark|
|
67
|
-
current_or_guest_user.bookmarks.where(bookmark).exists? || current_or_guest_user.bookmarks.create(bookmark)
|
68
|
-
end
|
69
|
-
|
70
|
-
if request.xhr?
|
71
|
-
success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count }}) : render(:text => "", :status => "500")
|
72
|
-
else
|
73
|
-
if @bookmarks.length > 0 && success
|
74
|
-
flash[:notice] = I18n.t('blacklight.bookmarks.add.success', :count => @bookmarks.length)
|
75
|
-
elsif @bookmarks.length > 0
|
76
|
-
flash[:error] = I18n.t('blacklight.bookmarks.add.failure', :count => @bookmarks.length)
|
77
|
-
end
|
78
|
-
|
79
|
-
redirect_to :back
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Beware, :id is the Solr document_id, not the actual Bookmark id.
|
84
|
-
# idempotent, as DELETE is supposed to be.
|
85
|
-
def destroy
|
86
|
-
bookmark = current_or_guest_user.bookmarks.where(document_id: params[:id], document_type: blacklight_config.solr_document_model).first
|
87
|
-
|
88
|
-
success = bookmark && bookmark.delete && bookmark.destroyed?
|
89
|
-
|
90
|
-
unless request.xhr?
|
91
|
-
if success
|
92
|
-
flash[:notice] = I18n.t('blacklight.bookmarks.remove.success')
|
93
|
-
else
|
94
|
-
flash[:error] = I18n.t('blacklight.bookmarks.remove.failure')
|
95
|
-
end
|
96
|
-
redirect_to :back
|
97
|
-
else
|
98
|
-
# ajaxy request needs no redirect and should not have flash set
|
99
|
-
success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count }}) : render(:text => "", :status => "500")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def clear
|
104
|
-
if current_or_guest_user.bookmarks.clear
|
105
|
-
flash[:notice] = I18n.t('blacklight.bookmarks.clear.success')
|
106
|
-
else
|
107
|
-
flash[:error] = I18n.t('blacklight.bookmarks.clear.failure')
|
108
|
-
end
|
109
|
-
redirect_to :action => "index"
|
110
|
-
end
|
111
|
-
|
112
|
-
protected
|
113
|
-
def verify_user
|
114
|
-
unless current_or_guest_user or (action == "index" and token_or_current_or_guest_user)
|
115
|
-
flash[:notice] = I18n.t('blacklight.bookmarks.need_login') and raise Blacklight::Exceptions::AccessDenied
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def start_new_search_session?
|
120
|
-
action_name == "index"
|
121
|
-
end
|
122
|
-
|
123
|
-
# Used for #export action, with encrypted user_id.
|
124
|
-
def decrypt_user_id(encrypted_user_id)
|
125
|
-
user_id, timestamp = message_encryptor.decrypt_and_verify(encrypted_user_id)
|
126
|
-
|
127
|
-
if timestamp < 1.hour.ago
|
128
|
-
raise Blacklight::Exceptions::ExpiredSessionToken.new
|
129
|
-
end
|
130
|
-
|
131
|
-
user_id
|
132
|
-
end
|
133
|
-
|
134
|
-
# Used for #export action with encrypted user_id, available
|
135
|
-
# as a helper method for views.
|
136
|
-
def encrypt_user_id(user_id)
|
137
|
-
message_encryptor.encrypt_and_sign([user_id, Time.now])
|
138
|
-
end
|
139
|
-
helper_method :encrypt_user_id
|
140
|
-
|
141
|
-
##
|
142
|
-
# This method provides Rails 3 compatibility to our message encryptor.
|
143
|
-
# When we drop support for Rails 3, we can just use the AS::KeyGenerator
|
144
|
-
# directly instead of this helper.
|
145
|
-
def bookmarks_export_secret_token salt
|
146
|
-
OpenSSL::PKCS5.pbkdf2_hmac_sha1(Blacklight.secret_key, salt, 1000, 64)
|
147
|
-
end
|
148
|
-
|
149
|
-
def message_encryptor
|
150
|
-
derived_secret = bookmarks_export_secret_token("bookmarks session key")
|
151
|
-
ActiveSupport::MessageEncryptor.new(derived_secret)
|
152
|
-
end
|
153
|
-
|
154
|
-
def token_or_current_or_guest_user
|
155
|
-
token_user || current_or_guest_user
|
156
|
-
end
|
157
|
-
|
158
|
-
def token_user
|
159
|
-
@token_user ||= if params[:encrypted_user_id]
|
160
|
-
user_id = decrypt_user_id params[:encrypted_user_id]
|
161
|
-
User.find(user_id)
|
162
|
-
else
|
163
|
-
nil
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
6
|
+
end
|
@@ -8,7 +8,9 @@ module Blacklight::BlacklightHelperBehavior
|
|
8
8
|
include BlacklightConfigurationHelper
|
9
9
|
include HashAsHiddenFieldsHelper
|
10
10
|
include RenderConstraintsHelper
|
11
|
+
include RenderPartialsHelper
|
11
12
|
include FacetsHelper
|
13
|
+
extend Deprecation
|
12
14
|
|
13
15
|
##
|
14
16
|
# Get the name of this application, from either:
|
@@ -91,42 +93,6 @@ module Blacklight::BlacklightHelperBehavior
|
|
91
93
|
render :partial=>'catalog/search_form'
|
92
94
|
end
|
93
95
|
|
94
|
-
##
|
95
|
-
# Render "docuemnt actions" area for search results view
|
96
|
-
# (normally renders next to title in the list view)
|
97
|
-
#
|
98
|
-
# @param [SolrDocument] document
|
99
|
-
# @param [Hash] options
|
100
|
-
# @option options [String] :wrapping_class
|
101
|
-
# @return [String]
|
102
|
-
def render_index_doc_actions(document, options={})
|
103
|
-
wrapping_class = options.delete(:wrapping_class) || "index-document-functions"
|
104
|
-
|
105
|
-
content = []
|
106
|
-
content << render(:partial => 'catalog/bookmark_control', :locals => {:document=> document}.merge(options)) if render_bookmarks_control?
|
107
|
-
|
108
|
-
content_tag("div", safe_join(content, "\n"), :class=> wrapping_class)
|
109
|
-
end
|
110
|
-
|
111
|
-
##
|
112
|
-
# Render "docuemnt actions" for the item detail 'show' view.
|
113
|
-
# (this normally renders next to title)
|
114
|
-
#
|
115
|
-
# By default includes 'Bookmarks'
|
116
|
-
#
|
117
|
-
# @param [SolrDocument] document
|
118
|
-
# @param [Hash] options
|
119
|
-
# @option options [String] :wrapping_class
|
120
|
-
# @return [String]
|
121
|
-
def render_show_doc_actions(document=@document, options={})
|
122
|
-
wrapping_class = options.delete(:wrapping_class) || "documentFunctions"
|
123
|
-
|
124
|
-
content = []
|
125
|
-
content << render(:partial => 'catalog/bookmark_control', :locals => {:document=> document}.merge(options)) if render_bookmarks_control?
|
126
|
-
|
127
|
-
content_tag("div", safe_join(content, "\n"), :class=> wrapping_class)
|
128
|
-
end
|
129
|
-
|
130
96
|
##
|
131
97
|
# Determine whether to render a given field in the index view.
|
132
98
|
#
|
@@ -378,162 +344,22 @@ module Blacklight::BlacklightHelperBehavior
|
|
378
344
|
end
|
379
345
|
end
|
380
346
|
|
381
|
-
##
|
382
|
-
# Render the document index view
|
383
|
-
#
|
384
|
-
# @param [Array<SolrDocument>] list of documents to render
|
385
|
-
# @param [Hash] locals to pass to the render call
|
386
|
-
# @return [String]
|
387
|
-
def render_document_index documents = nil, locals = {}
|
388
|
-
documents ||= @document_list
|
389
|
-
render_document_index_with_view(document_index_view_type, documents, locals)
|
390
|
-
end
|
391
|
-
|
392
|
-
##
|
393
|
-
# Render the document index for a grouped response
|
394
|
-
def render_grouped_document_index
|
395
|
-
render :partial => 'catalog/group_default'
|
396
|
-
end
|
397
|
-
|
398
|
-
##
|
399
|
-
# Render the document index for the given view type with the
|
400
|
-
# list of documents.
|
401
|
-
#
|
402
|
-
# This method will interpolate the list of templates with
|
403
|
-
# the current view, and gracefully handles missing templates.
|
404
|
-
#
|
405
|
-
# @see #document_index_path_templates
|
406
|
-
#
|
407
|
-
# @param [String] view type
|
408
|
-
# @param [Array<SolrDocument>] list of documents to render
|
409
|
-
# @param [Hash] locals to pass to the render call
|
410
|
-
# @return [String]
|
411
|
-
def render_document_index_with_view view, documents, locals = {}
|
412
|
-
document_index_path_templates.each do |str|
|
413
|
-
partial = str % { index_view_type: view }
|
414
|
-
logger.debug "Looking for document index partial #{partial}"
|
415
|
-
template = lookup_context.find_all(partial, lookup_context.prefixes + [""], true, locals.keys + [:documents], {}).first
|
416
|
-
return template.render(self, locals.merge(documents: documents)) if template
|
417
|
-
end
|
418
|
-
|
419
|
-
return ""
|
420
|
-
end
|
421
|
-
|
422
|
-
##
|
423
|
-
# A list of document partial templates to attempt to render
|
424
|
-
#
|
425
|
-
# @see #render_document_index_with_view
|
426
|
-
# @return [Array<String>]
|
427
|
-
def document_index_path_templates
|
428
|
-
# first, the legacy template names for backwards compatbility
|
429
|
-
# followed by the new, inheritable style
|
430
|
-
# finally, a controller-specific path for non-catalog subclasses
|
431
|
-
@document_index_path_templates ||= ["document_%{index_view_type}", "catalog/document_%{index_view_type}", "catalog/document_list"]
|
432
|
-
end
|
433
|
-
|
434
|
-
##
|
435
|
-
# Return a normalized partial name for rendering a single document
|
436
|
-
#
|
437
|
-
# @param [SolrDocument]
|
438
|
-
# @param [Symbol] base name for the partial
|
439
|
-
# @return [String]
|
440
|
-
def document_partial_name(document, base_name = nil)
|
441
|
-
view_config = blacklight_config.view_config(:show)
|
442
|
-
|
443
|
-
display_type = if base_name and view_config.has_key? :"#{base_name}_display_type_field"
|
444
|
-
document[view_config[:"#{base_name}_display_type_field"]]
|
445
|
-
end
|
446
|
-
|
447
|
-
display_type ||= document[view_config.display_type_field]
|
448
|
-
|
449
|
-
display_type ||= 'default'
|
450
|
-
|
451
|
-
type_field_to_partial_name(document, display_type)
|
452
|
-
end
|
453
|
-
|
454
|
-
##
|
455
|
-
# Return a partial name for rendering a document
|
456
|
-
# this method can be overridden in order to transform the value
|
457
|
-
# (e.g. 'PdfBook' => 'pdf_book')
|
458
|
-
#
|
459
|
-
# @param [SolrDocument] document
|
460
|
-
# @param [String, Array] display_type a value suggestive of a partial
|
461
|
-
# @return [String] the name of the partial to render
|
462
|
-
# @example
|
463
|
-
# type_field_to_partial_name(['a book-article'])
|
464
|
-
# => 'a_book_article'
|
465
|
-
def type_field_to_partial_name(document, display_type)
|
466
|
-
# using "_" as sep. to more closely follow the views file naming conventions
|
467
|
-
# parameterize uses "-" as the default sep. which throws errors
|
468
|
-
Array(display_type).join(" ").gsub("-","_").parameterize("_")
|
469
|
-
end
|
470
|
-
|
471
|
-
##
|
472
|
-
# Return the list of partials for a given solr document
|
473
|
-
# @param [SolrDocument]
|
474
|
-
# @return [String]
|
475
|
-
def render_document_partials(doc, partials = [], locals ={})
|
476
|
-
safe_join(partials.map do |action_name|
|
477
|
-
render_document_partial(doc, action_name, locals)
|
478
|
-
end, "\n")
|
479
|
-
end
|
480
|
-
|
481
|
-
##
|
482
|
-
# Given a doc and a base name for a partial, this method will attempt to render
|
483
|
-
# an appropriate partial based on the document format and view type.
|
484
|
-
#
|
485
|
-
# If a partial that matches the document format is not found,
|
486
|
-
# render a default partial for the base name.
|
487
|
-
#
|
488
|
-
# @see #document_partial_path_templates
|
489
|
-
#
|
490
|
-
# @param [SolrDocument] doc
|
491
|
-
# @param [String] base name for the partial
|
492
|
-
# @param [Hash] locales to pass through to the partials
|
493
|
-
def render_document_partial(doc, base_name, locals = {})
|
494
|
-
format = if method(:document_partial_name).arity == 1
|
495
|
-
Deprecation.warn self, "The #document_partial_name with a single argument is deprecated. Update your override to include a second argument for the 'base name'"
|
496
|
-
document_partial_name(doc)
|
497
|
-
else
|
498
|
-
document_partial_name(doc, base_name)
|
499
|
-
end
|
500
|
-
|
501
|
-
document_partial_path_templates.each do |str|
|
502
|
-
partial = str % { action_name: base_name, format: format, index_view_type: document_index_view_type }
|
503
|
-
logger.debug "Looking for document partial #{partial}"
|
504
|
-
template = lookup_context.find_all(partial, lookup_context.prefixes + [""], true, locals.keys + [:document], {}).first
|
505
|
-
return template.render(self, locals.merge(document: doc)) if template
|
506
|
-
end
|
507
|
-
|
508
|
-
return ''
|
509
|
-
end
|
510
|
-
|
511
|
-
##
|
512
|
-
# A list of document partial templates to try to render for a document
|
513
|
-
#
|
514
|
-
# The partial names will be interpolated with the following variables:
|
515
|
-
# - action_name: (e.g. index, show)
|
516
|
-
# - index_view_type: (the current view type, e.g. list, gallery)
|
517
|
-
# - format: the document's format (e.g. book)
|
518
|
-
#
|
519
|
-
# @see #render_document_partial
|
520
|
-
def document_partial_path_templates
|
521
|
-
# first, the legacy template names for backwards compatbility
|
522
|
-
# followed by the new, inheritable style
|
523
|
-
# finally, a controller-specific path for non-catalog subclasses
|
524
|
-
@partial_path_templates ||= ["%{action_name}_%{index_view_type}_%{format}", "%{action_name}_%{index_view_type}_default", "%{action_name}_%{format}", "%{action_name}_default", "catalog/%{action_name}_%{format}", "catalog/_%{action_name}_partials/%{format}", "catalog/_%{action_name}_partials/default"]
|
525
|
-
end
|
526
|
-
|
527
347
|
##
|
528
348
|
# Render the document index heading
|
529
349
|
#
|
530
350
|
# @param [SolrDocument] doc
|
531
|
-
# @param [Hash] opts
|
351
|
+
# @param [Hash] opts (deprecated)
|
532
352
|
# @option opts [Symbol] :label Render the given field from the document
|
533
353
|
# @option opts [Proc] :label Evaluate the given proc
|
534
354
|
# @option opts [String] :label Render the given string
|
535
|
-
|
536
|
-
|
355
|
+
# @param [Symbol, Proc, String] field Render the given field or evaluate the proc or render the given string
|
356
|
+
def render_document_index_label doc, field, opts = {}
|
357
|
+
Deprecation.warn self, "render_document_index_label is deprecated"
|
358
|
+
if field.kind_of? Hash
|
359
|
+
Deprecation.warn self, "Calling render_document_index_label with a hash is deprecated"
|
360
|
+
field = field[:label]
|
361
|
+
end
|
362
|
+
presenter(doc).render_document_index_label field, opts
|
537
363
|
end
|
538
364
|
|
539
365
|
##
|
@@ -566,6 +392,12 @@ module Blacklight::BlacklightHelperBehavior
|
|
566
392
|
has_user_authentication_provider? and current_or_guest_user.present?
|
567
393
|
end
|
568
394
|
|
395
|
+
##
|
396
|
+
# Determine whether to render the saved searches link
|
397
|
+
def render_saved_searches?
|
398
|
+
has_user_authentication_provider? and current_user
|
399
|
+
end
|
400
|
+
|
569
401
|
##
|
570
402
|
# Returns a document presenter for the given document
|
571
403
|
def presenter(document)
|
@@ -575,7 +407,7 @@ module Blacklight::BlacklightHelperBehavior
|
|
575
407
|
##
|
576
408
|
# Override this method if you want to use a different presenter class
|
577
409
|
def presenter_class
|
578
|
-
Blacklight::DocumentPresenter
|
410
|
+
blacklight_config.document_presenter_class || Blacklight::DocumentPresenter
|
579
411
|
end
|
580
412
|
|
581
413
|
##
|