pagy 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,36 +1,41 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/metadata
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  class Pagy
6
5
  # Add a specialized backend method for pagination metadata
7
- module Backend ; private
6
+ module Backend
7
+ private
8
8
 
9
- METADATA = [ :scaffold_url, :first_url, :prev_url, :page_url, :next_url, :last_url,
10
- :count, :page, :items, :vars, :pages, :last, :from, :to, :prev, :next, :series ]
11
- METADATA << :sequels if VARS.key?(:steps) # :steps gets defined along with the #sequels method
9
+ METADATA = %i[ scaffold_url first_url prev_url page_url next_url last_url
10
+ count page items vars pages last from to prev next series
11
+ ].tap do |metadata|
12
+ metadata << :sequels if VARS.key?(:steps) # :steps gets defined along with the #sequels method
13
+ end.freeze
12
14
 
13
15
  VARS[:metadata] = METADATA.dup
14
16
 
15
17
  include Helpers
16
18
 
17
- def pagy_metadata(pagy, url=false)
18
- names = pagy.vars[:metadata]
19
- (unknown = names - METADATA).empty? or raise(VariableError.new(pagy), "unknown metadata #{unknown.inspect}")
19
+ def pagy_metadata(pagy, url=nil)
20
+ names = pagy.vars[:metadata]
21
+ unknown = names - METADATA
22
+ raise VariableError.new(pagy), "unknown metadata #{unknown.inspect}" \
23
+ unless unknown.empty?
24
+
20
25
  scaffold_url = pagy_url_for(PAGE_PLACEHOLDER, pagy, url)
21
- metadata = {}
22
- names.each do |key|
23
- metadata[key] = case key
24
- when :scaffold_url ; scaffold_url
25
- when :first_url ; scaffold_url.sub(PAGE_PLACEHOLDER, 1.to_s)
26
- when :prev_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.prev.to_s)
27
- when :page_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.page.to_s)
28
- when :next_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.next.to_s)
29
- when :last_url ; scaffold_url.sub(PAGE_PLACEHOLDER, pagy.last.to_s)
30
- else pagy.send(key)
31
- end
26
+ {}.tap do |metadata|
27
+ names.each do |key|
28
+ metadata[key] = case key
29
+ when :scaffold_url then scaffold_url
30
+ when :first_url then scaffold_url.sub(PAGE_PLACEHOLDER, 1.to_s)
31
+ when :prev_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.prev.to_s)
32
+ when :page_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.page.to_s)
33
+ when :next_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.next.to_s)
34
+ when :last_url then scaffold_url.sub(PAGE_PLACEHOLDER, pagy.last.to_s)
35
+ else pagy.send(key)
36
+ end
37
+ end
32
38
  end
33
- metadata
34
39
  end
35
40
 
36
41
  end
@@ -1,5 +1,4 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/navs
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  require 'pagy/extras/shared'
@@ -9,30 +8,52 @@ class Pagy
9
8
 
10
9
  # Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
11
10
  def pagy_nav_js(pagy, id=pagy_id)
12
- link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
13
- tags = { 'before' => p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
14
- : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ),
11
+ link = pagy_link_proc(pagy)
12
+ tags = { 'before' => pagy_nav_prev_html(pagy, link),
15
13
  'link' => %(<span class="page">#{link.call(PAGE_PLACEHOLDER)}</span> ),
16
14
  'active' => %(<span class="page active">#{pagy.page}</span> ),
17
15
  'gap' => %(<span class="page gap">#{pagy_t('pagy.nav.gap')}</span> ),
18
- 'after' => p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
19
- : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>) }
20
- %(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)})
16
+ 'after' => pagy_nav_next_html(pagy, link) }
17
+
18
+ html = %(<nav id="#{id}" class="pagy-nav-js pagination" role="navigation" aria-label="pager"></nav>)
19
+ html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
21
20
  end
22
21
 
23
22
  # Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
24
23
  def pagy_combo_nav_js(pagy, id=pagy_id)
25
- link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
26
-
27
- html = %(<nav id="#{id}" class="pagy-combo-nav-js pagination" role="navigation" aria-label="pager">)
28
- html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
29
- : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
30
- input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
31
- html << %(<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</span> )
32
- html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
33
- : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
34
- html << %(</nav>#{pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))})
24
+ link = pagy_link_proc(pagy)
25
+ p_page = pagy.page
26
+ p_pages = pagy.pages
27
+ input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
28
+
29
+ %(<nav id="#{id}" class="pagy-combo-nav-js pagination" role="navigation" aria-label="pager">#{
30
+ pagy_nav_prev_html(pagy, link)
31
+ }<span class="pagy-combo-input" style="margin: 0 0.6rem;">#{
32
+ pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
33
+ }</span> #{
34
+ pagy_nav_next_html(pagy, link)
35
+ }</nav>#{
36
+ pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
37
+ })
35
38
  end
