blacklight 6.21.0 → 6.22.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
  SHA256:
3
- metadata.gz: 481b96adfac07b1cb0009bc9969f299a3a5bab9f519b38c5f0b0f1ccd7a45ec6
4
- data.tar.gz: 0c237ece3ec9a48dfd7ddfa45086ca64c807bef013f5f2a0357f47bebe84b0be
3
+ metadata.gz: fd14b6772e7c5627ce2b623fba876af4d008965be530552de9d3b879edada1f9
4
+ data.tar.gz: dbc0fe7d619a9259adabe10a8a92655ec56b2c4b7f00474d89914b86e10740f5
5
5
  SHA512:
6
- metadata.gz: b94d6eb3e43c0fa7d5144370f43e3990491e5014977258782a775939bc12610b5fd7aa1c5521e3bbfb51785f652ca1fb8afdefd9f88ed078f56fdf3130152f20
7
- data.tar.gz: 7dfc79605ae0f1763eed7322273dcdb1b66c9655c94522a5795dc9d122c412fb855aac1ecc43f43bc9b0eb7a0a037c494769f4265b4bfa2418ccef6305583c2a
6
+ metadata.gz: c4bd4e37af22eb9055ce3a6fb596f607aed1bedea8a215bebfbaf7863f16f8dac2d852528520116c1518daa0277168d92ab2599d5d8c274a2b8afe19f3d95a84
7
+ data.tar.gz: 7670f38bf4afe72c7697f4dbcd095aadf9cdb858659419c9f1979cf19fb25c83e0fc0736a0a55cba86a5b6fd4abec420c886f0a1f454c5db37e8a395d66a840b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.21.0
1
+ 6.22.0
@@ -144,6 +144,22 @@ module Blacklight::Document
144
144
  def unique_key
145
145
  @unique_key ||= 'id'
146
146
  end
147
+
148
+ # Define an attribute reader on a document model
149
+ # @Example
150
+ # class SolrDocument
151
+ # include Blacklight::Solr::Document
152
+ # attribute :title, Blacklight::Types::String, 'title_tesim'
153
+ # end
154
+ #
155
+ # doc = SolrDocument.new(title_tesim: ["One flew over the cuckoo's nest"])
156
+ # doc.title
157
+ # #=> "One flew over the cuckoo's nest"
158
+ def attribute(name, type, field)
159
+ define_method name do
160
+ type.coerce(self[field])
161
+ end
162
+ end
147
163
  end
148
164
 
149
165
  private
@@ -0,0 +1,28 @@
1
+ module Blacklight
2
+ # These are data types that blacklight can use to coerce values from the index
3
+ module Types
4
+ class Array
5
+ def self.coerce(input)
6
+ ::Array.wrap(input)
7
+ end
8
+ end
9
+
10
+ class String
11
+ def self.coerce(input)
12
+ ::Array.wrap(input).first
13
+ end
14
+ end
15
+
16
+ class Date
17
+ def self.coerce(input)
18
+ field = String.coerce(input)
19
+ return if field.blank?
20
+ begin
21
+ ::Date.parse(field)
22
+ rescue ArgumentError
23
+ Rails.logger.info "Unable to parse date: #{field.first.inspect}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -7,7 +7,7 @@
7
7
  </button>
8
8
  <ul class="dropdown-menu" role="menu">
9
9
  <%- per_page_options_for_select.each do |(label, count)| %>
10
- <li><%= link_to(label, url_for(search_state.params_for_search(per_page: count))) %></li>
10
+ <li role="menuitem"><%= link_to(label, url_for(search_state.params_for_search(per_page: count))) %></li>
11
11
  <%- end -%>
12
12
  </ul>
13
13
  </div>
@@ -6,7 +6,7 @@
6
6
 
7
7
  <ul class="dropdown-menu" role="menu">
8
8
  <%- active_sort_fields.each do |sort_key, field_config| %>
9
- <li><%= link_to(sort_field_label(sort_key), url_for(search_state.params_for_search(sort: sort_key))) %></li>
9
+ <li role="menuitem"><%= link_to(sort_field_label(sort_key), url_for(search_state.params_for_search(sort: sort_key))) %></li>
10
10
  <%- end -%>
11
11
  </ul>
12
12
  </div>
@@ -18,10 +18,34 @@ RSpec.describe SolrDocument do
18
18
  it { is_expected.to eq ['Book'] }
19
19
  end
20
20
  end
21
-
21
+
22
22
  describe "#id" do
23
23
  subject { solrdoc.id }
24
24
  it { is_expected.to eq '00282214' }
25
25
  end
26
26
  end
27
+
28
+ describe '.attribute' do
29
+ subject(:title) { document.title }
30
+ let(:doc_class) do
31
+ Class.new(SolrDocument) do
32
+ attribute :title, Blacklight::Types::String, 'title_tesim'
33
+ attribute :author, Blacklight::Types::Array, 'author_tesim'
34
+ attribute :date, Blacklight::Types::Date, 'date_dtsi'
35
+
36
+ end
37
+ end
38
+ let(:document) do
39
+ doc_class.new(id: '123',
40
+ title_tesim: ['Good Omens'],
41
+ author_tesim: ['Neil Gaiman', 'Terry Pratchett'],
42
+ date_dtsi: '1990-01-01T00:00:00Z')
43
+ end
44
+
45
+ it "casts the attributes" do
46
+ expect(document.title).to eq 'Good Omens'
47
+ expect(document.author).to eq ['Neil Gaiman', 'Terry Pratchett']
48
+ expect(document.date).to eq Date.new(1990)
49
+ end
50
+ end
27
51
  end
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: 6.21.0
4
+ version: 6.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2019-11-08 00:00:00.000000000 Z
20
+ date: 2020-01-29 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -478,6 +478,7 @@ files:
478
478
  - app/presenters/blacklight/rendering/terminator.rb
479
479
  - app/presenters/blacklight/show_presenter.rb
480
480
  - app/services/blacklight/field_retriever.rb
481
+ - app/values/blacklight/types.rb
481
482
  - app/views/_flash_msg.html.erb
482
483
  - app/views/_user_util_links.html.erb
483
484
  - app/views/blacklight/nav/_bookmark.html.erb