recourse 2.0.2 → 3.0.1

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: 60194be6140d65a8864c22b460e7887350d353f4d1c57d678659c71bafbd142c
4
- data.tar.gz: 7613666c954f8aedb3dd7798cd961a14c17f4518efa6a9fbd8cfebf5477a6b0b
3
+ metadata.gz: 00a9c1bf568e9a4d8865b558364d3aa001887eb2cdabafad876ec20497442099
4
+ data.tar.gz: d5e660c1b0ff23011704883345e5be94bfc8103e936ac55b8f7bcb7e17855898
5
5
  SHA512:
6
- metadata.gz: 7e354bc6c67f848bd7155dcf9c01eeb07817d337681d2d1b1f42025059bc41aa4b52f536af5de504f12a271b85db7142a89d593afe7c8f345b4b77e40700f2dc
7
- data.tar.gz: 51d1b0cc87aece205403feeeaf9f347b2f91840ca8bc55b0691ce3d074eca23c3d694e06baf5ccf5971fd1c202c1bcb0c982bcd4046e6805e0ded353941428eb
6
+ metadata.gz: 1787a883804dd4e8bfb15415190421f0e54984bd64250141a59b09becb8e90a5682037becce24f6997c5ef4a193ba1db8aa61763a92157329fe09ba2e6e73ce4
7
+ data.tar.gz: e1ab2bd8325350dcb8e723bdb379236a6697d64ea51498b36692a060efdb0cc033361a238678af1bccb5a7d4c7d8029bfe7866ef981ce73d24546fddaeb5a504
@@ -5,25 +5,25 @@ module SearchableHelper
5
5
  # @param [ApplicationRecord] model the model of each object returned by the search
6
6
  def search_form(q:, model:, url: url_for(model))
7
7
  search_form_for(q, search_form_params(url: url)) do |form|
8
- safe_join [filter_field_for(form, model:), search_field_for(form, model:)].compact
8
+ safe_join [*filter_fields_for(form, model:), search_field_for(form, model:)].compact
9
9
  end
10
10
  end
11
11
 
12
12
  # Highlights the search query within the text of the matched content.
13
- def search_highlight(content, model:)
14
- highlight content.to_s, params.dig(:q, model.search_field)
15
- end
13
+ def search_highlight(content, model:) = highlight content.to_s, params.dig(:q, model.search_field)
16
14
 
17
15
  private
18
16
 
19
- def filter_field_for(form, model:)
20
- method = model.filter_field
21
- choices = model.filter_choices
22
- options = { prompt: model.filter_prompt }
23
- form.select method, choices, options, filter_field_params if method && choices
17
+ def filter_fields_for(form, model:)
18
+ selects = model.filter_fields.map do |method, options = {}|
19
+ choices = options.delete :choices
20
+ form.select method, choices, options, filter_field_params if choices
21
+ end
22
+ safe_join selects.compact
24
23
  end
25
24
 
26
25
  def search_field_for(form, model:)
26
+ return unless model.search_field
27
27
  adorn = tag.svg width: 16, height: 16, viewBox: '0 0 16 16', xmlns: 'http://www.w3.org/2000/svg' do
28
28
  tag.path d: 'M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001q.044.06.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1 1 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0'
29
29
  end
@@ -33,7 +33,7 @@ private
33
33
 
34
34
  def search_form_params(url:)
35
35
  {
36
- url: url, class: 'col-8 sm:col-6 md:col-4 d-flex pe-4', role: 'search',
36
+ url: url, class: 'col-6 d-flex pe-4', role: 'search',
37
37
  data: { turbo_frame: :results, turbo_action: :advance },
38
38
  }
39
39
  end
@@ -26,16 +26,10 @@ module Recourse
26
26
  end
27
27
 
28
28
  # @note to be overriden by subclasses -- the name of the field to filter by.
29
- def filter_field
30
- end
31
-
32
- # @note to be overriden by subclasses -- the prompt for the field to filter by.
33
- def filter_prompt
34
- end
29
+ def filter_fields = {}
35
30
 
36
- # @note to be overriden by subclasses -- the values for the field to filter by.
37
- def filter_choices
38
- end
31
+ # Returns the names of all the search and filter fields.
32
+ def searchable_fields = [search_field, filter_fields.keys]
39
33
  end
40
34
  end
41
35
 
@@ -1,3 +1,3 @@
1
1
  module Recourse
2
- VERSION = '2.0.2'
2
+ VERSION = '3.0.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recourse
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo