pagy 3.12.0 → 3.13.0

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: 579eed5284017d67002b2def3cc82fab990b416c9b89226bdea2ec210677a014
4
- data.tar.gz: b4fd177fbae68205121d79437dda967646aa593e45569934142a35546224c87e
3
+ metadata.gz: e16e1b508c2096d675f846a898da3e1338e8535b460074535e1742cd08a3c6cb
4
+ data.tar.gz: 450a453312266d3af1f8b18a9cd0734ebc002a6533b9f6c269d7802706f66116
5
5
  SHA512:
6
- metadata.gz: c5eba45292ec4f0c25047830e9c761aa081b6365e95be4ba09e5917c52ca59e9d956fccf376e6c7fb821fc318363a5078ce72abbfa83b6d11603a13953d3a476
7
- data.tar.gz: b25ac2fcc23d996ff77f14b6f539d34e972a3c41178a790dc0697c92082243ec33fafe834639c4fce8acf3bfa11c77f78ca725d2f2b01f91665af9f2def43b6b
6
+ metadata.gz: da6eccb117de48a28d0572d011b29040c7c5f17dcb8282a1a7eadc0c5d11f38aea062e6a4f8e6db40ceba2b2022a54af1deb74e7a2eeb720f0b76b4fdba11098
7
+ data.tar.gz: 873549bfee07251e7c5948eb24837f01309db20b69e512cffa53a8552e5ca6c634c60a49239d0e87480635118e83e213acc29981d9cbd0d30874a912443e4a6d
data/lib/config/pagy.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # Pagy initializer file (3.12.0)
4
+ # Pagy initializer file (3.13.0)
5
5
  # Customize only what you really need and notice that Pagy works also without any of the following lines.
6
6
  # Should you just cherry pick part of this file, please maintain the require-order of the extras
7
7
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '3.12.0';
5
+ Pagy.version = '3.13.0';
6
6
 
7
7
  Pagy.init = function(arg){
8
8
  var target = arg instanceof Event || arg === undefined ? document : arg,
data/lib/pagy.rb CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'pathname'
6
6
 
7
- class Pagy ; VERSION = '3.12.0'
7
+ class Pagy ; VERSION = '3.13.0'
8
8
 
9
9
  # Root pathname to get the path of Pagy files like templates or dictionaries
10
10
  def self.root; @root ||= Pathname.new(__FILE__).dirname.freeze end
@@ -32,18 +32,31 @@ class Pagy ; VERSION = '3.12.0'
32
32
  end
33
33
 
34
34
  # Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
35
- def series(size=@vars[:size])
36
- (series = []) and size.empty? and return series
37
- 4.times{|i| (size[i]>=0 rescue nil) or raise(VariableError.new(self), "expected 4 items >= 0 in :size; got #{size.inspect}")}
38
- [*0..size[0], *@page-size[1]..@page+size[2], *@last-size[3]+1..@last+1].sort!.each_cons(2) do |a, b|
39
- if a<0 || a==b || a>@last # skip out of range and duplicates
40
- elsif a+1 == b; series.push(a) # no gap -> no additions
41
- elsif a+2 == b; series.push(a, a+1) # 1 page gap -> fill with missing page
42
- else series.push(a, :gap) # n page gap -> add gap
43
- end # skip the end boundary (last+1)
44
- end # shift the start boundary (0) and
45
- series.shift; series[series.index(@page)] = @page.to_s; series # convert the current page to String
35
+ def series(size=@vars[:size])
36
+ return [] if size.empty?
37
+ raise VariableError.new(self), "expected 4 items >= 0 in :size; got #{size.inspect}" \
38
+ unless size.size == 4 && size.all?{ |num| num >= 0 rescue false }
39
+ # This algorithm (backported from pagy 4.3) is up to ~5x faster and ~2.3x lighter than the previous one
40
+ left_gap_start = 1 + size[0]
41
+ left_gap_end = @page - size[1] - 1
42
+ right_gap_start = @page + size[2] + 1
43
+ right_gap_end = @last - size[3]
44
+ left_gap_end = right_gap_end if left_gap_end > right_gap_end
45
+ right_gap_start = left_gap_start if left_gap_start > right_gap_start
46
+ series = []
47
+ start = 1
48
+ if (left_gap_end - left_gap_start) > 0
49
+ series.push(*start..(left_gap_start - 1), :gap)
50
+ start = left_gap_end + 1
46
51
  end
52
+ if (right_gap_end - right_gap_start) > 0
53
+ series.push(*start..(right_gap_start - 1), :gap)
54
+ start = right_gap_end + 1
55
+ end
56
+ series.push(*start..@last)
57
+ series[series.index(@page)] = @page.to_s
58
+ series
59
+ end
47
60
 
48
61
  end
49
62
 
@@ -8,7 +8,7 @@ class Pagy
8
8
  class Countless < Pagy
9
9
 
10
10
  # Merge and validate the options, do some simple arithmetic and set a few instance variables
11
- def initialize(vars={})
11
+ def initialize(vars={}) # rubocop:disable Lint/MissingSuper
12
12
  @vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden)
