pagy 4.7.1 → 4.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67bf0b9d4c13c5ca1e0698f6e4fd928e07eaad4fd3e8dfe2ef8d95612e5eb8d9
4
- data.tar.gz: 40fae4aadf56256885e813847a0df296bb857ea48ed629a49d6fd20092fe4dbf
3
+ metadata.gz: dfababb2b5f9594ebcf7827cde7c45e9073ba9a270ddca251714e0d8fa1ef711
4
+ data.tar.gz: b20c84d4099a7302d6324fa671001051275d01d363eff5b6007d4240b1700d8a
5
5
  SHA512:
6
- metadata.gz: c2408b52d3e5cf97ea5d32cc2da809f2e9e38802767555b3ecd94a7947d9e52adf45e623c992acf2c1a12dcacf081f01823bc0e59fd97a6c980d68d08af1b8ea
7
- data.tar.gz: d0ffa69cc1cff5e0d5eb767e77d8abe63fe1df47f19c6535677c481c87ea3bd0fdc81042571fb02b3015b72377d9a7b9aa738bce0353d8e8ec62120608927ffe
6
+ metadata.gz: ba6eadeb0285c6dcf1ae98dfe58fe8844916f3d517813fbc8add6b5b0e0d3933234e26eb15c9fa931c7fccd256844df26d72694f23a3596fa874c3288a4fd4aa
7
+ data.tar.gz: 35d1b022f3d4c85521e69b960be16812c5ffe276e1a015e6fa9ce1630f1abf05486908568585dcd0257fee4d2fb304fe6296839404a9091e54a3c6fa10d0068b
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017-2020 Domizio Demichelis
3
+ Copyright (c) 2017-2021 Domizio Demichelis
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/lib/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (4.7.1)
3
+ # Pagy initializer file (4.10.1)
4
4
  # Customize only what you really need and notice that Pagy works also without any of the following lines.
5
5
  # Should you just cherry pick part of this file, please maintain the require-order of the extras
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '4.7.1'
5
+ Pagy.version = '4.10.1'
6
6
 
7
7
  Pagy.delay = 100
8
8
 