36
39
 
40
+ private
41
+
42
+ def pagy_nav_prev_html(pagy, link)
43
+ if (p_prev = pagy.prev)
44
+ %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
45
+ else
46
+ %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> )
47
+ end
48
+ end
49
+
50
+ def pagy_nav_next_html(pagy, link)
51
+ if (p_next = pagy.next)
52
+ %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
53
+ else
54
+ %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>)
55
+ end
56
+ end
57
+
37
58
  end
38
59
  end
@@ -1,10 +1,9 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/overflow
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  class Pagy
6
5
 
7
- module Overflow
6
+ module UseOverflowExtra
8
7
  VARS[:overflow] = :empty_page
9
8
 
10
9
  def overflow? = @overflow
@@ -34,33 +33,33 @@ class Pagy
34
33
  def series(size=@vars[:size])
35
34
  @page = @last # series for last page
36
35
  super(size).tap do |s| # call original series
37
- s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
38
- @page = @vars[:page] # restore the actual page
36
+ s[s.index(@page.to_s)] = @page # string to integer (i.e. no current page)
37
+ @page = @vars[:page] # restore the actual page
39
38
  end
40
39
  end
41
40
  end
42
41
 
43
42
  end
44
- prepend Overflow
43
+ prepend UseOverflowExtra
45
44
 
46
45
 
47
46
  # support for Pagy::Countless
48
47
  if defined?(Pagy::Countless)
49
48
  class Countless
50
49
 
51
- module Overflow
50
+ module UseOverflowExtra
52
51
 
53
52
  def finalize(items)
54
53
  @overflow = false
55
54
  super
56
55
  rescue OverflowError
57
- @overflow = true # add the overflow flag
56
+ @overflow = true # add the overflow flag
58
57
  case @vars[:overflow]
59
58
  when :exception
60
- raise # same as without the extra
59
+ raise # same as without the extra
61
60
  when :empty_page
62
- @offset = @items = @from = @to = 0 # vars relative to the actual page
63
- @vars[:size] = [] # no page in the series
61
+ @offset = @items = @from = @to = 0 # vars relative to the actual page
62
+ @vars[:size] = [] # no page in the series
64
63
  self
65
64
  else
66
65
  raise VariableError.new(self), "expected :overflow variable in [:empty_page, :exception]; got #{@vars[:overflow].inspect}"
@@ -68,7 +67,7 @@ class Pagy
68
67
  end
69
68
 
70
69
  end
71
- prepend Overflow
70
+ prepend UseOverflowExtra
72
71
 
73
72
  end
74
73
  end
@@ -1,5 +1,4 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/searchkick
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  class Pagy
@@ -10,7 +9,7 @@ class Pagy
10
9
  # returns an array used to delay the call of #search
11
10
  # after the pagination variables are merged to the options
12
11
  # it also pushes to the same array an eventually called method
13
- def pagy_searchkick(term = "*", **options, &block)
12
+ def pagy_searchkick(term = '*', **options, &block)
14
13
  [self, term, options, block].tap do |args|
15
14
  args.define_singleton_method(:method_missing){|*a| args += a}
16
15
  end
@@ -27,7 +26,8 @@ class Pagy
27
26
  end
28
27
 
29
28
  # Add specialized backend methods to paginate Searchkick::Results
30
- module Backend ; private
29
+ module Backend
30
+ private
31
31
 
32
32
  # Return Pagy object and results
33
33
  def pagy_searchkick(pagy_search_args, vars={})
@@ -37,12 +37,13 @@ class Pagy
37
37
  options[:page] = vars[:page]
38
38
  results = model.search(term, **options, &block)
39
39
  vars[:count] = results.total_count
40
+
40
41
  pagy = Pagy.new(vars)
41
42
  # with :last_page overflow we need to re-run the method in order to get the hits
42
- if defined?(Pagy::Overflow) && pagy.overflow? && pagy.vars[:overflow] == :last_page
43
- return pagy_searchkick(pagy_search_args, vars.merge(page: pagy.page))
44
- end
45
- return pagy, called.empty? ? results : results.send(*called)
43
+ return pagy_searchkick(pagy_search_args, vars.merge(page: pagy.page)) \
44
+ if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
45
+
46
+ [ pagy, called.empty? ? results : results.send(*called) ]
46
47
  end
47
48
 
48
49
  # Sub-method called only by #pagy_searchkick: here for easy customization of variables by overriding
