blacklight 6.4.0 → 6.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08a32b124f67c2eee4651aa298a0c04c6cc1b0a3
4
- data.tar.gz: 99eb3c4e5a513755c0b44572d3f59e43ad46ae84
3
+ metadata.gz: a6689bf20317b8fb6bee88d3064ce8528fbfe2ec
4
+ data.tar.gz: 2a83b261f71d22b9959014af71f0cc64736bd228
5
5
  SHA512:
6
- metadata.gz: 36debbcf121bb69692fd23a4f3183fa11a463cf33d754e2dd25589ef3fed03b2d89ef8c12a695bbc6666f42ecb67b2d6cc00600fbec0eeb1e2d2bd12970c993c
7
- data.tar.gz: 4efcffee2bac9324aa344f2671a987e5628f1be7444c3517c4f8b63ea6917a7b8fee38dc796d616fb5a637dfca961382d89e6e0bca6512c49733f60a7c891874
6
+ metadata.gz: 0e83db02e3fa34951449c29fcc84ea4e92395d90a914b0432f6a2494c52f12b0032f482fbd5fbd0f309c03457038546f4eee4273f9a26ca39869ccc09af92160
7
+ data.tar.gz: 6273e3a816b869b90ed3f4eb5e1dffcf2d15786687b806fd45c9b0c61e76894158d4b0a3a741e10fd06c94b865342edcfdb589ba959dfa3cf3857a85e3d53a00
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  .DS_Store
2
2
  *.sw[pon]
3
3
  .bundle
4
+ .byebug_history
4
5
  .rvmrc
5
6
  *.log
6
7
  Gemfile.lock
data/Gemfile CHANGED
@@ -11,10 +11,10 @@ group :test do
11
11
  end
12
12
 
13
13
  # BEGIN ENGINE_CART BLOCK
14
- # engine_cart: 0.8.0
15
- # engine_cart stanza: 0.8.0
14
+ # engine_cart: 0.10.0
15
+ # engine_cart stanza: 0.10.0
16
16
  # the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
17
- file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path(".internal_test_app", File.dirname(__FILE__)))
17
+ file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
18
18
  if File.exist?(file)
19
19
  begin
20
20
  eval_gemfile file
@@ -28,20 +28,19 @@ else
28
28
  if ENV['RAILS_VERSION']
29
29
  if ENV['RAILS_VERSION'] == 'edge'
30
30
  gem 'rails', github: 'rails/rails'
31
- ENV['ENGINE_CART_RAILS_OPTIONS']= "--edge --skip-turbolinks"
31
+ ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
32
32
  else
33
33
  gem 'rails', ENV['RAILS_VERSION']
34
34
  end
35
35
  end
36
36
 
37
- if ENV['RAILS_VERSION'].nil? || ENV['RAILS_VERSION'] =~ /^5\.0/ || ENV['RAILS_VERSION'] == 'edge'
38
- # noop
39
- elsif ENV['RAILS_VERSION'] =~ /^4\.2/
40
- gem 'responders', "~> 2.0"
41
- gem 'sass-rails', ">= 5.0"
42
- else
43
- gem 'bootstrap-sass', '< 3.3.5' # 3.3.5 requires sass 3.3, incompatible with sass-rails 4.x
44
- gem 'sass-rails', "< 5.0"
37
+ case ENV['RAILS_VERSION']
38
+ when /^4.2/
39
+ gem 'responders', '~> 2.0'
40
+ gem 'sass-rails', '>= 5.0'
41
+ gem 'coffee-rails', '~> 4.1.0'
42
+ when /^4.[01]/
43
+ gem 'sass-rails', '< 5.0'
45
44
  end
46
45
  end
47
46
  # END ENGINE_CART BLOCK
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.4.0
1
+ 6.5.0
@@ -1,7 +1,7 @@
1
1
  .twitter-typeahead {
2
2
  float: left;
3
3
  width: 100%;
4
- z-index: 10000;
4
+ z-index: $zindex-typeahead;
5
5
 
6
6
  input.tt-input.form-control {
7
7
  width: 100%;
@@ -4,3 +4,4 @@ $logo_image: 'blacklight/logo.png' !default;
4
4
 
5
5
  /* label (field names) */
6
6
  $field_name_color: $text-muted !default;
7
+ $zindex-typeahead: $zindex-dropdown;
@@ -15,6 +15,7 @@ module Blacklight::Bookmarks
15
15
 
16
16
  before_action :verify_user
17
17
 
18
+ blacklight_config.http_method = Blacklight::Engine.config.bookmarks_http_method
18
19
  blacklight_config.add_results_collection_tool(:clear_bookmarks_widget)
19
20
 
20
21
  blacklight_config.show.document_actions[:bookmark].if = false if blacklight_config.show.document_actions[:bookmark]
@@ -83,7 +84,7 @@ module Blacklight::Bookmarks
83
84
  end
84
85
 
85
86
  if request.xhr?
86
- success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count }}) : render(:text => "", :status => "500")
87
+ success ? render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count }}) : render(plain: "", status: "500")
87
88
  else
