blacklight 7.11.1 → 7.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +89 -0
  3. data/.rubocop.yml +11 -0
  4. data/.solr_wrapper.yml +5 -0
  5. data/VERSION +1 -1
  6. data/app/builders/blacklight/action_builder.rb +6 -0
  7. data/app/components/blacklight/constraint_component.html.erb +5 -0
  8. data/app/components/blacklight/constraint_component.rb +13 -0
  9. data/app/components/blacklight/constraint_layout_component.rb +2 -1
  10. data/app/components/blacklight/constraints_component.html.erb +10 -0
  11. data/app/components/blacklight/constraints_component.rb +67 -0
  12. data/app/components/blacklight/document/action_component.html.erb +9 -0
  13. data/app/components/blacklight/document/action_component.rb +38 -0
  14. data/app/components/blacklight/document/actions_component.html.erb +13 -0
  15. data/app/components/blacklight/document/actions_component.rb +26 -0
  16. data/app/components/blacklight/document/bookmark_component.html.erb +1 -1
  17. data/app/components/blacklight/document/bookmark_component.rb +8 -0
  18. data/app/components/blacklight/document/citation_component.html.erb +4 -2
  19. data/app/components/blacklight/document/citation_component.rb +8 -1
  20. data/app/components/blacklight/document/group_component.html.erb +9 -0
  21. data/app/components/blacklight/document/group_component.rb +26 -0
  22. data/app/components/blacklight/document/more_like_this_component.rb +2 -0
  23. data/app/components/blacklight/document/thumbnail_component.html.erb +12 -0
  24. data/app/components/blacklight/document/thumbnail_component.rb +25 -0
  25. data/app/components/blacklight/document_component.html.erb +1 -0
  26. data/app/components/blacklight/document_component.rb +41 -27
  27. data/app/components/blacklight/facet_field_component.html.erb +1 -0
  28. data/app/components/blacklight/facet_field_filter_component.html.erb +12 -0
  29. data/app/components/blacklight/facet_field_filter_component.rb +25 -0
  30. data/app/components/blacklight/facet_field_pagination_component.html.erb +19 -0
  31. data/app/components/blacklight/facet_field_pagination_component.rb +17 -0
  32. data/app/components/blacklight/facet_item_component.rb +4 -8
  33. data/app/components/blacklight/response/facet_group_component.html.erb +3 -1
  34. data/app/components/blacklight/response/facet_group_component.rb +8 -1
  35. data/app/components/blacklight/response/pagination_component.rb +3 -0
  36. data/app/components/blacklight/response/sort_component.html.erb +1 -1
  37. data/app/components/blacklight/response/spellcheck_component.rb +9 -2
  38. data/app/components/blacklight/response/view_type_component.html.erb +11 -0
  39. data/app/components/blacklight/response/view_type_component.rb +36 -0
  40. data/app/components/blacklight/search_bar_component.html.erb +10 -8
  41. data/app/components/blacklight/search_bar_component.rb +20 -1
  42. data/app/components/blacklight/search_context_component.rb +6 -2
  43. data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
  44. data/app/components/blacklight/system/flash_message_component.html.erb +4 -0
  45. data/app/components/blacklight/system/flash_message_component.rb +24 -0
  46. data/app/controllers/concerns/blacklight/catalog.rb +10 -4
  47. data/app/controllers/concerns/blacklight/controller.rb +12 -3
  48. data/app/controllers/concerns/blacklight/facet.rb +19 -5
  49. data/app/controllers/concerns/blacklight/search_context.rb +2 -2
  50. data/app/controllers/concerns/blacklight/search_fields.rb +7 -1
  51. data/app/controllers/concerns/blacklight/searchable.rb +1 -1
  52. data/app/helpers/blacklight/blacklight_helper_behavior.rb +127 -17
  53. data/app/helpers/blacklight/catalog_helper_behavior.rb +36 -5
  54. data/app/helpers/blacklight/component_helper_behavior.rb +36 -6
  55. data/app/helpers/blacklight/configuration_helper_behavior.rb +33 -11
  56. data/app/helpers/blacklight/facets_helper_behavior.rb +39 -10
  57. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +5 -0
  58. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +35 -16
  59. data/app/helpers/blacklight/render_partials_helper_behavior.rb +10 -5
  60. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +4 -2
  61. data/app/helpers/blacklight/suggest_helper_behavior.rb +1 -0
  62. data/app/helpers/blacklight/url_helper_behavior.rb +23 -3
  63. data/app/models/blacklight/icon.rb +0 -1
  64. data/app/models/concerns/blacklight/document.rb +1 -1
  65. data/app/models/concerns/blacklight/suggest/response.rb +1 -1
  66. data/app/models/record_mailer.rb +1 -1
  67. data/app/presenters/blacklight/document_presenter.rb +46 -1
  68. data/app/presenters/blacklight/facet_field_presenter.rb +3 -1
  69. data/app/presenters/blacklight/facet_item_presenter.rb +14 -2
  70. data/app/presenters/blacklight/field_presenter.rb +9 -6
  71. data/app/presenters/blacklight/index_presenter.rb +2 -2
  72. data/app/presenters/blacklight/json_presenter.rb +3 -1
  73. data/app/presenters/blacklight/rendering/link_to_facet.rb +3 -1
  74. data/app/presenters/blacklight/show_presenter.rb +4 -34
  75. data/app/presenters/blacklight/thumbnail_presenter.rb +5 -1
  76. data/app/services/blacklight/document_factory.rb +3 -0
  77. data/app/services/blacklight/field_retriever.rb +18 -4
  78. data/app/services/blacklight/search_service.rb +13 -12
  79. data/app/values/blacklight/types.rb +1 -1
  80. data/app/views/bookmarks/_tools.html.erb +12 -7
  81. data/app/views/catalog/_bookmark_control.html.erb +1 -1
  82. data/app/views/catalog/_constraints.html.erb +12 -7
  83. data/app/views/catalog/_document.atom.builder +9 -6
  84. data/app/views/catalog/_document.rss.builder +4 -2
  85. data/app/views/catalog/_facet_index_navigation.html.erb +1 -10
  86. data/app/views/catalog/_facet_pagination.html.erb +1 -19
  87. data/app/views/catalog/_facets.html.erb +1 -1
  88. data/app/views/catalog/_group.html.erb +1 -9
  89. data/app/views/catalog/_index.html.erb +1 -1
  90. data/app/views/catalog/_search_form.html.erb +1 -1
  91. data/app/views/catalog/_search_results.html.erb +1 -1
  92. data/app/views/catalog/_show.html.erb +1 -1
  93. data/app/views/catalog/_show_header.html.erb +1 -1
  94. data/app/views/catalog/_show_main_content.html.erb +2 -2
  95. data/app/views/catalog/_show_tools.html.erb +12 -8
  96. data/app/views/catalog/_start_over.html.erb +1 -1
  97. data/app/views/catalog/_thumbnail.html.erb +1 -5
  98. data/app/views/catalog/_view_type_group.html.erb +5 -13
  99. data/app/views/catalog/index.json.jbuilder +10 -6
  100. data/app/views/catalog/show.json.jbuilder +1 -1
  101. data/app/views/shared/_flash_msg.html.erb +1 -15
  102. data/blacklight.gemspec +1 -0
  103. data/config/locales/blacklight.ca.yml +241 -0
  104. data/lib/blacklight/abstract_repository.rb +13 -4
  105. data/lib/blacklight/configuration.rb +11 -5
  106. data/lib/blacklight/configuration/display_field.rb +50 -0
  107. data/lib/blacklight/configuration/facet_field.rb +65 -1
  108. data/lib/blacklight/configuration/field.rb +13 -0
  109. data/lib/blacklight/configuration/fields.rb +1 -1
  110. data/lib/blacklight/configuration/index_field.rb +5 -0
  111. data/lib/blacklight/configuration/search_field.rb +8 -0
  112. data/lib/blacklight/configuration/show_field.rb +5 -0
  113. data/lib/blacklight/configuration/sort_field.rb +3 -0
  114. data/lib/blacklight/configuration/tool_config.rb +5 -0
  115. data/lib/blacklight/configuration/view_config.rb +37 -0
  116. data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -1
  117. data/lib/blacklight/search_builder.rb +13 -23
  118. data/lib/blacklight/search_state.rb +86 -72
  119. data/lib/blacklight/search_state/filter_field.rb +122 -0
  120. data/lib/blacklight/solr/repository.rb +4 -4
  121. data/lib/blacklight/solr/response.rb +1 -1
  122. data/lib/blacklight/solr/search_builder_behavior.rb +71 -51
  123. data/lib/generators/blacklight/templates/catalog_controller.rb +8 -7
  124. data/package.json +4 -0
  125. data/spec/components/blacklight/document/action_component_spec.rb +43 -0
  126. data/spec/components/blacklight/document/group_component_spec.rb +45 -0
  127. data/spec/components/blacklight/document_component_spec.rb +23 -0
  128. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +0 -1
  129. data/spec/components/blacklight/system/flash_message_component_spec.rb +54 -0
  130. data/spec/controllers/blacklight/search_fields_spec.rb +2 -0
  131. data/spec/controllers/catalog_controller_spec.rb +2 -0
  132. data/spec/features/search_spec.rb +0 -5
  133. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +1 -2
  134. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +6 -1
  135. data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +2 -0
  136. data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +2 -0
  137. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +3 -1
  138. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +2 -0
  139. data/spec/helpers/blacklight_helper_spec.rb +10 -0
  140. data/spec/helpers/catalog_helper_spec.rb +4 -4
  141. data/spec/lib/blacklight/configuration/facet_field_spec.rb +17 -0
  142. data/spec/lib/blacklight/configuration/view_config_spec.rb +15 -0
  143. data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +9 -0
  144. data/spec/lib/blacklight/search_state/filter_field_spec.rb +125 -0
  145. data/spec/lib/blacklight/search_state_spec.rb +132 -3
  146. data/spec/models/blacklight/configuration_spec.rb +8 -0
  147. data/spec/models/blacklight/search_builder_spec.rb +1 -1
  148. data/spec/models/blacklight/solr/search_builder_spec.rb +40 -2
  149. data/spec/presenters/blacklight/field_presenter_spec.rb +30 -5
  150. data/spec/services/blacklight/search_service_spec.rb +1 -5
  151. data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -1
  152. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -2
  153. data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
  154. data/spec/views/catalog/show.json.jbuilder_spec.rb +1 -0
  155. data/tasks/blacklight.rake +27 -12
  156. metadata +53 -4
  157. data/.npmignore +0 -23
  158. data/.travis.yml +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74d6e5485343fa8fc02b71d94e374d2f2d0a49f05e9bbf2e2226fe02088213f4