@@ -1,5 +1,4 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/semantic
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  require 'pagy/extras/shared'
@@ -9,47 +8,69 @@ class Pagy
9
8
 
10
9
  # Pagination for semantic: it returns the html with the series of links to the pages
11
10
  def pagy_semantic_nav(pagy)
12
- link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
11
+ link = pagy_link_proc(pagy, 'class="item"')
13
12
 
14
- html = (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
15
- : +%(<div class="item disabled"><i class="left small chevron icon"></i></div>))
13
+ html = +%(<div class="pagy-semantic-nav ui pagination menu" aria-label="pager">)
14
+ html << pagy_semantic_prev_html(pagy, link)
16
15
  pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
17
- html << if item.is_a?(Integer); %(#{link.call item}) # page link
18
- elsif item.is_a?(String) ; %(<a class="item active">#{item}</a>) # current page
19
- elsif item == :gap ; %(<div class="disabled item">...</div>) # page gap
16
+ html << case item
17
+ when Integer then link.call item # page link
18
+ when String then %(<a class="item active">#{item}</a>) # current page
19
+ when :gap then %(<div class="disabled item">...</div>) # page gap
20
20
  end
21
21
  end
22
- html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
23
- : %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
24
- %(<div class="pagy-semantic-nav ui pagination menu" aria-label="pager">#{html}</div>)
22
+ html << pagy_semantic_next_html(pagy, link)
23
+ html << %(</div>)
25
24
  end
26
25
 
27
26
  # Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript
28
27
  def pagy_semantic_nav_js(pagy, id=pagy_id)
29
- link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
30
- tags = { 'before' => (p_prev ? %(#{link.call(p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"')})
31
- : %(<div class="item disabled"><i class="left small chevron icon"></i></div>)),
32
- 'link' => %(#{link.call(PAGE_PLACEHOLDER)}),
28
+ link = pagy_link_proc(pagy, 'class="item"')
29
+ tags = { 'before' => pagy_semantic_prev_html(pagy, link),
30
+ 'link' => link.call(PAGE_PLACEHOLDER),
33
31
  'active' => %(<a class="item active">#{pagy.page}</a>),
34
32
  'gap' => %(<div class="disabled item">#{pagy_t('pagy.nav.gap')}</div>),
35
- 'after' => (p_next ? %(#{link.call(p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"')})
36
- : %(<div class="item disabled"><i class="right small chevron icon"></i></div>)) }
37
- %(<div id="#{id}" class="pagy-semantic-nav-js ui pagination menu" role="navigation" aria-label="pager"></div>#{pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)})
33
+ 'after' => pagy_semantic_next_html(pagy, link) }
34
+
35
+ html = %(<div id="#{id}" class="pagy-semantic-nav-js ui pagination menu" role="navigation" aria-label="pager"></div>)
36
+ html << pagy_json_tag(pagy, :nav, id, tags, pagy.sequels)
38
37
  end
39
38
 
40
39
  # Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
41
40
  def pagy_semantic_combo_nav_js(pagy, id=pagy_id)
42
- link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages
43
-
44
- html = %(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">)
45
- html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
46
- : %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
47
- input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem; margin: 0 0.3rem">)
48
- html << %(<div class="pagy-combo-input item">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div> )
49
- html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
50
- : %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
51
- html << %(</div>#{pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))})
41
+ link = pagy_link_proc(pagy, 'class="item"')
42
+ p_page = pagy.page
43
+ p_pages = pagy.pages
44
+ input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 0; text-align: center; width: #{p_pages.to_s.length+1}rem; margin: 0 0.3rem">)
45
+
46
+ %(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">#{
47
+ pagy_semantic_prev_html(pagy, link)
48
+ }<div class="pagy-combo-input item">#{
49
+ pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)
50
+ }</div> #{
51
+ pagy_semantic_next_html(pagy, link)
52
+ }</div>#{
53
+ pagy_json_tag(pagy, :combo_nav, id, p_page, pagy_marked_link(link))
54
+ })
52
55
  end
53
56
 
57
+ private
58
+
59
+ def pagy_semantic_prev_html(pagy, link)
60
+ if (p_prev = pagy.prev)
61
+ link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'
62
+ else
63
+ %(<div class="item disabled"><i class="left small chevron icon"></i></div>)
64
+ end
65
+ end
66
+
67
+ def pagy_semantic_next_html(pagy, link)
68
+ if (p_next = pagy.next)
69
+ link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'
70
+ else
71
+ %(<div class="item disabled"><i class="right small chevron icon"></i></div>)
72
+ end
73
+ end
74
+
54
75
  end
55
76
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  # frozen_string_literal: true
3
2
 
4
3
  require 'digest'
@@ -19,8 +18,11 @@ class Pagy
19
18
  # Notice: if :steps is false it will use the single {0 => @vars[:size]} size
20
19
  def sequels
21
20
  steps = @vars[:steps] || {0 => @vars[:size]}
22
- steps.key?(0) or raise(VariableError.new(self), "expected :steps to define the 0 width; got #{steps.inspect}")
23
- sequels = {}; steps.each {|width, size| sequels[width.to_s] = series(size)}; sequels
21
+ raise VariableError.new(self), "expected :steps to define the 0 width; got #{steps.inspect}" \
22
+ unless steps.key?(0)
23
+ {}.tap do |sequels|
24
+ steps.each {|width, size| sequels[width.to_s] = series(size)}
25
+ end
24
26
  end
25
27
 
26
28
  module Frontend
@@ -28,23 +30,27 @@ class Pagy
28
30
  if defined?(Oj)
29
31
  # it returns a script tag with the JSON-serialized args generated with the faster oj gem
30
32
  def pagy_json_tag(pagy, *args)
31
- args << ( defined?(Trim) && pagy.vars[:page_param] )
33
+ args << ( defined?(UseTrimExtra) && pagy.vars[:page_param] )
32
34
  %(<script type="application/json" class="pagy-json">#{Oj.dump(args, mode: :strict)}</script>)
33
35
  end
34
36
  else
35
37
  require 'json'
36
38
  # it returns a script tag with the JSON-serialized args generated with the slower to_json
37
39
  def pagy_json_tag(pagy, *args)
38
- args << ( defined?(Trim) && pagy.vars[:page_param] )
40
+ args << ( defined?(UseTrimExtra) && pagy.vars[:page_param] )
39
41
  %(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
40
42
  end
41
43
  end
42
44
 
43
45
  # it returns the SHA1 (fastest on modern ruby) string used as default `id` attribute by all the `*_js` tags
44
- def pagy_id = "pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
46
+ def pagy_id
47
+ "pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
48
+ end
45
49
 
46
50
  # it returns the marked link to used by pagy.js
47
- def pagy_marked_link(link) = link.call(PAGE_PLACEHOLDER, '', 'style="display: none;"')
51
+ def pagy_marked_link(link)
52
+ link.call PAGE_PLACEHOLDER, '', 'style="display: none;"'
53
+ end
48
54
 
49
55
  end
50
56
 
@@ -1,5 +1,4 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/support
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  class Pagy
@@ -15,13 +14,19 @@ class Pagy
15
14
  end
16
15
 
17
16
  def pagy_prev_link(pagy, text = pagy_t('pagy.nav.prev'), link_extra = '')
18
- pagy.prev ? %(<span class="page prev"><a href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
19
- : %(<span class="page prev disabled">#{text}</span>)
17
+ if pagy.prev
18
+ %(<span class="page prev"><a href="#{pagy_url_for(pagy.prev, pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
19
+ else
20
+ %(<span class="page prev disabled">#{text}</span>)
21
+ end
20
22
  end
21
23
 
22
24
  def pagy_next_link(pagy, text = pagy_t('pagy.nav.next'), link_extra = '')
23
- pagy.next ? %(<span class="page next"><a href="#{pagy_url_for(pagy.next, pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
24
- : %(<span class="page next disabled">#{text}</span>)
25
+ if pagy.next
26
+ %(<span class="page next"><a href="#{pagy_url_for(pagy.next, pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
27
+ else
28
+ %(<span class="page next disabled">#{text}</span>)
29
+ end
25
30
  end
26
31
 
27
32
  def pagy_prev_link_tag(pagy)
@@ -1,19 +1,23 @@
1
1
  # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/trim
2
- # encoding: utf-8
3
2
  # frozen_string_literal: true
4
3
 
5
4
  class Pagy
6
5
 
7
- module Trim
6
+ module UseTrimExtra
7
+
8
8
  def pagy_link_proc(pagy, link_extra='')
9
9
  link_proc = super(pagy, link_extra)
10
- re = /[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/
11
- lambda do |n, text=n, extra=''|
12
- link = link_proc.call(n, text, extra)
13
- n == 1 ? link.sub(re, '') : link
10
+ lambda do |num, text=num, extra=''|
11
+ link = link_proc.call(num, text, extra)
12
+ if num == 1
13
+ link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
14
+ else
15
+ link
16
+ end
14
17
  end
15
18
  end
19
+
16
20
  end
17
- Frontend.prepend Trim
21
+ Frontend.prepend UseTrimExtra
18
22
 
19
23
  end