88
89
  if @bookmarks.any? && success
89
90
  flash[:notice] = I18n.t('blacklight.bookmarks.add.success', :count => @bookmarks.length)
@@ -114,16 +115,13 @@ module Blacklight::Bookmarks
114
115
  # Deprecated in Rails 5.0
115
116
  redirect_to :back, notice: I18n.t('blacklight.bookmarks.remove.success')
116
117
  end
118
+ elsif request.xhr?
119
+ head 500 # ajaxy request needs no redirect and should not have flash set
120
+ elsif respond_to? :redirect_back
121
+ redirect_back fallback_location: bookmarks_path, flash: { error: I18n.t('blacklight.bookmarks.remove.failure') }
117
122
  else
118
- if request.xhr?
119
- # ajaxy request needs no redirect and should not have flash set
120
- render(:text => "", :status => "500")
121
- elsif respond_to? :redirect_back
122
- redirect_back fallback_location: bookmarks_path, flash: { error: I18n.t('blacklight.bookmarks.remove.failure') }
123
- else
124
- # Deprecated in Rails 5.0
125
- redirect_to :back, flash: { error: I18n.t('blacklight.bookmarks.remove.failure') }
126
- end
123
+ # Deprecated in Rails 5.0
124
+ redirect_to :back, flash: { error: I18n.t('blacklight.bookmarks.remove.failure') }
127
125
  end
128
126
  end
129
127
 
@@ -43,11 +43,9 @@ module Blacklight::Catalog
43
43
  # to add responses for formats other than html or json see _Blacklight::Document::Export_
44
44
  def show
45
45
  @response, @document = fetch params[:id]
46
-
47
46
  respond_to do |format|
48
47
  format.html { setup_next_and_previous_documents }
49
48
  format.json { render json: { response: { document: @document } } }
50
-
51
49
  additional_export_formats(@document, format)
52
50
  end
53
51
  end
@@ -71,15 +69,11 @@ module Blacklight::Catalog
71
69
  @facet = blacklight_config.facet_fields[params[:id]]
72
70
  @response = get_facet_field_response(@facet.key, params)
73
71
  @display_facet = @response.aggregations[@facet.key]
74
-
75
72
  @pagination = facet_paginator(@facet, @display_facet)
76
-
77
-
78
73
  respond_to do |format|
79
74
  # Draw the facet selector for users who have javascript disabled:
80
75
  format.html
81
76
  format.json
82
-
83
77
  # Draw the partial for the "more" facet modal window:
84
78
  format.js { render :layout => false }
85
79
  end
@@ -88,12 +82,8 @@ module Blacklight::Catalog
88
82
  # method to serve up XML OpenSearch description and JSON autocomplete response
89
83
  def opensearch
90
84
  respond_to do |format|
91
- format.xml do
92
- render :layout => false
93
- end
94
- format.json do
95
- render :json => get_opensearch_response
96
- end
85
+ format.xml { render layout: false }
86
+ format.json { render json: get_opensearch_response }
97
87
  end
98
88
  end
99
89
 
@@ -107,7 +97,7 @@ module Blacklight::Catalog
107
97
 
108
98
  ##
109
99
  # Check if any search parameters have been set
110
- # @return [Boolean]
100
+ # @return [Boolean]
111
101
  def has_search_parameters?
112
102
  !params[:q].blank? or !params[:f].blank? or !params[:search_field].blank?
113
103
  end
@@ -129,13 +119,10 @@ module Blacklight::Catalog
129
119
  ##
130
120
  # Render additional response formats for the index action, as provided by the
131
121
  # blacklight configuration