4
- data.tar.gz: d1894865278720fc03af712e6cb424eaa1f3c30aa0f71666be7a301052663562
3
+ metadata.gz: f57c80d2b77a3b8bd0d536f3800fad183aa43d5aec10b71f921dfb23cbb6b26c
4
+ data.tar.gz: 9748a16edba74f0a1f24b1d6813987196088e1d217dd621b6455ca235aec37be
5
5
  SHA512:
6
- metadata.gz: 9d40718c50283de79a47a70e77c3cdd5e13a92edf1eb657d749c96f25fd473523a09f4d68e594adf3d2f5cb3a6e249d6ebd61bf7ec349a4bc97ffad8b213fc5e
7
- data.tar.gz: d3732c39e9672c23943b01aef361d29fc7cfb3f1f9d6e243770b72cc6ac61677cee2f478ae8cf50120d51d3978eda85492d4f386a15820b04d6350bfac53219c
6
+ metadata.gz: af48c90bc958243c5177660307c059a974c647f27b1fd890061e6efbba253b68d4690e46547b488fee11fe92140db88d39051a0a666e656f478d89e9650fd541
7
+ data.tar.gz: '019a8e8383aff4582a98a74348c2b40cf7e57aa121213fbd43702c13ff66f2f30c455d43c06dfa0f26c39ebc74f9d34ff40f72b72ed30bdd180384f58deb25cb'
@@ -0,0 +1,89 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ lint:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: 2.7
25
+ - name: Install dependencies
26
+ run: bundle install
27
+ - name: Run linter
28
+ run: bundle exec rake rubocop
29
+ test:
30
+ runs-on: ubuntu-latest
31
+ strategy:
32
+ matrix:
33
+ ruby: [2.6, 2.7]
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - name: Set up Ruby
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ ruby-version: ${{ matrix.ruby }}
40
+ - name: Install dependencies
41
+ run: bundle install
42
+ - name: Run tests
43
+ run: bundle exec rake ci
44
+ env:
45
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
46
+ test_rails5:
47
+ runs-on: ubuntu-latest
48
+ strategy:
49
+ matrix:
50
+ ruby: [2.5, 2.6]
51
+ steps:
52
+ - uses: actions/checkout@v2
53
+ - name: Set up Ruby
54
+ uses: ruby/setup-ruby@v1
55
+ with:
56
+ ruby-version: ${{ matrix.ruby }}
57
+ - name: Install dependencies
58
+ run: bundle install
59
+ env:
60
+ RAILS_VERSION: 5.2.4.2
61
+ - name: Run tests
62
+ run: bundle exec rake ci
63
+ env:
64
+ RAILS_VERSION: 5.2.4.2
65
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
66
+ api_test:
67
+ runs-on: ubuntu-latest
68
+ strategy:
69
+ matrix:
70
+ ruby: [2.7]
71
+ steps:
72
+ - uses: actions/checkout@v2
73
+ - name: Set up Ruby
74
+ uses: ruby/setup-ruby@v1
75
+ with:
76
+ ruby-version: ${{ matrix.ruby }}
77
+ - name: Install dependencies
78
+ run: bundle install
79
+ - name: Run tests
80
+ run: bundle exec rake ci
81
+ env:
82
+ BLACKLIGHT_API_TEST: true
83
+ ENGINE_CART_RAILS_OPTIONS: '--api --skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-action-cable --skip-coffee --skip-test'
84
+ docker_build:
85
+ runs-on: ubuntu-latest
86
+ steps:
87
+ - uses: actions/checkout@v2
88
+ - name: Build docker image
89
+ run: docker-compose build app
@@ -29,6 +29,7 @@ Layout/IndentationConsistency:
29
29
  Metrics/BlockLength:
30
30
  Exclude:
31
31
  - "app/views/catalog/index.json.jbuilder"
32
+ - "app/views/catalog/_document.atom.builder"
32
33
  - "lib/railties/blacklight.rake"
33
34
  - "tasks/blacklight.rake"
34
35
  - "spec/**/*"
@@ -36,12 +37,19 @@ Metrics/BlockLength:
36
37
  Metrics/ClassLength:
37
38
  Exclude:
38
39
  - "lib/blacklight/configuration.rb"
40
+ - "lib/blacklight/search_builder.rb"
41
+ - "lib/blacklight/search_state.rb"
39
42
 
40
43
  Layout/LineLength:
41
44
  Max: 200
42
45
  Exclude:
43
46
  - 'spec/**/*'
44
47
 
48
+ Metrics/ModuleLength:
49
+ Exclude:
50
+ - 'app/controllers/concerns/blacklight/catalog.rb'
51
+ - 'lib/blacklight/solr/search_builder_behavior.rb'
52
+
45
53
  Naming/HeredocDelimiterNaming:
46
54
  Enabled: false
47
55
 
@@ -57,6 +65,9 @@ Naming/PredicateName:
57
65
  Rails:
58
66
  Enabled: true
59
67
 
68
+ Rails/ApplicationMailer:
69
+ Enabled: false
70
+
60
71
  # https://github.com/rubocop-hq/rubocop/issues/6439