13
13
  { items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
14
14
  (@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \
@@ -4,6 +4,7 @@ class Pagy
4
4
  attr_reader :pagy
5
5
 
6
6
  def initialize(pagy)
7
+ super
7
8
  @pagy = pagy
8
9
  end
9
10
 
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: 3.12.0
4
+ version: 3.13.0
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-03-12 00:00:00.000000000 Z
11
+ date: 2021-04-20 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,7 +22,6 @@ files:
22
22
  - LICENSE.txt
23
23
  - lib/config/pagy.rb
24
24
  - lib/javascripts/pagy.js
25
- - lib/locales/README.md
26
25
  - lib/locales/bg.yml
27
26
  - lib/locales/bs.yml
28
27
  - lib/locales/ca.yml
@@ -96,7 +95,6 @@ files:
96
95
  - lib/templates/uikit_nav.html.erb
97
96
  - lib/templates/uikit_nav.html.haml
98
97
  - lib/templates/uikit_nav.html.slim
99
- - pagy.gemspec
100
98
  homepage: https://github.com/ddnexus/pagy
101
99
  licenses:
102
100
  - MIT
@@ -119,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
117
  - !ruby/object:Gem::Version
120
118
  version: '0'
121
119
  requirements: []
122
- rubygems_version: 3.1.4
120
+ rubygems_version: 3.1.6
123
121
  signing_key:
124
122
  specification_version: 4
125
123
  summary: The Ultimate Pagination Ruby Gem
@@ -1,35 +0,0 @@
1
- # Pagy locales
2
-
3
- ### Please, submit your translation!
4
-
5
- If you find that some translation could be improved, please, create an issue.
6
-
7
- If you are using pagy with some language missing from the dictionary files, please, submit your translation!
8
-
9
- You can create a Pull Request for your language, and get all the help you need to correctly complete it. Here is a check list.
10
-
11
- ### Check list for a new dictionary file:
12
-
13
- - [ ] Find the pluralization rule for your language
14
-
15
- - [ ] Find the locale file you need in the [list of pluralizations](https://github.com/svenfuchs/rails-i18n/tree/master/rails/pluralization) and check the pluralization rule in it. For example it is `::RailsI18n::Pluralization::OneOther.with_locale(:en)` for `en.rb`. Note the rule part i.e. `OneOther`. In pagy that translates to the symbol `:one_other`.
16
-
17
- - [ ] If the pluralization rule of your language is not the `:one_other` default, confirm that the [p11n.rb](https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb) file already defines the pluralization rule of your dictionary file:
18
-
19
- - [ ] If the rule is not defined, you can either: a) Add the rule as a new rule/lambda entry in the `p11n` variable hash and relative tests or b) Just create an issue requesting the addition to the rule/lambda entry and tests.
20
-
21
- - [ ] Add your language to the `plurals` hash in the file.
22
-
23
- - [ ] add/edit the first line comment in the language rule in your dictionary file (e.g. `# :one_other pluralization ...`
24
-
25
- - [ ] The mandatory pluralized entry in the dictionary file is the `item_name`. Please, provide all the plurals needed by your language. E.g. if your language uses the `:east_slavic` you should provide the plurals for `one`, `few`, `many` and `other`, if it uses `:one_other`, you should provide `one` and `other` plurals. If it uses `:other` you should only provide a single value. Look into other dictionary files to get some example. Ask if in doubt.
26
-
27
- - [ ] The other entries in the dictionary file don't need any plural variant in most languages since the pluralization of the `item_name` in the sentence is enough. However, in some language, a whole sentence might need to be written in different ways for different counts. In that case you should add the different plurals for the sentence and the `count` will trigger the one that applies.
28
-
29
- Feel free to ask for help in your Pull Request.
30
-
31
- ### Useful Links
32
-
33
- * [Pagy I18n Documentation](https://ddnexus.github.io/pagy/api/frontend#i18n)
34
- * [I18n Extra](https://ddnexus.github.io/pagy/extras/i18n)
35
-
data/pagy.gemspec DELETED
@@ -1,16 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'pagy'
4
-
5
- Gem::Specification.new do |s|
6
- s.name = 'pagy'
7
- s.version = Pagy::VERSION
8
- s.authors = ['Domizio Demichelis']
9
- s.email = ['dd.nexus@gmail.com']
10
- s.summary = 'The Ultimate Pagination Ruby Gem'
11
- s.description = 'Agnostic pagination in plain ruby: it works with any framework, ORM and DB type, with all kinds of collections, even pre-paginated, scopes, Arrays, JSON data... Easy, powerful, fast and light.'
12
- s.homepage = 'https://github.com/ddnexus/pagy'
13
- s.license = 'MIT'
14
- s.files = `git ls-files -z`.split("\x0").select{|f| f.start_with?('lib', 'pagy.gemspec', 'LICENSE') }
15
- s.required_ruby_version = ['>= 1.9', '< 3.0']
16
- end