132
- #
133
- # example:
134
- #
135
- # config.index.respond_to.txt = Proc.new { render text: "A list of docs." }
136
- #
137
- # Make sure your format has a well known mime-type or is registered in
138
- # config/initializers/mime_types.rb
122
+ # @param [Hash] format
123
+ # @note Make sure your format has a well known mime-type or is registered in config/initializers/mime_types.rb
124
+ # @example
125
+ # config.index.respond_to.txt = Proc.new { render plain: "A list of docs." }
139
126
  def additional_response_formats format
140
127
  blacklight_config.index.respond_to.each do |key, config|
141
128
  format.send key do
@@ -160,7 +147,7 @@ module Blacklight::Catalog
160
147
  # the document extension framework. See _Blacklight::Document::Export_
161
148
  def additional_export_formats(document, format)
162
149
  document.export_formats.each_key do | format_name |
163
- format.send(format_name.to_sym) { render text: document.export_as(format_name), layout: false }
150
+ format.send(format_name.to_sym) { render body: document.export_as(format_name), layout: false }
164
151
  end
165
152
  end
166
153
 
@@ -169,7 +156,6 @@ module Blacklight::Catalog
169
156
  def document_export_formats format
170
157
  format.any do
171
158
  format_name = params.fetch(:format, '').to_sym
172
-
173
159
  if @response.export_formats.include? format_name
174
160
  render_document_export_format format_name
175
161
  else
@@ -181,11 +167,11 @@ module Blacklight::Catalog
181
167
  ##
182
168
  # Render the document export formats for a response
183
169
  # First, try to render an appropriate template (e.g. index.endnote.erb)
184
- # If that fails, just concatenate the document export responses with a newline.
170
+ # If that fails, just concatenate the document export responses with a newline.
185
171
  def render_document_export_format format_name
186
172
  render
187
173
  rescue ActionView::MissingTemplate
188
- render text: @response.documents.map { |x| x.export_as(format_name) if x.exports_as? format_name }.compact.join("\n"), layout: false
174
+ render plain: @response.documents.map { |x| x.export_as(format_name) if x.exports_as? format_name }.compact.join("\n"), layout: false
189
175
  end
190
176
 
191
177
  # Overrides the Blacklight::Controller provided #search_action_url.
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight::CatalogHelperBehavior
3
3
 
4
- def rss_feed_link_tag
5
- auto_discovery_link_tag(:rss, feed_link_url('rss'), title: t('blacklight.search.rss_feed'))
4
+ # @param [Hash] options
5
+ # @option options :route_set the route scope to use when constructing the link
6
+ def rss_feed_link_tag(options = {})
7
+ auto_discovery_link_tag(:rss, feed_link_url('rss', options), title: t('blacklight.search.rss_feed'))
6
8
  end
7
9
 
8
- def atom_feed_link_tag
9
- auto_discovery_link_tag(:atom, feed_link_url('atom'), title: t('blacklight.search.atom_feed'))
10
+ # @param [Hash] options
11
+ # @option options :route_set the route scope to use when constructing the link
12
+ def atom_feed_link_tag(options = {})
13
+ auto_discovery_link_tag(:atom, feed_link_url('atom', options), title: t('blacklight.search.atom_feed'))
10
14
  end
11
15
 
12
16
  ##
@@ -285,7 +289,11 @@ module Blacklight::CatalogHelperBehavior
285
289
 
286
290
  private
287
291
 
288
- def feed_link_url(format)
289
- url_for search_state.to_h.merge(format: format)
292
+ # @param [String] format
293
+ # @param [Hash] options
294
+ # @option options :route_set the route scope to use when constructing the link
295
+ def feed_link_url(format, options = {})
296
+ scope = options.delete(:route_set) || self
297
+ scope.url_for search_state.to_h.merge(format: format)
290
298
  end
291
299
  end
@@ -50,6 +50,11 @@ module Blacklight::RenderConstraintsHelperBehavior
50
50
  # @return [String]
51
51
  def remove_constraint_url(localized_params)
52
52
  scope = localized_params.delete(:route_set) || self
53
+
54
+ unless localized_params.is_a? ActionController::Parameters
55
+ localized_params = ActionController::Parameters.new(localized_params)
56
+ end
57
+
53
58
  options = localized_params.merge(q: nil, action: 'index')
54
59
  options.permit!
55
60
  scope.url_for(options)
@@ -2,7 +2,7 @@
2
2
  # == Transformation conventions