61
72
  Style/AccessModifierDeclarations:
62
73
  Enabled: false
@@ -0,0 +1,5 @@
1
+ # Place any default configuration for solr_wrapper here
2
+ # port: 8983
3
+ collection:
4
+ dir: lib/generators/blacklight/templates/solr/conf
5
+ name: blacklight-core
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.11.1
1
+ 7.13.2
@@ -4,6 +4,12 @@ module Blacklight
4
4
  # Dynamically creates methods on the given controller (typically CatalogController)
5
5
  # for handling configured show tools
6
6
  class ActionBuilder
7
+ # @param [Object] klass
8
+ # @param [String] name
9
+ # @param [Hash] opts
10
+ # @option opts [Symbol] callback
11
+ # @option opts [Symbol] validator
12
+ # @option opts [Boolean] define_method
7
13
  def initialize(klass, name, opts)
8
14
  @klass = klass
9
15
  @name = name
@@ -0,0 +1,5 @@
1
+ <%= render(@layout.new(
2
+ classes: (Array(@classes) + ["filter-#{@facet_item_presenter.facet_config.key.parameterize}"]).join(' '),
3
+ label: @facet_item_presenter.field_label,
4
+ value: @facet_item_presenter.label,
5
+ remove_path: @facet_item_presenter.remove_href)) %>
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class ConstraintComponent < ::ViewComponent::Base
5
+ with_collection_parameter :facet_item_presenter
6
+
7
+ def initialize(facet_item_presenter:, classes: 'filter', layout: Blacklight::ConstraintLayoutComponent)
8
+ @facet_item_presenter = facet_item_presenter
9
+ @classes = classes
10
+ @layout = layout
11
+ end
12
+ end
13
+ end
@@ -2,11 +2,12 @@
2
2
 
