pagy 2.1.5 → 3.0.0

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.
@@ -1,20 +1,20 @@
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
1
3
  zh-TW:
2
4
  pagy:
5
+
6
+ item_name: ""
7
+
3
8
  nav:
4
9
  prev: "‹ 上一頁"
5
10
  next: "下一頁 ›"
6
11
  gap: "…"
12
+
13
+ combo_nav_js: "第 %{page_input} / %{pages} 頁"
14
+
7
15
  info:
8
- single_page:
9
- zero: "沒找到 %{item_name}"
10
- one: "顯示 <b>1</b> 項%{item_name}"
11
- other: "顯示<b>所有 %{count}</b> 項%{item_name}"
16
+ no_items: "沒找到項"
17
+ single_page: "顯示 <b>%{count}</b> 項%{item_name}"
12
18
  multiple_pages: "共 <b>%{count}</b> 項%{item_name},顯示 <b>%{from}-%{to}</b>"
13
- item_name:
14
- zero: ""
15
- one: ""
16
- other: ""
17
- compact: "第 %{page_input} / %{pages} 頁"
18
- items:
19
- one: "每頁顯示 %{items_input} 項"
20
- other: "每頁顯示 %{items_input} 項"
19
+
20
+ items_selector_js: "每頁顯示 %{items_input} 項%{item_name}"
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'pathname'
6
6
 
7
- class Pagy ; VERSION = '2.1.5'
7
+ class Pagy ; VERSION = '3.0.0'
8
8
 
9
9
  class OverflowError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end
10
10
 
@@ -12,7 +12,7 @@ class Pagy ; VERSION = '2.1.5'
12
12
  def self.root; @root ||= Pathname.new(__FILE__).dirname.freeze end
13
13
 
14
14
  # default vars
15
- VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', item_path:'pagy.info.item_name', cycle: false }
15
+ VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', i18n_key:'pagy.item_name', cycle:false }
16
16
 
17
17
  attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next
18
18
 
@@ -41,7 +41,7 @@ class Pagy ; VERSION = '2.1.5'
41
41
  if a<0 || a==b || a>@last # skip out of range and duplicates
42
42
  elsif a+1 == b; series.push(a) # no gap -> no additions
43
43
  elsif a+2 == b; series.push(a, a+1) # 1 page gap -> fill with missing page
44
- else series.push(a, :gap) # n page gap -> add :gap
44
+ else series.push(a, :gap) # n page gap -> add gap
45
45
  end # skip the end boundary (last+1)
46
46
  end # shift the start boundary (0) and
47
47
  series.shift; series[series.index(@page)] = @page.to_s; series # convert the current page to String