@@ -0,0 +1,26 @@
1
+ # :arabic pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
3
+ ar:
4
+ pagy:
5
+
6
+ item_name:
7
+ zero: "صفر"
8
+ one: "عنصر"
9
+ two: "عنصرين"
10
+ few: "قليل"
11
+ many: "كثير"
12
+ other: "عناصر"
13
+
14
+ nav:
15
+ prev: "‹ السابق"
16
+ next: "التالي ›"
17
+ gap: "…"
18
+
19
+ info:
20
+ no_items: "لا يوجد %{item_name}"
21
+ single_page: "عرض <b>%{count}</b> %{item_name}"
22
+ multiple_pages: "عرض %{item_name} <b>%{from}-%{to}</b> من اجمالي <b>%{count}</b>"
23
+
24
+ combo_nav_js: "الصفحة %{page_input} من %{pages}"
25
+
26
+ items_selector_js: "عرض %{items_input} %{item_name} لكل صفحة"
@@ -19,6 +19,20 @@ from12to14 = [12,13,14].freeze
19
19
  p11n = {
20
20
  one_other: -> (n){ n == 1 ? 'one' : 'other' }, # default
21
21
 
22
+ arabic: lambda do |n|
23
+ n ||= 0
24
+ mod100 = n % 100
25
+
26
+ case
27
+ when n == 0 then 'zero' # rubocop:disable Style/NumericPredicate
28
+ when n == 1 then 'one'
29
+ when n == 2 then 'two'
30
+ when (3..10).to_a.include?(mod100) then 'few'
31
+ when (11..99).to_a.include?(mod100) then 'many'
32
+ else 'other'
33
+ end
34
+ end,
35
+
22
36
  east_slavic: lambda do |n|
23
37
  n ||= 0
24
38
  mod10 = n % 10
@@ -32,14 +46,6 @@ p11n = {
32
46
  end
33
47
  end,
34
48
 
35
- west_slavic: lambda do |n|
36
- case n
37
- when 1 then 'one'
38
- when 2, 3, 4 then 'few'
39
- else 'other'
40
- end
41
- end,
42
-
43
49
  one_two_other: lambda do |n|
44
50
  case n
45
51
  when 1 then 'one'
@@ -63,7 +69,16 @@ p11n = {
63
69
  when (from0to1 + from5to9).include?(mod10) || from12to14.include?(mod100) then 'many'
64
70
  else 'other'
65
71
  end
72
+ end,
73
+
74
+ west_slavic: lambda do |n|
75
+ case n
76
+ when 1 then 'one'
77
+ when 2, 3, 4 then 'few'
78
+ else 'other'
79
+ end
66
80
  end
81
+
67
82
  }
68
83
 
69
84
  # Hash of locale/pluralization pairs
@@ -71,6 +86,7 @@ p11n = {
71
86
  # The default pluralization for locales not explicitly listed here
72
87
  # is the :one_other pluralization proc (used for English)
73
88
  plurals = Hash.new(p11n[:one_other]).tap do |hash|
89
+ hash['ar'] = p11n[:arabic]
74
90
  hash['bs'] = p11n[:east_slavic]
75
91
  hash['cs'] = p11n[:west_slavic]
76
92
  hash['id'] = p11n[:other]
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # main class
7
7
  class Pagy
8
- VERSION = '4.7.1'
8
+ VERSION = '4.10.1'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -23,7 +23,7 @@ class Pagy
23
23
  # Merge and validate the options, do some simple arithmetic and set the instance variables
24
24
  def initialize(vars)
25
25
  @vars = VARS.merge( vars.delete_if{|k,v| VARS.key?(k) && (v.nil? || v == '') } )
26
- @vars[:fragment] = deprecated_var(:anchor, @vars[:anchor], :fragment, @vars[:fragment]) if @vars[:anchor]
26
+ @vars[:fragment] = Pagy.deprecated_var(:anchor, @vars[:anchor], :fragment, @vars[:fragment]) if @vars[:anchor]
27
27
 
28
28
  INSTANCE_VARS_MIN.each do |name,min|
29
29
  raise VariableError.new(self), "expected :#{name} >= #{min}; got #{@vars[name].inspect}" \
@@ -4,22 +4,22 @@ class Pagy
4
4
 
5
5
  # deprecated variables
6
6
  def deprecated_var(var, val, new_var, new_val)
7
- value = new_val || val
8
- Warning.warn %([PAGY WARNING] deprecated use of `#{var}` var will not be supported in 5.0! Use `#{new_var}: #{value.inspect}` instead.)
7
+ value = val || new_val
8
+ Warning.warn %([PAGY WARNING] deprecated use of '#{var}' var will not be supported in 5.0! Use '#{new_var}: #{value.inspect}' instead.)
9
9
  value
10
10
  end
11
11
 
12
12
  # deprecated pagy_url_for argument order
13
13
  def deprecated_order(pagy, page)
14
- Warning.warn '[PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.'
14
+ Warning.warn %([PAGY WARNING] inverted use of pagy/page in pagy_url_for will not be supported in 5.0! Use pagy_url_for(pagy, page) instead.)
15
15
  [page, pagy]
16
16
  end
17
17
 
18
18
 
19
19
  # deprecated posiitioal arguments
20
20
  def deprecated_arg(arg, val, new_key, new_val)
21
- value = new_val || val # we use the new_val if present
22
- Warning.warn %([PAGY WARNING] deprecated use of positional `#{arg}` arg will not be supported in 5.0! Use only the keyword arg `#{new_key}: #{value.inspect}` instead.)
21
+ value = val || new_val # we use the new_val if present
22
+ Warning.warn %([PAGY WARNING] deprecated use of positional '#{arg}' arg will not be supported in 5.0! Use only the keyword arg '#{new_key}: #{value.inspect}' instead.)
23
23
  value
24
24
  end
25
25
 
@@ -16,7 +16,9 @@ class Pagy
16
16
  Regexp.last_match(1)&.to_sym
17
17
  end
18
18
 
19
- def value = pagy.vars[variable]
19
+ def value
20
+ pagy.vars[variable]
21
+ end
20
22
  end
21
23
 
22
24
  # specific overflow error
@@ -66,7 +66,7 @@ class Pagy
66
66
  private
67
67
 
68
68
  def pagy_bulma_prev_next_html(pagy, link)
69
- html = if (p_prev = pagy.prev)
69
+ html = +if (p_prev = pagy.prev)
70
70
  link.call p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"'
71
71
  else
72
72
  %(<a class="pagination-previous" disabled>#{pagy_t 'pagy.nav.prev'}</a>)
@@ -25,10 +25,10 @@ class Pagy
25
25
  rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
26
26
  rels['last'] = pagy.last unless countless
27
27
  url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: true)
28
- hash = { 'Link' => rels.filter_map do |rel, num|
28
+ hash = { 'Link' => rels.map do |rel, num| # filter_map if ruby >=2.7
29
29
  next unless num
30
30
  [ rel, url_str.sub(PAGE_PLACEHOLDER, num.to_s) ]
31
- end.to_h }
31
+ end.compact.to_h }
32
32
  headers = pagy.vars[:headers]
33
33
  hash[headers[:page]] = pagy.page.to_s if headers[:page]
34
34
  hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
@@ -14,7 +14,9 @@ class Pagy
14
14
  end
15
15
 
16
16
  module UseI18nGem
17
- def pagy_t(key, **opts) = ::I18n.t(key, **opts)
17
+ def pagy_t(key, **opts)
18
+ ::I18n.t(key, **opts)
19
+ end
18
20
  end
19
21
  prepend UseI18nGem
20
22
 
@@ -40,7 +40,7 @@ class Pagy
40
40
  link = pagy_marked_link(pagy_link_proc(pagy, link_extra: link_extra))
41
41
  p_vars[:items] = p_items # restore the items
42
42
 
43
- html = %(<span#{p_id} class="pagy-items-selector-js" #{pagy_json_attr pagy, :items_selector, pagy.from, link}>)
43
+ html = +%(<span#{p_id} class="pagy-items-selector-js" #{pagy_json_attr pagy, :items_selector, pagy.from, link}>)
44
44
  input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
45
45
  html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
46
46
  items_input: input,
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pagy
4
+
5
+ VARS[:meilisearch_search_method] ||= :pagy_search
6
+
7
+ module Meilisearch
8
+ # returns an array used to delay the call of #search
9
+ # after the pagination variables are merged to the options
10
+ def pagy_meilisearch(term = nil, **vars)
11
+ [self, term, vars]
12
+ end
13
+ alias_method VARS[:meilisearch_search_method], :pagy_meilisearch
14
+ end
15
+
16
+ # create a Pagy object from a Meilisearch results
17
+ def self.new_from_meilisearch(results, vars={})
18
+ vars[:items] = results.raw_answer['limit']
19
+ vars[:page] = [results.raw_answer['offset'] / vars[:items], 1].max
20
+ vars[:count] = results.raw_answer['nbHits']
21
+ new(vars)
22
+ end
23
+
24
+ # Add specialized backend methods to paginate Meilisearch results
25
+ module Backend
26
+ private
27
+
28
+ # Return Pagy object and results
29
+ def pagy_meilisearch(pagy_search_args, vars = {})
30
+ model, term, options = pagy_search_args
31
+ vars = pagy_meilisearch_get_vars(nil, vars)
32
+ options[:limit] = vars[:items]
33
+ options[:offset] = (vars[:page] - 1) * vars[:items]
34
+ results = model.search(term, **options)
35
+ vars[:count] = results.raw_answer['nbHits']
36
+
37
+ pagy = Pagy.new(vars)
38
+ # with :last_page overflow we need to re-run the method in order to get the hits
39
+ return pagy_meilisearch(pagy_search_args, vars.merge(page: pagy.page)) \
40
+ if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
41
+
42
+ [ pagy, results ]
43
+ end
44
+
45
+ # Sub-method called only by #pagy_meilisearch: here for easy customization of variables by overriding
46
+ # the _collection argument is not available when the method is called
47
+ def pagy_meilisearch_get_vars(_collection, vars)
48
+ pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
49
+ vars[:items] ||= VARS[:items]
50
+ vars[:page] ||= (params[ vars[:page_param] || VARS[:page_param] ] || 1).to_i
51
+ vars
52
+ end
53
+
54
+ end
55
+ end
@@ -6,7 +6,9 @@ class Pagy
6
6
  module UseOverflowExtra
7
7
  VARS[:overflow] = :empty_page
8
8
 
9
- def overflow? = @overflow
9
+ def overflow?
10
+ @overflow
11
+ end
10
12
 
11
13
  def initialize(vars)
12
14
  @overflow ||= false # don't override if :last_page re-run the method after an overflow
@@ -46,7 +46,11 @@ class Pagy
46
46
  "#{url_string}#{query_string}#{p_vars[:fragment]}"
47
47
  end
48
48
  end
49
- Helpers.prepend UseStandaloneExtra
49
+
50
+ # single line in order to avoid complicating simplecov already tested with other GitHub Actions
51
+ Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') \
52
+ && Helpers.prepend(UseStandaloneExtra) \
53
+ || ( Frontend.prepend(UseStandaloneExtra); Backend.prepend(UseStandaloneExtra) if defined?(Pagy::Backend::METADATA) ) # rubocop:disable Style/Semicolon
50
54
 
51
55
  # defines a dummy #params method if not already defined in the including module
52
56
  module Backend
@@ -12,7 +12,7 @@ class Pagy
12
12
  link_proc = super(pagy, link_extra: link_extra)
13
13
  return link_proc unless pagy.vars[:enable_trim_extra]
14
14
  lambda do |num, text=num, extra=''|
15
- link = link_proc.call(num, text, extra)
15
+ link = +link_proc.call(num, text, extra)
16
16
  return link unless num == 1
17
17
  link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
18
18
  end
@@ -11,7 +11,7 @@ class Pagy
11
11
  p_id = %( id="#{pagy_id}") if pagy_id
12
12
  link = pagy_link_proc(pagy, link_extra: link_extra)
13
13
 
14
- html = %(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
14
+ html = +%(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
15
15
  pagy.series.each do |item|
16
16
  html << case item
17
17
  when Integer then %(<li>#{link.call item}</li>)
data/lib/pagy/frontend.rb CHANGED
@@ -25,7 +25,9 @@ class Pagy
25
25
  end
26
26
 
27
27
  # Sub-method called only by #pagy_url_for: here for easy customization of params by overriding
28
- def pagy_get_params(params) = params
28
+ def pagy_get_params(params)
29
+ params
30
+ end
29
31
  end
30
32
 
31
33
  # All the code here has been optimized for performance: it may not look very pretty
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.1
4
+ version: 4.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Agnostic pagination in plain ruby: it works with any framework, ORM
14
14
  and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays,
@@ -22,6 +22,7 @@ files:
22
22
  - LICENSE.txt
23
23
  - lib/config/pagy.rb
24
24
  - lib/javascripts/pagy.js
25
+ - lib/locales/ar.yml
25
26
  - lib/locales/bg.yml
26
27
  - lib/locales/bs.yml
27
28
  - lib/locales/ca.yml
@@ -72,6 +73,7 @@ files:
72
73
  - lib/pagy/extras/i18n.rb
73
74
  - lib/pagy/extras/items.rb
74
75
  - lib/pagy/extras/materialize.rb
76
+ - lib/pagy/extras/meilisearch.rb
75
77
  - lib/pagy/extras/metadata.rb
76
78
  - lib/pagy/extras/navs.rb
77
79
  - lib/pagy/extras/overflow.rb
@@ -110,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
113
  - - ">="
112
114
  - !ruby/object:Gem::Version
113
- version: '3.0'
115
+ version: '2.5'
114
116
  required_rubygems_version: !ruby/object:Gem::Requirement
115
117
  requirements:
116
118
  - - ">="