3
3
  module Blacklight
4
4
  class ConstraintLayoutComponent < ::ViewComponent::Base
5
- def initialize(value:, label: nil, remove_path: nil, classes: nil)
5
+ def initialize(value:, label: nil, remove_path: nil, classes: nil, search_state: nil)
6
6
  @value = value
7
7
  @label = label
8
8
  @remove_path = remove_path
9
9
  @classes = Array(classes).join(' ')
10
+ @search_state = search_state
10
11
  end
11
12
 
12
13
  def render?
@@ -0,0 +1,10 @@
1
+ <%= content_tag :div, id: @id, class: @classes do %>
2
+ <h2 class="sr-only"><%= t('blacklight.search.search_constraints_header') %></h2>
3
+
4
+ <%= link_to t('blacklight.search.start_over'), start_over_path, class: "catalog_startOverLink btn btn-primary" %>
5
+
6
+ <span class="constraints-label sr-only"><%= t('blacklight.search.filters.title') %></span>
7
+ <%= query_constraints_area || query_constraints %>
8
+ <%= facet_constraints_area || facet_constraints %>
9
+ <%= additional_constraints %>
10
+ <% end %>
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ class ConstraintsComponent < ::ViewComponent::Base
5
+ with_content_areas :query_constraints_area, :facet_constraints_area, :additional_constraints
6
+
7
+ def initialize(search_state:,
8
+ id: 'appliedParams', classes: 'clearfix constraints-container',
9
+ query_constraint_component: Blacklight::ConstraintLayoutComponent, facet_constraint_component: Blacklight::ConstraintComponent)
10
+ @search_state = search_state
11
+ @query_constraint_component = query_constraint_component
12
+ @facet_constraint_component = facet_constraint_component
13
+ @id = id
14
+ @classes = classes
15
+ end
16
+
17
+ def query_constraints
18
+ return if @search_state.query_param.blank?
19
+
20
+ Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) do
21
+ @view_context.render(
22
+ @query_constraint_component.new(
23
+ search_state: @search_state,
24
+ value: @search_state.query_param,
25
+ label: @view_context.constraint_query_label(@search_state.params),
26
+ remove_path: @view_context.remove_constraint_url(@search_state),
27
+ classes: 'query'
28
+ )
29
+ )
30
+ end
31
+ end
32
+
33
+ def facet_constraints
34
+ @view_context.render(@facet_constraint_component.with_collection(facet_item_presenters))
35
+ end
36
+
37
+ def start_over_path
38
+ Deprecation.silence(Blacklight::UrlHelperBehavior) do
39
+ @view_context.start_over_path
40
+ end
41
+ end
42
+
43
+ def render?
44
+ Deprecation.silence(Blacklight::RenderConstraintsHelperBehavior) { @view_context.query_has_constraints? }
45
+ end
46
+
47
+ private
48
+
49
+ def facet_item_presenters
50
+ Deprecation.silence(Blacklight::SearchState) do
51
+ @search_state.filter_params.each_pair.flat_map do |facet, values|
52
+ facet_config = @view_context.facet_configuration_for_field(facet)
53
+
54
+ Array(values).map do |val|
55
+ next if val.blank? # skip empty string
56
+
57
+ facet_item_presenter(facet_config, val, facet)
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ def facet_item_presenter(facet_config, facet_item, facet_field)
64
+ Blacklight::FacetItemPresenter.new(facet_item, facet_config, @view_context, facet_field)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,9 @@
1
+ <% if using_default_document_action? %>
2
+ <%= link_to label,
3
+ url,
4
+ id: @id,
5
+ class: 'nav-link',
6
+ data: {}.merge(({ blacklight_modal: "trigger" } if @action.modal != false) || {}) %>
7
+ <% else %>
8
+ <%= @view_context.render(partial: @action.partial || @action.name.to_s, locals: { document: @document, document_action_config: @action }.merge(@options)) %>
9
+ <% end %>
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Document
5
+ # Render a bookmark widget to bookmark / unbookmark a document
6
+ class ActionComponent < ::ViewComponent::Base
7
+ with_collection_parameter :action
8
+
9
+ # @param [Blacklight::Document] document
10
+ def initialize(document:, action:, options: {}, url_opts: {}, id: nil)
11
+ @document = document
12
+ @action = action
13
+ @options = options
14
+ @url_opts = url_opts
15
+ @id = id || @action.fetch(:id, "#{@action.name}Link")
16
+ end
17
+
18
+ def using_default_document_action?
19
+ return true if @action.component
20
+ return false unless @action.partial == 'document_action'
21
+
22
+ @view_context.partial_from_blacklight?(@action.partial)
23
+ end
24
+
25
+ def label
26
+ Deprecation.silence(Blacklight::ComponentHelperBehavior) do
27
+ @view_context.document_action_label(@action.name, @action)
28
+ end
29
+ end
30
+
31
+ def url
32
+ Deprecation.silence(Blacklight::ComponentHelperBehavior) do
33
+ @view_context.document_action_path(@action, @url_opts.merge(({ id: @document } if @document) || {}))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ <%= content_tag @tag, class: @classes do %>
2
+ <% @actions.each do |action| %>
3
+ <% result = capture { @view_context.render((action.component || Blacklight::Document::ActionComponent).new(action: action, document: @document, options: @options, url_opts: @url_opts)) } %>
4
+
5
+ <% if @wrapping_tag %>
6
+ <%= content_tag(@wrapping_tag, class: Array(@wrapping_classes) + [action.key]) do %>
7
+ <%= result %>
8
+ <% end %>
9
+ <% else %>
10
+ <%= result %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blacklight
4
+ module Document
5
+ # Render a bookmark widget to bookmark / unbookmark a document
6
+ class ActionsComponent < ::ViewComponent::Base
7
+ # @param [Blacklight::Document] document
8
+ # rubocop:disable Metrics/ParameterLists
9
+ def initialize(document: nil, actions: [], options: {}, url_opts: nil, tag: :div, classes: 'index-document-functions', wrapping_tag: nil, wrapping_classes: nil)
10
+ @document = document
11
+ @actions = actions
12
+ @tag = tag
13
+ @classes = classes
14
+ @options = options
15
+ @url_opts = url_opts
16
+ @wrapping_tag = wrapping_tag
17
+ @wrapping_classes = wrapping_classes
18
+ end
19
+ # rubocop:enable Metrics/ParameterLists
20
+
21
+ def render?
22
+ @actions.any?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,7 @@
1
1
  <%-