3
3
  # The main use case for extensions is for transforming a Document to another
4
4
  # format. Either to another type of Ruby object, or to an exportable string in
5
- # a certain format.
5
+ # a certain format.
6
6
  #
7
7
  # The convention for methods contained in extensions that transform to a ruby
8
8
  # object is "to_*". For instance, "to_marc" would return a Ruby Marc object.
@@ -20,7 +20,7 @@
20
20
  # If an extension advertises what export formats it can provide, than those
21
21
  # formats will automatically be delivered by the Blacklight catalog/show
22
22
  # controller, and potentially automatically advertised in various places
23
- # that advertise available formats. (HTML link rel=alternate; Atom
23
+ # that advertise available formats. (HTML link rel=alternate; Atom
24
24
  # link rel=alterate; etc).
25
25
  #
26
26
  # Export formats are 'registered' by calling the #will_export_as method
@@ -40,21 +40,21 @@
40
40
  #
41
41
  module Blacklight::Document::Export
42
42
 
43
- ##
43
+ ##
44
44
  # Register exportable formats supported by the individual document.
45
45
  # Usually called by an extension in it's self.extended method, to
46
- # register the formats that extension can export.
47
- #
46
+ # register the formats that extension can export.
47
+ #
48
48
  # some_document.will_export_as(:some_format, "application/type") means
49
49
  # that the document (usually via an extension) has a method
50
50
  # "export_as_some_format" which returns a String of content that
51
- # is described by the mime content_type given.
52
- #
51
+ # is described by the mime content_type given.
52
+ #
53
53
  # The format name should ideally _already_ be registered with
54
54
  # Rails Mime::Type, in your application initializer, representing
55
55
  # the content type given. However, this method will attempt to
56
56
  # register it using Mime::Type.register_alias if it's not previously
57
- # registered. This is a bit sketchy though.
57
+ # registered. This is a bit sketchy though.
58
58
  def will_export_as(short_name, content_type = nil)
59
59
  #Lookup in Rails Mime::Type, register if needed, otherwise take
60
60
  # content-type from registration if needed.
@@ -62,34 +62,32 @@ module Blacklight::Document::Export
62
62
  content_type ||= Mime[short_name.to_sym]
63
63
  else
64
64
  # not registered, we need to register. Use register_alias to be least
65
- # likely to interfere with host app.
65
+ # likely to interfere with host app.
66
66
  Mime::Type.register_alias(content_type, short_name)
67
67
  end
68
68
 
69
69
  export_formats[short_name] = { content_type: content_type }
70
70
  end
71
-
71
+
72
72
  # Collects formats that this doc can export as.
73
- # Returns a hash, keys are format short-names that can
74
- # be exported. Hash includes:
75
- # :content-type => mime-content-type
76
- # maybe more later
77
73
  # To see if a given export format is supported by this document,
78
74
  # simply call document.export_formats.keys.include?(:my_format)
79
- # Then call #export_as! to do the export.
75
+ # Then call #export_as! to do the export.
76
+ # @return [Hash{Symbol=>Hash{Symbol=>String}}] keys are format short-names that can be exported, values are Hashes
77
+ # @example { :marc => { content_type: 'application/marc' } }
80
78
  def export_formats
81
79
  @export_formats ||= {}
82
80
  end
83
-
81
+
84
82
  # Call with a format shortname, export_as(:marc), simply returns
85
83
  # #export_as_marc . Later we may expand the design to allow you
86
84
  # to register an arbitrary method name instead of insisting
87
85
  # on the convention, so clients should call this method so
88
- # they'll still keep working if we do that.
86
+ # they'll still keep working if we do that.
89
87
  def export_as(short_name)
90
88
  send("export_as_#{short_name}")
91
89
  end
92
-
90
+
93
91
  def exports_as? short_name
94
92
  respond_to? "export_as_#{short_name}"
95
93
  end
data/app/models/search.rb CHANGED
@@ -1,26 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
  class Search < ActiveRecord::Base
3
-
4
3
  belongs_to_arguments = { optional: true } if Rails.version >= '5.0.0'
5
4
 
6
5
  belongs_to :user, belongs_to_arguments
7
6
 
8
7
  serialize :query_params
9
8
 
10
- if Blacklight::Utils.needs_attr_accessible?
11
- attr_accessible :query_params
12
- end
9
+ attr_accessible :query_params if Blacklight::Utils.needs_attr_accessible?
13
10
 
14
11
  # A Search instance is considered a saved search if it has a user_id.
15
12
  def saved?
16
13
  self.user_id?
17
14
  end
18
-
15
+
19
16
  # delete old, unsaved searches
20
17
  def self.delete_old_searches(days_old)
21
18
  raise ArgumentError, 'days_old is expected to be a number' unless days_old.is_a?(Numeric)
22
19
  raise ArgumentError, 'days_old is expected to be greater than 0' if days_old <= 0
23
- self.destroy_all(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old])
20
+ self.where(['created_at < ? AND user_id IS NULL', Time.zone.today - days_old]).destroy_all
24
21
  end
25
-
26
22
  end
@@ -22,7 +22,7 @@
22
22
  <%- @searches.each do |search| -%>
23
23
  <tr>
24
24
  <td><%= link_to_previous_search(search.query_params) %></td>
25
- <td><%= button_to t('blacklight.saved_searches.delete'), blacklight.forget_search_path(search.id) %></td>
25
+ <td><%= button_to t('blacklight.saved_searches.delete'), blacklight.forget_search_path(search.id), :class => 'btn btn-danger' %></td>
26
26
  </tr>
27
27
  <%- end -%>
28
28
  </table>
data/blacklight.gemspec CHANGED
@@ -40,6 +40,6 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency "rspec-collection_matchers", ">= 1.0"
41
41
  s.add_development_dependency "capybara", '~> 2.6.0'
42
42
  s.add_development_dependency "poltergeist"
43
- s.add_development_dependency 'engine_cart', '~> 0.8.0'
43
+ s.add_development_dependency 'engine_cart', '~> 0.10'
44
44
  s.add_development_dependency "equivalent-xml"
45
45
  end
@@ -42,5 +42,6 @@ module Blacklight
42
42
  'Cricket' => 'mms.mycricket.com'
43
43
  }
44
44
 
45
+ config.bookmarks_http_method = :post
45
46
  end
46
47
  end
@@ -10,22 +10,25 @@ module Blacklight
10
10
  # @param [ActionController::Parameters] params
11
11
  # @param [Blacklight::Config] blacklight_config
12
12
  def initialize(params, blacklight_config)
13
- if params.instance_of? Hash
14
- # This is an ActionView::TestCase workaround. Will be resolved by
15
- # https://github.com/rails/rails/pull/22913 (Rails > 4.2.5)
16
- @params = params.with_indifferent_access
17
- else
13
+ if params.respond_to?(:to_unsafe_h)
18
14
  # This is the typical (not-ActionView::TestCase) code path.
19
15
  @params = params.to_unsafe_h
20
16
  # In Rails 5 to_unsafe_h returns a HashWithIndifferentAccess, in Rails 4 it returns Hash
21
17
  @params = @params.with_indifferent_access if @params.instance_of? Hash
18
+ elsif params.is_a? Hash
19
+ # This is an ActionView::TestCase workaround for Rails 4.2.
20
+ @params = params.dup.with_indifferent_access
21
+ else
22
+ @params = params.dup.to_h.with_indifferent_access
22
23
  end
24
+
23
25
  @blacklight_config = blacklight_config
24
26
  end
25
27
 
26
- def to_h
28
+ def to_hash
27
29
  @params
28
30
  end
31
+ alias to_h to_hash
29
32
 
30
33
  def reset
31
34
  Blacklight::SearchState.new(ActionController::Parameters.new, blacklight_config)
@@ -112,7 +115,7 @@ module Blacklight
112
115
  # @yield [params] The merged parameters hash before being sanitized
113
116
  def params_for_search(params_to_merge={}, &block)
114
117
  # params hash we'll return
115
- my_params = params.dup.merge(params_to_merge.dup)
118
+ my_params = params.dup.merge(Blacklight::SearchState.new(params_to_merge, blacklight_config))
116
119
 
117
120
  if block_given?
118
121
  yield my_params
@@ -1,6 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  describe BookmarksController do
4
+ describe '#blacklight_config' do
5
+ it 'uses POST requests for querying solr' do
6
+ expect(@controller.blacklight_config.http_method).to eq :post
7
+ end
8
+ end
9
+
4
10
  # jquery 1.9 ajax does error callback if 200 returns empty body. so use 204 instead.
5
11
  describe "update" do
6
12
  it "has a 200 status code when creating a new one" do