pagy 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pagy.rb +3 -3
  3. data/lib/pagy/frontend.rb +10 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d15c4b37bce77cfd5a60512d46d728a5ea33dcd8f9f32cf31de6307f9d5b5d8
4
- data.tar.gz: 501a0e654d0874766cafaa5c12b79e3dc5b643cdb3150a99e6bd2d4cf45ce159
3
+ metadata.gz: dda23dfaf654fccdeafca5c511f6e1f23c501e4599989f5e6887b1d1f0ecc3ad
4
+ data.tar.gz: 9be4570f44ffdd234e58364ff92bbec6fd5f8dedad6050a7defef37314dd84e2
5
5
  SHA512:
6
- metadata.gz: eb2aff48d06edc8e6aa08c118f55b01cc9e70beafc23fbb99a9af5bcb45bd63d0abc90a766d941abfeafa7ed0dbdd592f2471c383b8082bda02f328a679c3ad6
7
- data.tar.gz: c48a529c198243dbcb66c20f7b5047dd12bdec53a22d72954b61967dbbb205bc5037ab6e84426f12be2ca3f5d43d4b61380d99a16f64ace8116a08c79ee8d489
6
+ metadata.gz: 52e7cb89a79da6e3a8f9610ed4e0088cfc731a14f61fef6b0a1dc40eec0b692639dd3d41692774bf0f8e87464609eb9e52cc0afd653c9f66214b3e703d3d559d
7
+ data.tar.gz: d2418aa0a685140b8e73c06fe510076126bdc62f0d264f1be5a1e282f53600387ae5905b5c552aaf19d6e2b82eb64a215044484189a5522323ea578e85ea00a2
data/lib/pagy.rb CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- class Pagy ; VERSION = '0.8.3'
5
+ class Pagy ; VERSION = '0.8.4'
6
6
 
7
7
  class OutOfRangeError < StandardError; end
8
8
 
9
9
  # root pathname to get the path of pagy files like templates or dictionaries
10
10
  def self.root; Pathname.new(__FILE__).dirname end
11
11
 
12
- # default core vars
13
- VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params: {} }
12
+ # default vars
13
+ VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params: {}, anchor: ''.freeze, link_extra: ''.freeze, item_path: 'pagy.info.item_name'.freeze }
14
14
 
15
15
  attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next
16
16
 
data/lib/pagy/frontend.rb CHANGED
@@ -28,9 +28,9 @@ class Pagy
28
28
 
29
29
  # return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total"
30
30
  def pagy_info(pagy)
31
- name = pagy_t(pagy.vars[:item_path] || 'pagy.info.item_name'.freeze, count: pagy.count)
32
- key = pagy.pages == 1 ? 'single_page'.freeze : 'multiple_pages'.freeze
33
- pagy_t("pagy.info.#{key}", item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
31
+ name = pagy_t(pagy.vars[:item_path], count: pagy.count)
32
+ path = pagy.pages == 1 ? 'pagy.info.single_page'.freeze : 'pagy.info.multiple_pages'.freeze
33
+ pagy_t(path, item_name: name, count: pagy.count, from: pagy.from, to: pagy.to)
34
34
  end
35
35
 
36
36
 
@@ -47,16 +47,15 @@ class Pagy
47
47
 
48
48
  MARKER = "-pagy-#{'pagy'.hash}-".freeze
49
49
 
50
- # returns a specialized proc to generate the HTML links
51
- def pagy_link_proc(pagy, lx=''.freeze) # "lx" means "link extra"
52
- p_prev, p_next, p_lx = pagy.prev, pagy.next, pagy.vars[:link_extra]
53
- a, b = %(<a href="#{pagy_url_for(MARKER, pagy)}"#{p_lx ? %( #{p_lx}) : ''.freeze}#{lx.empty? ? lx : %( #{lx})}).split(MARKER)
54
- -> (n, text=n, x=''.freeze) { "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'.freeze
55
- elsif n == p_next ; ' rel="next"'.freeze
56
- else ''.freeze end }#{x.empty? ? x : %( #{x})}>#{text}</a>" }
50
+ # returns a performance optimized proc to generate the HTML links
51
+ def pagy_link_proc(pagy, link_extra=''.freeze)
52
+ p_prev, p_next = pagy.prev, pagy.next
53
+ a, b = %(<a href="#{pagy_url_for(MARKER, pagy)}" #{pagy.vars[:link_extra]} #{link_extra}).split(MARKER, 2)
54
+ -> (n, text=n, extra=''.freeze) { "#{a}#{n}#{b}#{ if n == p_prev ; ' rel="prev"'.freeze
55
+ elsif n == p_next ; ' rel="next"'.freeze
56
+ else ''.freeze end } #{extra}>#{text}</a>" }
57
57
  end
58
58
 
59
-
60
59
  # Pagy::Frontend::I18N constant
61
60
  zero_one = [:zero, :one]; I18N = { plurals: -> (c) {(zero_one[c] || :other).to_s.freeze}, data: {}}
62
61
  def I18N.load_file(file) I18N[:data].replace(YAML.load_file(file).first[1]) end
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: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-01 00:00:00.000000000 Z
11
+ date: 2018-06-02 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,