@@ -24,43 +24,34 @@ class Pagy
24
24
  %(<nav class="pagy-bootstrap-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></nav>)
25
25
  end
26
26
 
27
- # Compact pagination for bootstrap: it returns the html with the series of links to the pages
28
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
- def pagy_bootstrap_compact_nav(pagy, id=pagy_id)
27
+ # Javascript pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.nav javascript
28
+ def pagy_bootstrap_nav_js(pagy, id=pagy_id)
29
+ link, p_prev, p_next = pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next
30
+ tags = { 'before' => p_prev ? %(<ul class="pagination"><li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
31
+ : %(<ul class="pagination"><li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>),
32
+ 'link' => %(<li class="page-item">#{marker = link.call(MARKER)}</li>),
33
+ 'active' => %(<li class="page-item active">#{marker}</li>),
34
+ 'gap' => %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>),
35
+ 'after' => p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li></ul>)
36
+ : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li></ul>) }
37
+ %(<nav id="#{id}" class="pagy-bootstrap-nav-js pagination" role="navigation" aria-label="pager"></nav>#{pagy_json_tag(:nav, id, MARKER, tags, pagy.sequels)})
38
+ end
39
+
40
+ # Javascript combo pagination for bootstrap: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
41
+ def pagy_bootstrap_combo_nav_js(pagy, id=pagy_id)
30
42
  link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
31
43
 
32
- html = EMPTY + %(<nav id="#{id}" class="pagy-bootstrap-compact-nav pagination" role="navigation" aria-label="pager">)
33
- html << link.call(MARKER, '', %(style="display: none;" ))
44
+ html = %(<nav id="#{id}" class="pagy-bootstrap-combo-nav-js pagination" role="navigation" aria-label="pager">) \
45
+ + link.call(MARKER, '', %(style="display: none;" ))
34
46
  (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
35
47
  html << %(<div class="btn-group" role="group">)
36
48
  html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous" class="prev btn btn-primary"')
37
49
  : %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
38
50
  input = %(<input type="number" min="1" max="#{p_pages}" value="#{p_page}" class="text-primary" style="padding: 0; border: none; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
39
- html << %(<div class="pagy-compact-input btn btn-primary disabled" style="white-space: nowrap;">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div>)
51
+ html << %(<div class="pagy-combo-input btn btn-primary disabled" style="white-space: nowrap;">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>)
40
52
  html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next" class="next btn btn-primary"')
41
53
  : %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
42
- html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
43
- end
44
-
45
- # Responsive pagination for bootstrap: it returns the html with the series of links to the pages
46
- # rendered by the Pagy.responsive javascript
47
- def pagy_bootstrap_responsive_nav(pagy, id=pagy_id)
48
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive
49
-
50
- tags['before'] = EMPTY + '<ul class="pagination">'
51
- tags['before'] << (p_prev ? %(<li class="page-item prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
52
- : %(<li class="page-item prev disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.prev')}</a></li>))
53
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
54
- tags[item.to_s] = if item.is_a?(Integer); %(<li class="page-item">#{link.call item}</li>) # page link
55
- elsif item.is_a?(String) ; %(<li class="page-item active">#{link.call item}</li>) # active page
56
- elsif item == :gap ; %(<li class="page-item gap disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
57
- end
58
- end
59
- tags['after'] = EMPTY + (p_next ? %(<li class="page-item next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
60
- : %(<li class="page-item next disabled"><a href="#" class="page-link">#{pagy_t('pagy.nav.next')}</a></li>))
61
- tags['after'] << '</ul>'
62
- script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
63
- %(<nav id="#{id}" class="pagy-bootstrap-responsive-nav pagination" role="navigation" aria-label="pager"></nav>#{script})
54
+ html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
64
55
  end
65
56
 
66
57
  end
@@ -11,10 +11,10 @@ class Pagy
11
11
  def pagy_bulma_nav(pagy)
12
12
  link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
13
13
 
14
- html = EMPTY + (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
15
- : %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>))
16
- html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
17
- : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>))
14
+ html = (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
15
+ : %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>)) \
16
+ + (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
17
+ : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>))
18
18
  html << '<ul class="pagination-list">'
19
19
  pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
20
20
  html << if item.is_a?(Integer); %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}") }</li>) # page link
@@ -26,43 +26,36 @@ class Pagy
26
26
  %(<nav class="pagy-bulma-nav pagination is-centered" role="navigation" aria-label="pagination">#{html}</nav>)
27
27
  end
28
28
 
29
- # Compact pagination for Bulma: it returns the html with the series of links to the pages
30
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
31
- def pagy_bulma_compact_nav(pagy, id=pagy_id)
29
+ # Javascript pagination for bulma: it returns a nav and a JSON tag used by the Pagy.nav javascript
30
+ def pagy_bulma_nav_js(pagy, id=pagy_id)
31
+ link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
32
+ tags = { 'before' => ( (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
33
+ : %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>)) \
34
+ + (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
35
+ : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>)) \
36
+ + '<ul class="pagination-list">' ),
37
+ 'link' => %(<li>#{link.call(MARKER, MARKER, %(class="pagination-link" aria-label="goto page #{MARKER}"))}</li>),
38
+ 'active' => %(<li>#{link.call(MARKER, MARKER, %(class="pagination-link is-current" aria-current="page" aria-label="page #{MARKER}"))}</li>),
39
+ 'gap' => %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>),
40
+ 'after' => '</ul>' }
41
+ %(<nav id="#{id}" class="pagy-bulma-nav-js pagination is-centered" role="navigation" aria-label="pagination"></nav>#{pagy_json_tag(:nav, id, MARKER, tags, pagy.sequels)})
42
+ end
43
+
44
+ # Javascript combo pagination for Bulma: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
45
+ def pagy_bulma_combo_nav_js(pagy, id=pagy_id)
32
46
  link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
33
47
 
34
- html = EMPTY + %(<nav id="#{id}" class="pagy-bulma-compact-nav" role="navigation" aria-label="pagination">)
35
- html << link.call(MARKER, '', 'style="display: none;"')
48
+ html = %(<nav id="#{id}" class="pagy-bulma-combo-nav-js" role="navigation" aria-label="pagination">) \
49
+ + link.call(MARKER, '', 'style="display: none;"')
36
50
  (html << link.call(1, '', %(style="display: none;"))) if defined?(TRIM)
37
51
  html << %(<div class="field is-grouped is-grouped-centered" role="group">)
38
52
  html << (p_prev ? %(<p class="control">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="button" aria-label="previous page"')}</p>)
39
53
  : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.prev')}</a></p>))
40
54
  input = %(<input class="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;">)
41
- html << %(<div class="pagy-compact-input control level is-mobile">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div>)
55
+ html << %(<div class="pagy-combo-input control level is-mobile">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>)
42
56
  html << (p_next ? %(<p class="control">#{link.call(p_next, pagy_t('pagy.nav.next'), 'class="button" aria-label="next page"')}</p>)
43
57
  : %(<p class="control"><a class="button" disabled>#{pagy_t('pagy.nav.next')}</a></p>))
44
- html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
45
- end
46
-
47
- # Responsive pagination for Bulma: it returns the html with the series of links to the pages
48
- # rendered by the Pagy.responsive javascript
49
- def pagy_bulma_responsive_nav(pagy, id=pagy_id)
50
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
51
-
52
- tags['before'] = EMPTY + (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')
53
- : %(<a class="pagination-previous" disabled>#{pagy_t('pagy.nav.prev')}</a>))
54
- tags['before'] << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'class="pagination-next" aria-label="next page"')
55
- : %(<a class="pagination-next" disabled>#{pagy_t('pagy.nav.next')}</a>))
56
- tags['before'] << '<ul class="pagination-list">'
57
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
58
- tags[item.to_s] = if item.is_a?(Integer); %(<li>#{link.call item, item, %(class="pagination-link" aria-label="goto page #{item}")}</li>)
59
- elsif item.is_a?(String) ; %(<li>#{link.call item, item, %(class="pagination-link is-current" aria-current="page" aria-label="page #{item}")}</li>)
60
- elsif item == :gap ; %(<li><span class="pagination-ellipsis">#{pagy_t('pagy.nav.gap')}</span></li>)
61
- end
62
- end
63
- tags['after'] = '</ul>'
64
- script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
65
- %(<nav id="#{id}" class="pagy-bulma-responsive-nav pagination is-centered" role="navigation" aria-label="pagination"></nav>#{script})
58
+ html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
66
59
  end
67
60
 
68
61
  end
@@ -24,43 +24,36 @@ class Pagy
24
24
  %(<nav class="pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
25
25
  end
26
26
 
27
- # Compact pagination for Foundation: it returns the html with the series of links to the pages
28
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
- def pagy_foundation_compact_nav(pagy, id=pagy_id)
27
+ # Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
28
+ def pagy_foundation_nav_js(pagy, id=pagy_id)
29
+ link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
30
+ tags = { 'before' => ( '<ul class="pagination">' \
31
+ + (p_prev ? %(<li class="prev">#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"')}</li>)
32
+ : %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>)) ),
33
+ 'link' => %(<li>#{link.call(MARKER)}</li>),
34
+ 'active' => %(<li class="current">#{pagy.page}</li>),
35
+ 'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
36
+ 'after' => ( (p_next ? %(<li class="next">#{link.call(p_next, pagy_t('pagy.nav.next'), 'aria-label="next"')}</li>)
37
+ : %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>)) \
38
+ + '</ul>' ) }
39
+ %(<nav id="#{id}" class="pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>#{pagy_json_tag(:nav, id, MARKER, tags, pagy.sequels)})
40
+ end
41
+
42
+ # Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
43
+ def pagy_foundation_combo_nav_js(pagy, id=pagy_id)
30
44
  link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
31
45
 
32
- html = EMPTY + %(<nav id="#{id}" class="pagy-foundation-compact-nav" role="navigation" aria-label="Pagination">)
33
- html << link.call(MARKER, '', %(style="display: none;" ))
46
+ html = %(<nav id="#{id}" class="pagy-foundation-combo-nav-js" role="navigation" aria-label="Pagination">) \
47
+ + link.call(MARKER, '', %(style="display: none;" ))
34
48
  (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
35
49
  html << %(<div class="input-group">)
36
50
  html << (p_prev ? link.call(p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"')
37
51
  : %(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t('pagy.nav.prev')}</a>))
38
52
  input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1}rem; padding: 0 0.3rem; margin: 0 0.3rem;">)
39
- html << %(<span class="input-group-label">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</span>)
53
+ html << %(<span class="input-group-label">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</span>)
40
54
  html << (p_next ? link.call(p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"')
41
55
  : %(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t('pagy.nav.next')}</a>))
42
- html << %(</div></nav>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
43
- end
44
-
45
- # Responsive pagination for Foundation: it returns the html with the series of links to the pages
46
- # rendered by the Pagy.responsive javascript
47
- def pagy_foundation_responsive_nav(pagy, id=pagy_id)
48
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
49
-
50
- tags['before'] = EMPTY + '<ul class="pagination">'
51
- tags['before'] << (p_prev ? %(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
52
- : %(<li class="prev disabled">#{pagy_t('pagy.nav.prev')}</li>))
53
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
54
- tags[item.to_s] = if item.is_a?(Integer); %(<li>#{link.call item}</li>) # page link
55
- elsif item.is_a?(String) ; %(<li class="current">#{item}</li>) # active page
56
- elsif item == :gap ; %(<li class="ellipsis gap" aria-hidden="true"></li>) # page gap
57
- end
58
- end
59
- tags['after'] = EMPTY + (p_next ? %(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
60
- : %(<li class="next disabled">#{pagy_t('pagy.nav.next')}</li>))
61
- tags['after'] << '</ul>'
62
- script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
63
- %(<nav id="#{id}" class="pagy-foundation-responsive-nav" aria-label="Pagination"></nav>#{script})
56
+ html << %(</div></nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
64
57
  end
65
58
 
66
59
  end
@@ -10,7 +10,7 @@ class Pagy
10
10
 
11
11
  Pagy::I18n.clear.instance_eval { undef :load; undef :t } # unload the pagy default constant for efficiency
12
12
 
13
- # no :pagy_without_i18n alias with the i18n gem
13
+ alias :pagy_without_i18n :pagy_t
14
14
  def pagy_t_with_i18n(*args) ::I18n.t(*args) end
15
15
  alias :pagy_t :pagy_t_with_i18n
16
16
 
@@ -46,15 +46,14 @@ class Pagy
46
46
  alias_method :pagy_url_for, :pagy_url_for_with_items
47
47
 
48
48
  # Return the items selector HTML. For example "Show [20] items per page"
49
- def pagy_items_selector(pagy, id=pagy_id)
49
+ def pagy_items_selector_js(pagy, id=pagy_id)
50
50
  p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-"
51
51
 
52
- html = EMPTY + %(<span id="#{id}">)
53
- html << %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>)
54
- p_vars[:items] = p_items # restore the items
55
- 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;">)
56
- html << %(#{pagy_t('pagy.items', items_input: input, count: p_items)})
57
- html << %(</span>#{pagy_json_tag(:items, id, MARKER, pagy.from)})
52
+ html = %(<span id="#{id}">) + %(<a href="#{pagy_url_for("#{MARKER}-page-", pagy)}"></a>)
53
+ p_vars[:items] = p_items # restore the items
54
+ 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;">)
55
+ html << %(#{pagy_t('pagy.items_selector_js', item_name: pagy_t(pagy.vars[:i18n_key], count: p_items), items_input: input, count: p_items)})
56
+ html << %(</span>#{pagy_json_tag(:items_selector, id, MARKER, pagy.from)})
58
57
  end
59
58
 
60
59
  end
@@ -23,13 +23,27 @@ class Pagy
23
23
  %(<div class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
24
24
  end
25
25
 
26
- # Compact pagination for materialize: it returns the html with the series of links to the pages
27
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
28
- def pagy_materialize_compact_nav(pagy, id=pagy_id)
26
+ # Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
27
+ def pagy_materialize_nav_js(pagy, id=pagy_id)
28
+ link, p_prev, p_next = pagy_link_proc(pagy), pagy.prev, pagy.next
29
+ tags = { 'before' => ( '<ul class="pagination">' \
30
+ + (p_prev ? %(<li class="waves-effect prev">#{link.call(p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"')}</li>)
31
+ : %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>)) ),
32
+ 'link' => %(<li class="waves-effect">#{marker = link.call(MARKER)}</li>),
33
+ 'active' => %(<li class="active">#{marker}</li>),
34
+ 'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>),
35
+ 'after' => ( (p_next ? %(<li class="waves-effect next">#{link.call(p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"')}</li>)
36
+ : %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>)) \
37
+ + '</ul>' ) }
38
+ %(<div id="#{id}" class="pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>#{pagy_json_tag(:nav, id, MARKER, tags, pagy.sequels)})
39
+ end
40
+
41
+ # Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
42
+ def pagy_materialize_combo_nav_js(pagy, id=pagy_id)
29
43
  link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.page, pagy.pages
30
44
 
31
- html = EMPTY + %(<div id="#{id}" class="pagy-materialize-compact-nav pagination" role="navigation" aria-label="pager">)
32
- html << link.call(MARKER, '', %(style="display: none;" ))
45
+ html = %(<div id="#{id}" class="pagy-materialize-combo-nav-js pagination" role="navigation" aria-label="pager">) \
46
+ + link.call(MARKER, '', %(style="display: none;" ))
33
47
  (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
34
48
  html << %(<div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;">)
35
49
  html << '<ul class="pagination" style="margin: 0px;">'
@@ -37,31 +51,10 @@ class Pagy
37
51
  html << (p_prev ? %(<li class="waves-effect prev" #{li_style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
38
52
  : %(<li class="prev disabled" #{li_style}><a href="#"><i class="material-icons">chevron_left</i></a></li>))
39
53
  input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 2px; border: none; border-radius: 2px; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
40
- html << %(<div class="pagy-compact-input btn-flat" style="cursor: default; padding: 0px">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div>)
54
+ html << %(<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div>)
41
55
  html << (p_next ? %(<li class="waves-effect next" #{li_style}>#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
42
56
  : %(<li class="next disabled" #{li_style}><a href="#"><i class="material-icons">chevron_right</i></a></li>))
43
- html << %(</ul></div>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
44
- end
45
-
46
- # Responsive pagination for Materialize: it returns the html with the series of links to the pages
47
- # rendered by the Pagy.responsive javascript
48
- def pagy_materialize_responsive_nav(pagy, id=pagy_id)
49
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive
50
-
51
- tags['before'] = EMPTY + '<ul class="pagination">'
52
- tags['before'] << (p_prev ? %(<li class="waves-effect prev">#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
53
- : %(<li class="prev disabled"><a href="#"><i class="material-icons">chevron_left</i></a></li>))
54
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
55
- tags[item.to_s] = if item.is_a?(Integer); %(<li class="waves-effect">#{link.call item}</li>) # page link
56
- elsif item.is_a?(String) ; %(<li class="active">#{link.call item}</li>) # active page
57
- elsif item == :gap ; %(<li class="gap disabled"><a href="#">#{pagy_t('pagy.nav.gap')}</a></li>) # page gap
58
- end
59
- end
60
- tags['after'] = EMPTY + (p_next ? %(<li class="waves-effect next">#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
61
- : %(<li class="next disabled"><a href="#"><i class="material-icons">chevron_right</i></a></li>))
62
- tags['after'] << '</ul>'
63
- script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
64
- %(<div id="#{id}" class="pagy-materialize-responsive-nav pagination" role="navigation" aria-label="pager"></div>#{script})
57
+ html << %(</ul></div>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
65
58
  end
66
59
 
67
60
  end
@@ -0,0 +1,40 @@
1
+ # See the Pagy documentation: https://ddnexus.github.io/pagy/extras/navs
2
+ # encoding: utf-8
3
+ # frozen_string_literal: true
4
+
5
+ require 'pagy/extras/shared'
6
+
7
+ class Pagy
8
+ module Frontend
9
+
10
+ # Javascript pagination: it returns a nav and a JSON tag used by the Pagy.nav javascript
11
+ 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> ),
15
+ 'link' => %(<span class="page">#{link.call(MARKER)}</span> ),
16
+ 'active' => %(<span class="page active">#{pagy.page}</span> ),
17
+ '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(:nav, id, MARKER, tags, pagy.sequels)})
21
+ end
22
+
23
+ # Javascript combo pagination: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
24
+ 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-js pagination" role="navigation" aria-label="pager">) \
28
+ + link.call(MARKER, '', %(style="display: none;" ))
29
+ (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
30
+ html << (p_prev ? %(<span class="page prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</span> )
31
+ : %(<span class="page prev disabled">#{pagy_t('pagy.nav.prev')}</span> ))
32
+ 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;">)
33
+ 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> )
34
+ html << (p_next ? %(<span class="page next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</span>)
35
+ : %(<span class="page next disabled">#{pagy_t('pagy.nav.next')}</span>))
36
+ html << %(</nav>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
37
+ end
38
+
39
+ end
40
+ end
@@ -7,7 +7,7 @@ require 'pagy/extras/shared'
7
7
  class Pagy
8
8
  module Frontend
9
9
 
10
- # Pagination for semantic-ui: it returns the html with the series of links to the pages
10
+ # Pagination for semantic: it returns the html with the series of links to the pages
11
11
  def pagy_semantic_nav(pagy)
12
12
  link, p_prev, p_next = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next
13
13
 
@@ -24,40 +24,33 @@ class Pagy
24
24
  %(<div class="pagy-semantic-nav ui pagination menu" aria-label="pager">#{html}</div>)
25
25
  end
26
26
 
27
- # Compact pagination for semantic: it returns the html with the series of links to the pages
28
- # we use a numeric input tag to set the page and the Pagy.compact javascript to navigate
29
- def pagy_semantic_compact_nav(pagy, id=pagy_id)
27
+ # Javascript pagination for semantic: it returns a nav and a JSON tag used by the Pagy.nav javascript
28
+ 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(MARKER)}),
33
+ 'active' => %(<a class="item active">#{pagy.page}</a>),
34
+ '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(:nav, id, MARKER, tags, pagy.sequels)})
38
+ end
39
+
40
+ # Combo pagination for semantic: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
41
+ def pagy_semantic_combo_nav_js(pagy, id=pagy_id)
30
42
  link, p_prev, p_next, p_page, p_pages = pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.page, pagy.pages
31
43
 
32
- html = EMPTY + %(<div id="#{id}" class="pagy-semantic-compact-nav ui compact menu" role="navigation" aria-label="pager">)
33
- html << link.call(MARKER, '', %(style="display: none;" ))
44
+ html = %(<div id="#{id}" class="pagy-semantic-combo-nav-js ui compact menu" role="navigation" aria-label="pager">) \
45
+ + link.call(MARKER, '', %(style="display: none;" ))
34
46
  (html << link.call(1, '', %(style="display: none;" ))) if defined?(TRIM)
35
47
  html << (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
36
48
  : %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
37
49
  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">)
38
- html << %(<div class="pagy-compact-input item">#{pagy_t('pagy.compact', page_input: input, count: p_page, pages: p_pages)}</div> )
50
+ html << %(<div class="pagy-combo-input item">#{pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages)}</div> )
39
51
  html << (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
40
52
  : %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
41
- html << %(</div>#{pagy_json_tag(:compact, id, MARKER, p_page, !!defined?(TRIM))})
42
- end
43
-
44
- # Responsive pagination for semantic: it returns the html with the series of links to the pages
45
- # rendered by the Pagy.responsive javascript
46
- def pagy_semantic_responsive_nav(pagy, id=pagy_id)
47
- tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="item"'), pagy.prev, pagy.next, pagy.responsive
48
-
49
- tags['before'] = (p_prev ? %(#{link.call p_prev, '<i class="left small chevron icon"></i>', 'aria-label="previous"'})
50
- : %(<div class="item disabled"><i class="left small chevron icon"></i></div>))
51
- responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
52
- tags[item.to_s] = if item.is_a?(Integer); %(#{link.call item}) # page link
53
- elsif item.is_a?(String) ; %(<a class="item active">#{item}</a>) # current page
54
- elsif item == :gap ; %(<div class="disabled item">...</div>) # page gap
55
- end
56
- end
57
- tags['after'] = (p_next ? %(#{link.call p_next, '<i class="right small chevron icon"></i>', 'aria-label="next"'})
58
- : %(<div class="item disabled"><i class="right small chevron icon"></i></div>))
59
- script = pagy_json_tag(:responsive, id, tags, responsive[:widths], responsive[:series])
60
- %(<div id="#{id}" class="pagy-semantic-responsive-nav ui pagination menu" role="navigation" aria-label="pager"></div>#{script})
53
+ html << %(</div>#{pagy_json_tag(:combo_nav, id, MARKER, p_page, !!defined?(TRIM))})
61
54
  end
62
55
 
63
56
  end