blacklight 5.12.1 → 5.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +14 -8
- data/app/helpers/blacklight/catalog_helper_behavior.rb +9 -0
- data/app/helpers/blacklight/layout_helper_behavior.rb +34 -0
- data/app/helpers/layout_helper.rb +3 -0
- data/app/views/catalog/_show_main_content.html.erb +19 -0
- data/app/views/catalog/index.html.erb +2 -2
- data/app/views/catalog/show.html.erb +3 -30
- data/lib/blacklight/abstract_repository.rb +1 -2
- data/lib/blacklight/configuration.rb +6 -0
- data/lib/blacklight/request_builders.rb +2 -2
- data/lib/blacklight/search_builder.rb +79 -9
- data/lib/blacklight/search_helper.rb +10 -9
- data/lib/blacklight/solr_repository.rb +2 -2
- data/lib/blacklight/utils.rb +10 -1
- data/spec/helpers/blacklight_helper_spec.rb +33 -0
- data/spec/helpers/layout_helper_spec.rb +31 -0
- data/spec/lib/blacklight/configuration_spec.rb +12 -0
- data/spec/lib/blacklight/search_builder_spec.rb +91 -3
- data/spec/lib/blacklight/solr_repository_spec.rb +7 -0
- data/spec/lib/utils_spec.rb +44 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1b1cb3c8c840ba192f1b41a34318d44392d616a
|
4
|
+
data.tar.gz: 24a3b7ac9557d150777dd508738022c5edf5b376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5330c09fc2acb28fac501295d13078724d45f98c81d14163e7ce22b5b54e2cdaf8b5435704c0969534b69649db67d5a1f1893905c68c9021d53a508c5494981
|
7
|
+
data.tar.gz: 7c3071efa52edb0bd2549351e515fd4b40a87fdca82d25b2a910b6635f68ad2272bfba7cc9bd80ca9c2d5fc67897e50079149ece3b0df370134a8dc7827b1432
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
5.
|
1
|
+
5.13.0
|
@@ -266,23 +266,29 @@ module Blacklight::BlacklightHelperBehavior
|
|
266
266
|
##
|
267
267
|
# Render the document "heading" (title) in a content tag
|
268
268
|
# @overload render_document_heading(tag)
|
269
|
+
# @params [Symbol] tag
|
269
270
|
# @overload render_document_heading(document, options)
|
270
271
|
# @params [SolrDocument] document
|
271
272
|
# @params [Hash] options
|
272
273
|
# @options options [Symbol] :tag
|
274
|
+
# @overload render_document_heading(options)
|
275
|
+
# @params [Hash] options
|
276
|
+
# @options options [Symbol] :tag
|
273
277
|
def render_document_heading(*args)
|
274
278
|
options = args.extract_options!
|
275
|
-
|
276
|
-
|
277
|
-
|
279
|
+
|
280
|
+
tag_or_document = args.first
|
281
|
+
|
282
|
+
if tag_or_document.is_a? String or tag_or_document.is_a? Symbol
|
283
|
+
Deprecation.warn(Blacklight::BlacklightHelperBehavior, "#render_document_heading with a tag argument is deprecated; pass e.g. `tag: :h4` instead")
|
284
|
+
tag = tag_or_document
|
285
|
+
document = @document
|
278
286
|
else
|
279
|
-
|
280
|
-
|
287
|
+
tag = options.fetch(:tag, :h4)
|
288
|
+
document = tag_or_document || @document
|
281
289
|
end
|
282
290
|
|
283
|
-
tag
|
284
|
-
|
285
|
-
content_tag(tag, presenter(document).document_heading, :itemprop => "name")
|
291
|
+
content_tag(tag, presenter(document).document_heading, itemprop: "name")
|
286
292
|
end
|
287
293
|
|
288
294
|
##
|
@@ -117,6 +117,15 @@ module Blacklight::CatalogHelperBehavior
|
|
117
117
|
render :partial => 'show_sidebar'
|
118
118
|
end
|
119
119
|
|
120
|
+
##
|
121
|
+
# Render the main content partial for a document
|
122
|
+
#
|
123
|
+
# @param [SolrDocument]
|
124
|
+
# @return [String]
|
125
|
+
def render_document_main_content_partial(document = @document)
|
126
|
+
render partial: 'show_main_content'
|
127
|
+
end
|
128
|
+
|
120
129
|
##
|
121
130
|
# Should we display the sort and per page widget?
|
122
131
|
#
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Methods added to this helper will be available to all templates in the hosting
|
2
|
+
# application
|
3
|
+
module Blacklight
|
4
|
+
# A module for useful methods used in layout configuration
|
5
|
+
module LayoutHelperBehavior
|
6
|
+
##
|
7
|
+
# Classes added to a document's show content div
|
8
|
+
# @return [String]
|
9
|
+
def show_content_classes
|
10
|
+
"#{main_content_classes} show-document"
|
11
|
+
end
|
12
|
+
|
13
|
+
##
|
14
|
+
# Classes added to a document's sidebar div
|
15
|
+
# @return [String]
|
16
|
+
def show_sidebar_classes
|
17
|
+
sidebar_classes
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Classes used for sizing the main content of a Blacklight page
|
22
|
+
# @return [String]
|
23
|
+
def main_content_classes
|
24
|
+
'col-md-9 col-sm-8'
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Classes used for sizing the sidebar content of a Blacklight page
|
29
|
+
# @return [String]
|
30
|
+
def sidebar_classes
|
31
|
+
'col-md-3 col-sm-4'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%= render 'previous_next_doc' %>
|
2
|
+
|
3
|
+
<% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name).html_safe %>
|
4
|
+
<% content_for(:head) { render_link_rel_alternates } %>
|
5
|
+
|
6
|
+
<div id="document" class="document <%= render_document_class %>" itemscope itemtype="<%= @document.itemtype %>">
|
7
|
+
<div id="doc_<%= @document.id.to_s.parameterize %>">
|
8
|
+
<%= render_document_partials @document, blacklight_config.view_config(:show).partials %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
|
13
|
+
<!--
|
14
|
+
// COinS, for Zotero among others.
|
15
|
+
// This document_partial_name(@document) business is not quite right,
|
16
|
+
// but has been there for a while.
|
17
|
+
-->
|
18
|
+
<span class="Z3988" title="<%= @document.export_as_openurl_ctx_kev(document_partial_name(@document)) %>"></span>
|
19
|
+
<% end %>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
<div id="sidebar" class="
|
1
|
+
<div id="sidebar" class="<%= sidebar_classes %>">
|
2
2
|
<%= render 'search_sidebar' %>
|
3
3
|
</div>
|
4
4
|
|
5
|
-
<div id="content" class="
|
5
|
+
<div id="content" class="<%= main_content_classes %>">
|
6
6
|
<% unless has_search_parameters? %>
|
7
7
|
<%# if there are no input/search related params, display the "home" partial -%>
|
8
8
|
<%= render 'home' %>
|
@@ -1,34 +1,7 @@
|
|
1
|
-
<div id="content" class="
|
2
|
-
|
3
|
-
<%= render 'previous_next_doc' %>
|
4
|
-
|
5
|
-
|
6
|
-
<% @page_title = t('blacklight.search.show.title', :document_title => document_show_html_title, :application_name => application_name).html_safe -%>
|
7
|
-
<% content_for(:head) { render_link_rel_alternates } -%>
|
8
|
-
<%# this should be in a partial -%>
|
9
|
-
|
10
|
-
<div id="document" class="document <%= render_document_class %>" itemscope itemtype="<%= @document.itemtype %>">
|
11
|
-
<div id="doc_<%= @document.id.to_s.parameterize %>">
|
12
|
-
|
13
|
-
<% # bookmark/folder functions -%>
|
14
|
-
<%= render_document_partials @document, blacklight_config.view_config(:show).partials %>
|
15
|
-
|
16
|
-
</div>
|
17
|
-
</div>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
<% if @document.respond_to?(:export_as_openurl_ctx_kev) %>
|
22
|
-
<!--
|
23
|
-
// COinS, for Zotero among others.
|
24
|
-
// This document_partial_name(@document) business is not quite right,
|
25
|
-
// but has been there for a while.
|
26
|
-
-->
|
27
|
-
<span class="Z3988" title="<%= @document.export_as_openurl_ctx_kev(document_partial_name(@document)) %>"></span>
|
28
|
-
<% end %>
|
29
|
-
|
1
|
+
<div id="content" class="<%= show_content_classes %>">
|
2
|
+
<%= render_document_main_content_partial %>
|
30
3
|
</div>
|
31
4
|
|
32
|
-
<div id="sidebar" class="
|
5
|
+
<div id="sidebar" class="<%= show_sidebar_classes %>">
|
33
6
|
<%= render_document_sidebar_partial %>
|
34
7
|
</div>
|
@@ -76,6 +76,8 @@ module Blacklight
|
|
76
76
|
document_model: nil,
|
77
77
|
# document presenter class used by helpers and views
|
78
78
|
document_presenter_class: nil,
|
79
|
+
# repository connection configuration
|
80
|
+
connection_config: nil,
|
79
81
|
##
|
80
82
|
# == Blacklight view configuration
|
81
83
|
##
|
@@ -211,6 +213,10 @@ module Blacklight
|
|
211
213
|
super || Blacklight::SolrRepository
|
212
214
|
end
|
213
215
|
|
216
|
+
def connection_config
|
217
|
+
super || Blacklight.connection_config
|
218
|
+
end
|
219
|
+
|
214
220
|
def search_builder_class
|
215
221
|
super || locate_search_builder_class
|
216
222
|
end
|
@@ -90,7 +90,7 @@ module Blacklight
|
|
90
90
|
# @param [Hash] extra_params an optional hash of parameters that should be
|
91
91
|
# added to the query post processing
|
92
92
|
def build_solr_query(user_params, processor_chain, extra_params=nil)
|
93
|
-
search_builder(processor_chain).with(user_params).
|
93
|
+
search_builder(processor_chain).with(user_params).merge(extra_params)
|
94
94
|
end
|
95
95
|
deprecation_deprecate build_solr_query: :query
|
96
96
|
|
@@ -107,7 +107,7 @@ module Blacklight
|
|
107
107
|
# Retrieve the results for a list of document ids
|
108
108
|
# @deprecated
|
109
109
|
def solr_documents_by_field_values_params(field, values)
|
110
|
-
search_builder([:add_query_to_solr]).with(q: { field => values}).
|
110
|
+
search_builder([:add_query_to_solr]).with(q: { field => values}).merge(fl: '*')
|
111
111
|
end
|
112
112
|
deprecation_deprecate :solr_documents_by_field_values_params
|
113
113
|
|
@@ -19,11 +19,14 @@ module Blacklight
|
|
19
19
|
|
20
20
|
@scope = scope
|
21
21
|
@blacklight_params = {}
|
22
|
+
@merged_params = {}
|
23
|
+
@reverse_merged_params = {}
|
22
24
|
end
|
23
25
|
|
24
26
|
##
|
25
27
|
# Set the parameters to pass through the processor chain
|
26
28
|
def with blacklight_params = {}
|
29
|
+
params_will_change!
|
27
30
|
@blacklight_params = blacklight_params.dup
|
28
31
|
self
|
29
32
|
end
|
@@ -31,6 +34,7 @@ module Blacklight
|
|
31
34
|
##
|
32
35
|
# Update the :q (query) parameter
|
33
36
|
def where conditions
|
37
|
+
params_will_change!
|
34
38
|
@blacklight_params[:q] = conditions
|
35
39
|
self
|
36
40
|
end
|
@@ -38,16 +42,63 @@ module Blacklight
|
|
38
42
|
##
|
39
43
|
# Append additional processor chain directives
|
40
44
|
def append *addl_processor_chain
|
41
|
-
|
45
|
+
params_will_change!
|
46
|
+
builder = self.class.new(processor_chain + addl_processor_chain, scope)
|
47
|
+
.with(blacklight_params)
|
48
|
+
.merge(@merged_params)
|
49
|
+
.reverse_merge(@reverse_merged_params)
|
50
|
+
|
51
|
+
builder.start(@start) if @start
|
52
|
+
builder.rows(@rows) if @rows
|
53
|
+
builder.page(@page) if @page
|
54
|
+
|
55
|
+
builder
|
42
56
|
end
|
43
57
|
|
58
|
+
##
|
59
|
+
# Merge additional, repository-specific parameters
|
60
|
+
def merge extra_params, &block
|
61
|
+
if extra_params
|
62
|
+
params_will_change!
|
63
|
+
@merged_params.merge!(extra_params.to_hash, &block)
|
64
|
+
end
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# "Reverse merge" additional, repository-specific parameters
|
70
|
+
def reverse_merge extra_params, &block
|
71
|
+
if extra_params
|
72
|
+
params_will_change!
|
73
|
+
@reverse_merged_params.reverse_merge!(extra_params.to_hash, &block)
|
74
|
+
end
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
delegate :[], :key?, to: :to_hash
|
79
|
+
|
44
80
|
# a solr query method
|
45
81
|
# @param [Hash,HashWithIndifferentAccess] extra_controller_params (nil) extra parameters to add to the search
|
46
82
|
# @return [Blacklight::SolrResponse] the solr response object
|
47
|
-
def
|
48
|
-
|
83
|
+
def to_hash method_extra_params = nil
|
84
|
+
unless method_extra_params.nil?
|
85
|
+
Deprecation.warn(Blacklight::SearchBuilder, "Calling SearchBuilder#query with extra parameters is deprecated. Use #merge(Hash) instead")
|
86
|
+
merge(method_extra_params)
|
87
|
+
end
|
88
|
+
|
89
|
+
if params_need_update?
|
90
|
+
@params = processed_parameters.
|
91
|
+
reverse_merge(@reverse_merged_params).
|
92
|
+
merge(@merged_params).
|
93
|
+
tap { self.clear_changes }
|
94
|
+
else
|
95
|
+
@params
|
96
|
+
end
|
49
97
|
end
|
50
98
|
|
99
|
+
alias_method :query, :to_hash
|
100
|
+
alias_method :to_h, :to_hash
|
101
|
+
|
51
102
|
# @returns a params hash for searching solr.
|
52
103
|
# The CatalogController #index action uses this.
|
53
104
|
# Solr parameters can come from a number of places. From lowest
|
@@ -82,6 +133,7 @@ module Blacklight
|
|
82
133
|
|
83
134
|
def start start = nil
|
84
135
|
if start
|
136
|
+
params_will_change!
|
85
137
|
@start = start.to_i
|
86
138
|
self
|
87
139
|
else
|
@@ -96,6 +148,7 @@ module Blacklight
|
|
96
148
|
|
97
149
|
def page page = nil
|
98
150
|
if page
|
151
|
+
params_will_change!
|
99
152
|
@page = page.to_i
|
100
153
|
@page = 1 if @page < 1
|
101
154
|
self
|
@@ -114,6 +167,7 @@ module Blacklight
|
|
114
167
|
|
115
168
|
def rows rows = nil
|
116
169
|
if rows
|
170
|
+
params_will_change!
|
117
171
|
@rows = rows.to_i
|
118
172
|
@rows = blacklight_config.max_per_page if @rows > blacklight_config.max_per_page
|
119
173
|
self
|
@@ -135,11 +189,6 @@ module Blacklight
|
|
135
189
|
|
136
190
|
alias_method :per, :rows
|
137
191
|
|
138
|
-
protected
|
139
|
-
def request
|
140
|
-
Blacklight::Solr::Request.new
|
141
|
-
end
|
142
|
-
|
143
192
|
def sort
|
144
193
|
field = if blacklight_params[:sort].blank? and sort_field = blacklight_config.default_sort_field
|
145
194
|
# no sort param provided, use default
|
@@ -158,7 +207,12 @@ module Blacklight
|
|
158
207
|
def search_field
|
159
208
|
blacklight_config.search_fields[blacklight_params[:search_field]]
|
160
209
|
end
|
161
|
-
|
210
|
+
|
211
|
+
protected
|
212
|
+
def request
|
213
|
+
Blacklight::Solr::Request.new
|
214
|
+
end
|
215
|
+
|
162
216
|
def should_add_field_to_request? field_name, field
|
163
217
|
field.include_in_request || (field.include_in_request.nil? && blacklight_config.add_field_configuration_to_solr_request)
|
164
218
|
end
|
@@ -166,5 +220,21 @@ module Blacklight
|
|
166
220
|
def scope
|
167
221
|
@scope
|
168
222
|
end
|
223
|
+
|
224
|
+
def params_will_change!
|
225
|
+
@dirty = true
|
226
|
+
end
|
227
|
+
|
228
|
+
def params_changed?
|
229
|
+
!!@dirty
|
230
|
+
end
|
231
|
+
|
232
|
+
def params_need_update?
|
233
|
+
params_changed? || @params.nil?
|
234
|
+
end
|
235
|
+
|
236
|
+
def clear_changes
|
237
|
+
@dirty = false
|
238
|
+
end
|
169
239
|
end
|
170
240
|
end
|
@@ -78,7 +78,7 @@ module Blacklight::SearchHelper
|
|
78
78
|
# Returns a two-element array (aka duple) with first the solr response object,
|
79
79
|
# and second an array of SolrDocuments representing the response.docs
|
80
80
|
def get_search_results(user_params = params || {}, extra_controller_params = {})
|
81
|
-
query = search_builder.with(user_params).
|
81
|
+
query = search_builder.with(user_params).merge(extra_controller_params)
|
82
82
|
response = repository.search(query)
|
83
83
|
|
84
84
|
case
|
@@ -102,7 +102,7 @@ module Blacklight::SearchHelper
|
|
102
102
|
builder.page(user_params[:page]) if user_params[:page]
|
103
103
|
builder.rows(user_params[:per_page] || user_params[:rows]) if user_params[:per_page] or user_params[:rows]
|
104
104
|
|
105
|
-
response = repository.search(builder
|
105
|
+
response = repository.search(builder)
|
106
106
|
|
107
107
|
case
|
108
108
|
when (response.grouped? && grouped_key_for_results)
|
@@ -119,7 +119,7 @@ module Blacklight::SearchHelper
|
|
119
119
|
# @param [Hash,HashWithIndifferentAccess] extra_controller_params ({}) extra parameters to add to the search
|
120
120
|
# @return [Blacklight::SolrResponse] the solr response object
|
121
121
|
def query_solr(user_params = params || {}, extra_controller_params = {})
|
122
|
-
query = search_builder.with(user_params).
|
122
|
+
query = search_builder.with(user_params).merge(extra_controller_params)
|
123
123
|
repository.search(query)
|
124
124
|
end
|
125
125
|
deprecation_deprecate :query_solr
|
@@ -145,7 +145,7 @@ module Blacklight::SearchHelper
|
|
145
145
|
# @return [Blacklight::SolrResponse, Array<Blacklight::SolrDocument>] the solr response object and a list of solr documents
|
146
146
|
def get_solr_response_for_field_values(field, values, extra_controller_params = {})
|
147
147
|
query = Deprecation.silence(Blacklight::RequestBuilders) do
|
148
|
-
search_builder.with(params).
|
148
|
+
search_builder.with(params).merge(extra_controller_params).merge(solr_documents_by_field_values_params(field, values))
|
149
149
|
end
|
150
150
|
|
151
151
|
solr_response = repository.search(query)
|
@@ -159,7 +159,7 @@ module Blacklight::SearchHelper
|
|
159
159
|
# Get the solr response when retrieving only a single facet field
|
160
160
|
# @return [Blacklight::SolrResponse] the solr response
|
161
161
|
def get_facet_field_response(facet_field, user_params = params || {}, extra_controller_params = {})
|
162
|
-
query = search_builder.with(user_params).
|
162
|
+
query = search_builder.with(user_params).merge(extra_controller_params).merge(solr_facet_params(facet_field, user_params, extra_controller_params))
|
163
163
|
repository.search(query)
|
164
164
|
end
|
165
165
|
|
@@ -191,7 +191,7 @@ module Blacklight::SearchHelper
|
|
191
191
|
# the Blacklight app-level request params that define the search.
|
192
192
|
# @return [Blacklight::SolrDocument, nil] the found document or nil if not found
|
193
193
|
def get_single_doc_via_search(index, request_params)
|
194
|
-
query = search_builder.with(request_params).start(index - 1).rows(1).
|
194
|
+
query = search_builder.with(request_params).start(index - 1).rows(1).merge(fl: "*")
|
195
195
|
response = repository.search(query)
|
196
196
|
response.documents.first
|
197
197
|
end
|
@@ -202,7 +202,7 @@ module Blacklight::SearchHelper
|
|
202
202
|
def get_previous_and_next_documents_for_search(index, request_params, extra_controller_params={})
|
203
203
|
p = previous_and_next_document_params(index)
|
204
204
|
|
205
|
-
query = search_builder.with(request_params).start(p.delete(:start)).rows(p.delete(:rows)).
|
205
|
+
query = search_builder.with(request_params).start(p.delete(:start)).rows(p.delete(:rows)).merge(extra_controller_params).merge(p)
|
206
206
|
response = repository.search(query)
|
207
207
|
|
208
208
|
document_list = response.documents
|
@@ -223,7 +223,7 @@ module Blacklight::SearchHelper
|
|
223
223
|
def get_opensearch_response(field=nil, request_params = params || {}, extra_controller_params={})
|
224
224
|
field ||= blacklight_config.view_config('opensearch').title_field
|
225
225
|
|
226
|
-
query = search_builder.with(request_params).
|
226
|
+
query = search_builder.with(request_params).merge(solr_opensearch_params(field)).merge(extra_controller_params)
|
227
227
|
response = repository.search(query)
|
228
228
|
|
229
229
|
[response.params[:q], response.documents.flat_map {|doc| doc[field] }.uniq]
|
@@ -273,7 +273,8 @@ module Blacklight::SearchHelper
|
|
273
273
|
query = search_builder.
|
274
274
|
with(user_params).
|
275
275
|
where(blacklight_config.document_model.unique_key => ids).
|
276
|
-
|
276
|
+
merge(extra_controller_params).
|
277
|
+
merge(fl: '*')
|
277
278
|
solr_response = repository.search(query)
|
278
279
|
|
279
280
|
[solr_response, solr_response.documents]
|
@@ -12,8 +12,8 @@ module Blacklight
|
|
12
12
|
# @param [String] document's unique key value
|
13
13
|
# @param [Hash] additional solr query parameters
|
14
14
|
def find id, params = {}
|
15
|
-
doc_params = params.reverse_merge(
|
16
|
-
.reverse_merge(blacklight_config.
|
15
|
+
doc_params = params.reverse_merge(blacklight_config.default_document_solr_params)
|
16
|
+
.reverse_merge(qt: blacklight_config.document_solr_request_handler)
|
17
17
|
.merge(blacklight_config.document_unique_id_param => id)
|
18
18
|
|
19
19
|
solr_response = send_and_receive blacklight_config.document_solr_path || blacklight_config.solr_path, doc_params
|
data/lib/blacklight/utils.rb
CHANGED
@@ -26,7 +26,7 @@ module Blacklight
|
|
26
26
|
##
|
27
27
|
# An OpenStruct that responds to common Hash methods
|
28
28
|
class OpenStructWithHashAccess < OpenStruct
|
29
|
-
delegate :keys, :each, :map, :has_key?, :empty?, :delete, :
|
29
|
+
delegate :keys, :each, :map, :has_key?, :key?, :include?, :empty?, :length, :delete, :delete_if, :keep_if, :clear, :reject!, :select!, :replace, :fetch, :to_json, :as_json, to: :to_h
|
30
30
|
|
31
31
|
if ::RUBY_VERSION < '2.0'
|
32
32
|
def []=(key, value)
|
@@ -53,6 +53,15 @@ module Blacklight
|
|
53
53
|
self.class.new to_h.select(*args, &block)
|
54
54
|
end
|
55
55
|
|
56
|
+
def sort_by *args, &block
|
57
|
+
self.class.new Hash[to_h.sort_by(*args, &block)]
|
58
|
+
end
|
59
|
+
|
60
|
+
def sort_by! *args, &block
|
61
|
+
replace Hash[to_h.sort_by(*args, &block)]
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
56
65
|
##
|
57
66
|
# Merge the values of this OpenStruct with another OpenStruct or Hash
|
58
67
|
# @param [Hash,#to_h]
|
@@ -539,4 +539,37 @@ describe BlacklightHelper do
|
|
539
539
|
expect(helper.presenter_class).to eq Blacklight::DocumentPresenter
|
540
540
|
end
|
541
541
|
end
|
542
|
+
|
543
|
+
describe "#render_document_heading" do
|
544
|
+
before do
|
545
|
+
allow(helper).to receive(:presenter).and_return(double(document_heading: "Heading"))
|
546
|
+
end
|
547
|
+
|
548
|
+
let(:document) { double }
|
549
|
+
|
550
|
+
it "should accept no arguments and render the document heading" do
|
551
|
+
expect(helper.render_document_heading).to have_selector "h4", text: "Heading"
|
552
|
+
end
|
553
|
+
|
554
|
+
it "should accept a tag name and render the document heading" do
|
555
|
+
Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
|
556
|
+
expect(helper.render_document_heading(:h3)).to have_selector "h3", text: "Heading"
|
557
|
+
expect(helper.render_document_heading("h2")).to have_selector "h2", text: "Heading"
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
it "should accept the tag name as an option" do
|
562
|
+
expect(helper.render_document_heading tag: "h1").to have_selector "h1", text: "Heading"
|
563
|
+
end
|
564
|
+
|
565
|
+
it "should accept an explicit document argument" do
|
566
|
+
allow(helper).to receive(:presenter).with(document).and_return(double(document_heading: "Document Heading"))
|
567
|
+
expect(helper.render_document_heading(document)).to have_selector "h4", text: "Document Heading"
|
568
|
+
end
|
569
|
+
|
570
|
+
it "should accept the document with a tag option" do
|
571
|
+
allow(helper).to receive(:presenter).with(document).and_return(double(document_heading: "Document Heading"))
|
572
|
+
expect(helper.render_document_heading(document, tag: "h3")).to have_selector "h3", text: "Document Heading"
|
573
|
+
end
|
574
|
+
end
|
542
575
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LayoutHelper do
|
4
|
+
describe '#show_content_classes' do
|
5
|
+
it 'returns a string of classes' do
|
6
|
+
expect(helper.show_content_classes).to be_an String
|
7
|
+
expect(helper.show_content_classes).to eq 'col-md-9 col-sm-8 show-document'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#show_sidebar_classes' do
|
12
|
+
it 'returns a string of classes' do
|
13
|
+
expect(helper.show_sidebar_classes).to be_an String
|
14
|
+
expect(helper.show_sidebar_classes).to eq 'col-md-3 col-sm-4'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#main_content_classes' do
|
19
|
+
it 'returns a string of classes' do
|
20
|
+
expect(helper.main_content_classes).to be_an String
|
21
|
+
expect(helper.main_content_classes).to eq 'col-md-9 col-sm-8'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#sidebar_classes' do
|
26
|
+
it 'returns a string of classes' do
|
27
|
+
expect(helper.sidebar_classes).to be_an String
|
28
|
+
expect(helper.sidebar_classes).to eq 'col-md-3 col-sm-4'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -48,6 +48,18 @@ describe "Blacklight::Configuration" do
|
|
48
48
|
expect(@config.search_fields).to be_a_kind_of ActiveSupport::OrderedHash
|
49
49
|
expect(@config.sort_fields).to be_a_kind_of ActiveSupport::OrderedHash
|
50
50
|
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#connection_config" do
|
55
|
+
let(:custom_config) { double }
|
56
|
+
it "should have the global blacklight configuration" do
|
57
|
+
expect(@config.connection_config).to eq Blacklight.connection_config
|
58
|
+
end
|
59
|
+
it "should be overridable with custom configuration" do
|
60
|
+
@config.connection_config = custom_config
|
61
|
+
expect(@config.connection_config).to eq custom_config
|
62
|
+
end
|
51
63
|
end
|
52
64
|
|
53
65
|
describe "config.index.respond_to" do
|
@@ -47,10 +47,51 @@ describe Blacklight::SearchBuilder do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe "#
|
50
|
+
describe "#to_hash" do
|
51
51
|
it "should append the extra parameters to the result" do
|
52
|
-
|
53
|
-
|
52
|
+
Deprecation.silence(Blacklight::SearchBuilder) do
|
53
|
+
actual = subject.to_hash({a: 1})
|
54
|
+
expect(actual).to include a: 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should update if data is changed" do
|
59
|
+
subject.merge(q: 'xyz')
|
60
|
+
expect(subject.to_hash).to include q: 'xyz'
|
61
|
+
subject.merge(q: 'abc')
|
62
|
+
expect(subject.to_hash).to include q: 'abc'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#merge" do
|
67
|
+
let(:processor_chain) { [:pass_through] }
|
68
|
+
before do
|
69
|
+
allow(subject).to receive(:pass_through) do |req_params|
|
70
|
+
req_params.replace subject.blacklight_params
|
71
|
+
end
|
72
|
+
end
|
73
|
+
it "should overwrite the processed parameters" do
|
74
|
+
actual = subject.with(q: 'abc').merge(q: 'xyz')
|
75
|
+
expect(actual[:q]).to eq 'xyz'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#reverse_merge" do
|
80
|
+
let(:processor_chain) { [:pass_through] }
|
81
|
+
before do
|
82
|
+
allow(subject).to receive(:pass_through) do |req_params|
|
83
|
+
req_params.replace subject.blacklight_params
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should provide default values for parameters" do
|
88
|
+
actual = subject.reverse_merge(a: 1)
|
89
|
+
expect(actual[:a]).to eq 1
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not overwrite the processed parameters" do
|
93
|
+
actual = subject.with(q: 'abc').reverse_merge(q: 'xyz')
|
94
|
+
expect(actual[:q]).to eq 'abc'
|
54
95
|
end
|
55
96
|
end
|
56
97
|
|
@@ -152,4 +193,51 @@ describe Blacklight::SearchBuilder do
|
|
152
193
|
expect(subject.with(search_field: 'x').send(:search_field)).to eq blacklight_config.search_fields['x']
|
153
194
|
end
|
154
195
|
end
|
196
|
+
|
197
|
+
describe "#params_changed?" do
|
198
|
+
it "should be false" do
|
199
|
+
expect(subject.send(:params_changed?)).to eq false
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should be marked as changed when with() changes" do
|
203
|
+
subject.with(a: 1)
|
204
|
+
expect(subject.send(:params_changed?)).to eq true
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should be marked as changed when where() changes" do
|
208
|
+
subject.where(a: 1)
|
209
|
+
expect(subject.send(:params_changed?)).to eq true
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should be marked as changed when the processor chain changes" do
|
213
|
+
subject.append(:a)
|
214
|
+
expect(subject.send(:params_changed?)).to eq true
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should be marked as changed when merged parameters are added" do
|
218
|
+
subject.merge(a: 1)
|
219
|
+
expect(subject.send(:params_changed?)).to eq true
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should be marked as changed when reverse merged parameters are added" do
|
223
|
+
subject.merge(a: 1)
|
224
|
+
expect(subject.send(:params_changed?)).to eq true
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should be marked as changed when pagination changes" do
|
228
|
+
subject.page(1)
|
229
|
+
expect(subject.send(:params_changed?)).to eq true
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should be marked as changed when rows changes" do
|
233
|
+
subject.rows(1)
|
234
|
+
expect(subject.send(:params_changed?)).to eq true
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should be marked as changed when start offset changes" do
|
238
|
+
subject.start(1)
|
239
|
+
expect(subject.send(:params_changed?)).to eq true
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
155
243
|
end
|
@@ -42,6 +42,13 @@ describe Blacklight::SolrRepository do
|
|
42
42
|
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { id: '123', qt: 'abc'})).and_return(mock_response)
|
43
43
|
expect(subject.find("123", {qt: 'abc'})).to be_a_kind_of Blacklight::SolrResponse
|
44
44
|
end
|
45
|
+
|
46
|
+
it "should use the :qt parameter from the default_document_solr_params" do
|
47
|
+
blacklight_config.default_document_solr_params[:qt] = 'abc'
|
48
|
+
blacklight_config.document_solr_request_handler = 'xyz'
|
49
|
+
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { id: '123', qt: 'abc'})).and_return(mock_response)
|
50
|
+
expect(subject.find("123")).to be_a_kind_of Blacklight::SolrResponse
|
51
|
+
end
|
45
52
|
|
46
53
|
it "should preserve the class of the incoming params" do
|
47
54
|
doc_params = HashWithIndifferentAccess.new
|
data/spec/lib/utils_spec.rb
CHANGED
@@ -48,6 +48,50 @@ describe 'Blacklight::Utils' do
|
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
|
+
describe "#key?" do
|
52
|
+
subject do
|
53
|
+
h = Blacklight::OpenStructWithHashAccess.new
|
54
|
+
h[:a] = 1
|
55
|
+
h[:b] = 2
|
56
|
+
h
|
57
|
+
end
|
58
|
+
|
59
|
+
it "is true if the key exists" do
|
60
|
+
expect(subject.key? :a).to eq true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "is false if the key does not exist" do
|
64
|
+
expect(subject.key? :c).to eq false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#replace" do
|
69
|
+
subject { Blacklight::OpenStructWithHashAccess.new a: 1 }
|
70
|
+
|
71
|
+
it "can use #replace to reorder the hash" do
|
72
|
+
subject.replace b: 1
|
73
|
+
expect(subject.b).to eq 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#sort_by" do
|
78
|
+
subject { Blacklight::OpenStructWithHashAccess.new c: 3, b:1, a: 2 }
|
79
|
+
|
80
|
+
it "should sort the underlying hash" do
|
81
|
+
sorted = subject.sort_by { |k,v| v }
|
82
|
+
expect(sorted.keys).to match_array [:b, :a, :c]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#sort_by!" do
|
87
|
+
subject { Blacklight::OpenStructWithHashAccess.new c: 3, b:1, a: 2 }
|
88
|
+
|
89
|
+
it "should sort the underlying hash" do
|
90
|
+
subject.sort_by! { |k,v| v }
|
91
|
+
expect(subject.keys).to match_array [:b, :a, :c]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
51
95
|
describe "#merge" do
|
52
96
|
|
53
97
|
before do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Rochkind
|
@@ -17,7 +17,7 @@ authors:
|
|
17
17
|
autorequire:
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
|
-
date: 2015-
|
20
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rails
|
@@ -292,6 +292,7 @@ files:
|
|
292
292
|
- app/helpers/blacklight/configuration_helper_behavior.rb
|
293
293
|
- app/helpers/blacklight/facets_helper_behavior.rb
|
294
294
|
- app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb
|
295
|
+
- app/helpers/blacklight/layout_helper_behavior.rb
|
295
296
|
- app/helpers/blacklight/render_constraints_helper_behavior.rb
|
296
297
|
- app/helpers/blacklight/render_partials_helper.rb
|
297
298
|
- app/helpers/blacklight/search_history_constraints_helper_behavior.rb
|
@@ -303,6 +304,7 @@ files:
|
|
303
304
|
- app/helpers/component_helper.rb
|
304
305
|
- app/helpers/facets_helper.rb
|
305
306
|
- app/helpers/hash_as_hidden_fields_helper.rb
|
307
|
+
- app/helpers/layout_helper.rb
|
306
308
|
- app/helpers/render_constraints_helper.rb
|
307
309
|
- app/helpers/search_history_constraints_helper.rb
|
308
310
|
- app/models/bookmark.rb
|
@@ -350,6 +352,7 @@ files:
|
|
350
352
|
- app/views/catalog/_search_sidebar.html.erb
|
351
353
|
- app/views/catalog/_show_default.html.erb
|
352
354
|
- app/views/catalog/_show_header_default.html.erb
|
355
|
+
- app/views/catalog/_show_main_content.html.erb
|
353
356
|
- app/views/catalog/_show_more_like_this.html.erb
|
354
357
|
- app/views/catalog/_show_sidebar.html.erb
|
355
358
|
- app/views/catalog/_show_tools.html.erb
|
@@ -514,6 +517,7 @@ files:
|
|
514
517
|
- spec/helpers/configuration_helper_spec.rb
|
515
518
|
- spec/helpers/facets_helper_spec.rb
|
516
519
|
- spec/helpers/hash_as_hidden_fields_spec.rb
|
520
|
+
- spec/helpers/layout_helper_spec.rb
|
517
521
|
- spec/helpers/render_constraints_helper_spec.rb
|
518
522
|
- spec/helpers/search_history_constraints_helper_spec.rb
|
519
523
|
- spec/helpers/url_helper_spec.rb
|
@@ -634,6 +638,7 @@ test_files:
|
|
634
638
|
- spec/helpers/configuration_helper_spec.rb
|
635
639
|
- spec/helpers/facets_helper_spec.rb
|
636
640
|
- spec/helpers/hash_as_hidden_fields_spec.rb
|
641
|
+
- spec/helpers/layout_helper_spec.rb
|
637
642
|
- spec/helpers/render_constraints_helper_spec.rb
|
638
643
|
- spec/helpers/search_history_constraints_helper_spec.rb
|
639
644
|
- spec/helpers/url_helper_spec.rb
|