2
2
  # the data-doc-id attribute is used by our JS that converts to a checkbox/label.
3
3
  -%>
4
- <%= form_tag(@bookmark_path,
4
+ <%= form_tag(bookmark_path,
5
5
  method: bookmarked? ? :delete : :put,
6
6
  class: "bookmark-toggle",
7
7
  data: {
@@ -2,7 +2,11 @@
2
2
 
3
3
  module Blacklight
4
4
  module Document
5
+ # Render a bookmark widget to bookmark / unbookmark a document
5
6
  class BookmarkComponent < ::ViewComponent::Base
7
+ # @param [Blacklight::Document] document
8
+ # @param [Boolean] checked
9
+ # @param [Object] bookmark_path the rails route to use for bookmarks
6
10
  def initialize(document:, checked: nil, bookmark_path: nil)
7
11
  @document = document
8
12
  @checked = checked
@@ -14,6 +18,10 @@ module Blacklight
14
18
 
15
19
  @view_context.bookmarked? @document
16
20
  end
21
+
22
+ def bookmark_path
23
+ @bookmark_path || @view_context.bookmark_path(@document)
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -1,9 +1,11 @@
1
1
  <div>
2
2
  <h1 class="modal-title"><%= title %></h1>
3
3
 
4
- <%= @formats.each do |i18n_key, citation_method| %>
4
+ <% @formats.each do |i18n_key, citation_method| %>
5
5
  <h2><%= t(i18n_key) %></h2>
6
6
  <%= @document.send(citation_method).html_safe %>
7
- <% unless @formats.keys.last === i18n_key %><br/><br/><% end %>
7
+ <% unless @formats.keys.last === i18n_key %>
8
+ <br/><br/>
9
+ <% end %>
8
10
  <% end %>
9
11
  </div>
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Blacklight
4
4
  module Document
5
+ # Render citations for the document
5
6
  class CitationComponent < ::ViewComponent::Base
6
7
  DEFAULT_FORMATS = {
7
8
  'blacklight.citation.mla': :export_as_mla_citation_txt,
@@ -11,13 +12,19 @@ module Blacklight
11
12
 
12
13
  with_collection_parameter :document
13
14
 
15
+ # @param [Blacklight::Document] document
16
+ # @param [Hash<String => Symbol>] map of citation format names (suspiciously, i18n keys
17
+ # for them) to document methods that return the formatted citation.
14
18
  def initialize(document:, formats: DEFAULT_FORMATS)
15
19
  @document = document
16
20
  @formats = formats.select { |_k, v| @document.respond_to?(v) }
17
21
  end
18
22
 
23
+ # @return [String]
19
24
  def title
20
- @view_context.document_heading(@document)
25
+ Deprecation.silence(Blacklight::BlacklightHelperBehavior) do
26
+ @view_context.document_heading(@document)
27
+ end
21
28
  end
22
29
  end
23
30
  end