diff --git a/CHANGELOG.md b/CHANGELOG.md index 235a783e8..bfc76b735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ None - Dropped old rubies support: Pagy follows the [ruby end-of-life](https://endoflife.date/ruby) supported rubies now. - Renamed `:i18n_key` > `:item_i18n_key` +- Refactored `support` extra + - Removed `pagy_prev_link`: use `pagy_prev_html` without the `:text` argument (can customize `pagy.nav.prev`) + - Removed `pagy_next_link`: use `pagy_next_html` without the `:text` argument (can customize `pagy.nav.next`) ### Default changes possibly breaking test/views diff --git a/apps/pagy_standalone_app.ru b/apps/pagy_standalone_app.ru index 1e4e0f774..cf7ff25a6 100644 --- a/apps/pagy_standalone_app.ru +++ b/apps/pagy_standalone_app.ru @@ -25,7 +25,7 @@ require 'bundler/inline' # NOTICE: if you get any installation error with the following setup # temporarily remove the Gemfile and Gemfile.lock from the repo (they may interfere with the bundler/inline) -gemfile true do +gemfile false do source 'https://rubygems.org' gem 'oj' gem 'rack' diff --git a/docs/extras/support.md b/docs/extras/support.md index 60d53904d..25795e6cf 100644 --- a/docs/extras/support.md +++ b/docs/extras/support.md @@ -29,7 +29,7 @@ You can totally avoid one query per render by using the [countless](countless.md If you don't need the navbar you can just set the `:size` variable to an empty value and the page links will be skipped from the rendering. That works with `Pagy` and `Pagy:Countless` instances. All the `*nav` helpers will render only the `prev` and `next` links/buttons, allowing for a manual incremental pagination. -You can also use the [`pagy_prev_link`](https://github.com/ddnexus/pagy/blob/dca8669a10cb3be13e053fe435301c22cc64406f/lib/pagy/extras/navs.rb#L46) and [`pagy_next_link`](https://github.com/ddnexus/pagy/blob/dca8669a10cb3be13e053fe435301c22cc64406f/lib/pagy/extras/navs.rb#L54) helpers provided by the [navs extra](navs), mostly useful if you also use the `countless` extra. +You can also use the [`pagy_prev_html`](https://github.com/ddnexus/pagy/blob/dca8669a10cb3be13e053fe435301c22cc64406f/lib/pagy/extras/navs.rb#L46) and [`pagy_next_html`](https://github.com/ddnexus/pagy/blob/dca8669a10cb3be13e053fe435301c22cc64406f/lib/pagy/extras/navs.rb#L54) helpers provided by the [navs extra](navs), mostly useful if you also use the `countless` extra. Here is a basic example that uses `pagy_countless` (saving one query per render): @@ -77,7 +77,7 @@ end ||| _next_link.html.erb (partial) ```erb -<%== pagy_next_link(@pagy, text: 'More...', link_extra: 'id="next_link"') %> +<%== pagy_next_html(@pagy, text: 'More...', link_extra: 'id="next_link"') %> ``` ||| @@ -103,7 +103,7 @@ For a plain old javascript example, we are going to use the same [Incremental](# ||| _next_link.html.erb (partial) ```erb -<%== pagy_next_link(@pagy, text: 'More...', link_extra: 'id="next_link" style="display: none;"') %> +<%== pagy_next_html(@pagy, text: 'More...', link_extra: 'id="next_link" style="display: none;"') %> ``` ||| @@ -147,7 +147,7 @@ You may want to combine it with something like: ||| View ```erb -<%== pagy_next_link(@pagy, text: 'More...') %> +<%== pagy_next_html(@pagy, text: 'More...') %> ``` ||| @@ -161,15 +161,18 @@ Returns the url for the previous page. Useful to build minimalistic UIs that don Returns the url for the next page. Useful to build minimalistic UIs that don't use nav bar links (e.g. `countless` extra). -==- `pagy_prev_link(pagy, text: pagy_t('pagy.nav.prev'), link_extra: "")` +==- `pagy_prev_html(pagy, link_extra: "")` -Returns the `a` tag for the previous page. It is the same prev link string which is part of the `pagy_nav` helper. +Returns the enabled/disabled HTML string for the previous page link. It is the same prev link string which is +part of the +`pagy_nav` helper. Useful to build minimalistic helpers UIs that don't use nav bar links (e.g. `countless` extra). -==- `pagy_next_link(pagy, text: pagy_t('pagy.nav.next'), link_extra: "")` +==- `pagy_next_html(pagy, link_extra: "")` -Returns the `a` tag for the next page. It is the same next link string which is part of the `pagy_nav` helper. +Returns the enabled/disabled HTML string for the next page link. It is the same next link string which is part of the +`pagy_nav` helper. Useful to build minimalistic helpers UIs that don't use nav bar links (e.g. `countless` extra). diff --git a/lib/pagy.rb b/lib/pagy.rb index f0099b02c..cd6cc89a6 100644 --- a/lib/pagy.rb +++ b/lib/pagy.rb @@ -22,6 +22,7 @@ def self.root fragment: '', link_extra: '', item_i18n_key: 'pagy.item_name', + page_i18n_key: 'pagy.page_label', cycle: false, request_path: '' } diff --git a/lib/pagy/extras/frontend_helpers.rb b/lib/pagy/extras/frontend_helpers.rb index b04945699..2bd432254 100644 --- a/lib/pagy/extras/frontend_helpers.rb +++ b/lib/pagy/extras/frontend_helpers.rb @@ -6,7 +6,7 @@ class Pagy # :nodoc: # Private module documented in the main classes module FrontendHelpers # Additions for the Pagy class - module Pagy + module PagyOverride # `Pagy` instance method used by the `pagy*_nav_js` helpers. # It returns the sequels of width/series generated from the :steps hash # Example: @@ -26,10 +26,12 @@ def sequels(steps: @vars[:steps] || { 0 => @vars[:size] }, **_) # Support for the Calendar API def label_sequels(*); end + end + Pagy.prepend PagyOverride # Additions for Calendar class - module Calendar + module CalendarOverride def label_sequels(sequels = self.sequels) {}.tap do |label_sequels| sequels.each do |width, series| @@ -38,9 +40,10 @@ def label_sequels(sequels = self.sequels) end end end + Calendar.prepend CalendarOverride if defined?(Calendar) # Additions for the Frontend - module Frontend + module FrontendOverride if defined?(Oj) # Return a data tag with the base64 encoded JSON-serialized args generated with the faster oj gem # Base64 encoded JSON is smaller than HTML escaped JSON @@ -65,8 +68,6 @@ def pagy_marked_link(link) link.call PAGE_PLACEHOLDER, '', 'style="display: none;"' end end + Frontend.prepend FrontendOverride end - prepend FrontendHelpers::Pagy - Calendar.prepend FrontendHelpers::Calendar if defined?(Calendar) - Frontend.prepend FrontendHelpers::Frontend end diff --git a/lib/pagy/extras/navs.rb b/lib/pagy/extras/navs.rb index e4066a53f..81f492274 100644 --- a/lib/pagy/extras/navs.rb +++ b/lib/pagy/extras/navs.rb @@ -8,56 +8,43 @@ class Pagy # :nodoc: # The resulting code may not look very elegant, but produces the best benchmarks module NavsExtra # Javascript pagination: it returns a nav and a JSON tag used by the pagy.js file - def pagy_nav_js(pagy, pagy_id: nil, link_extra: '', **vars) + def pagy_nav_js(pagy, pagy_id: nil, link_extra: '', + page_label: nil, page_i18n_key: nil, **vars) sequels = pagy.sequels(**vars) p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra:) tags = { 'before' => pagy_nav_prev_html(pagy, link), 'link' => %(#{link.call(PAGE_PLACEHOLDER, LABEL_PLACEHOLDER)} ), - 'active' => %(#{LABEL_PLACEHOLDER} ), + 'active' => %() + + %(#{LABEL_PLACEHOLDER} ), 'gap' => %(#{pagy_t 'pagy.nav.gap'} ), 'after' => pagy_nav_next_html(pagy, link) } %() + pagy_aria_label(pagy, page_label, page_i18n_key)} #{ + pagy_data(pagy, :nav, tags, sequels, pagy.label_sequels(sequels)) + }>) end # Javascript combo pagination: it returns a nav and a JSON tag used by the pagy.js file - def pagy_combo_nav_js(pagy, pagy_id: nil, link_extra: '') + def pagy_combo_nav_js(pagy, pagy_id: nil, link_extra: '', + page_label: nil, page_i18n_key: nil) p_id = %( id="#{pagy_id}") if pagy_id link = pagy_link_proc(pagy, link_extra:) p_page = pagy.page p_pages = pagy.pages - input = %() + input = %() %(#{ - pagy_nav_prev_html pagy, link + pagy_aria_label(pagy, page_label, page_i18n_key)} #{ + pagy_data(pagy, :combo, pagy_marked_link(link))}>#{pagy_nav_prev_html(pagy, link) }#{ - pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages + pagy_t('pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages) } #{ - pagy_nav_next_html pagy, link + pagy_nav_next_html(pagy, link) }) end - - private - - def pagy_nav_prev_html(pagy, link) - if (p_prev = pagy.prev) - %(#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'} ) - else - %(#{pagy_t 'pagy.nav.prev'} ) - end - end - - def pagy_nav_next_html(pagy, link) - if (p_next = pagy.next) - %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}) - else - %(#{pagy_t 'pagy.nav.next'}) - end - end end Frontend.prepend NavsExtra end diff --git a/lib/pagy/extras/support.rb b/lib/pagy/extras/support.rb index 7002fd750..74ca57e17 100644 --- a/lib/pagy/extras/support.rb +++ b/lib/pagy/extras/support.rb @@ -14,38 +14,24 @@ def pagy_next_url(pagy) pagy_url_for(pagy, pagy.next) if pagy.next end - # Return the HTML string for the previous page link - def pagy_prev_link(pagy, text: pagy_t('pagy.nav.prev'), link_extra: '') - if pagy.prev - %() - else - %(#{text}) - end + # Return the enabled/disabled HTML string for the previous page link + def pagy_prev_html(pagy, link_extra: '', **vars) + link = pagy_link_proc(pagy, link_extra:) + pagy_nav_prev_html(pagy, link) end - # Return the HTML string for the next page link - def pagy_next_link(pagy, text: pagy_t('pagy.nav.next'), link_extra: '') - if pagy.next - %() - else - %(#{text}) - end + # Return the enabled/disabled HTML string for the next page link + def pagy_next_html(pagy, link_extra: '') + link = pagy_link_proc(pagy, link_extra:) + pagy_nav_next_html(pagy, link) end - # Return the HTML link tag for the previous page or nil + # Conditionally return the HTML link tag string for the previous page def pagy_prev_link_tag(pagy) %() if pagy.prev end - # Return the HTML link tag for the next page or nil + # Conditionally return the HTML link tag string for the next page def pagy_next_link_tag(pagy) %() if pagy.next end diff --git a/lib/pagy/frontend.rb b/lib/pagy/frontend.rb index 31237e884..20b89e890 100644 --- a/lib/pagy/frontend.rb +++ b/lib/pagy/frontend.rb @@ -15,32 +15,27 @@ module Frontend include UrlHelpers # Generic pagination: it returns the html with the series of links to the pages - def pagy_nav(pagy, pagy_id: nil, link_extra: '', **vars) - p_id = %( id="#{pagy_id}") if pagy_id - link = pagy_link_proc(pagy, link_extra:) - p_prev = pagy.prev - p_next = pagy.next + def pagy_nav(pagy, pagy_id: nil, link_extra: '', + page_label: nil, page_i18n_key: nil, **vars) + p_id = %( id="#{pagy_id}") if pagy_id + link = pagy_link_proc(pagy, link_extra:) - html = +%() - html << if p_prev - %(#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'} ) - else - %(#{pagy_t('pagy.nav.prev')} ) - end + html = +%() + html << pagy_nav_prev_html(pagy, link) pagy.series(**vars).each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] html << case item - when Integer then %(#{link.call item} ) - when String then %(#{pagy.label_for(item)} ) - when :gap then %(#{pagy_t('pagy.nav.gap')} ) - else raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}" + when Integer + %(#{link.call(item)} ) + when String + %() + + %(#{pagy.label_for(item)} ) + when :gap + %(#{pagy_t('pagy.nav.gap')} ) + else + raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}" end end - html << if p_next - %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}) - else - %(#{pagy_t('pagy.nav.next')}) - end - html << %() + html << %(#{pagy_nav_next_html(pagy, link)}) end # Return examples: "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total" @@ -79,5 +74,29 @@ def pagy_link_proc(pagy, link_extra: '') def pagy_t(key, opts = {}) Pagy::I18n.translate(@pagy_locale ||= nil, key, opts) end + + # Return the translated aria label + def pagy_aria_label(pagy, page_label, page_i18n_key, count: pagy.pages) + page_label ||= pagy_t(page_i18n_key || pagy.vars[:page_i18n_key], count: count) + %(aria-label="#{page_label}") + end + + private + + def pagy_nav_prev_html(pagy, link) + if (p_prev = pagy.prev) + %(#{link.call p_prev, pagy_t('pagy.nav.prev')} ) + else + %( ) + end + end + + def pagy_nav_next_html(pagy, link) + if (p_next = pagy.next) + %(#{link.call p_next, pagy_t('pagy.nav.next')}) + else + %() + end + end end end diff --git a/test/pagy/extras/metadata_test.rb.rematch b/test/pagy/extras/metadata_test.rb.rematch index 1437d4a3c..4936ed32f 100644 --- a/test/pagy/extras/metadata_test.rb.rematch +++ b/test/pagy/extras/metadata_test.rb.rematch @@ -14,6 +14,32 @@ :prev: 2 :next: 4 :pages: 26 +"[1] pagy/extras/metadata::#pagy_metadata for Pagy#test_0004_returns only specific metadata": + :scaffold_url: "/foo?page=__pagy_page__" + :page: 3 + :count: 1000 + :prev: 2 + :next: 4 + :pages: 50 +"[1] pagy/extras/metadata::#pagy_metadata for Pagy#test_0001_defines all metadata": +- :scaffold_url +- :first_url +- :prev_url +- :page_url +- :next_url +- :last_url +- :count +- :page +- :items +- :vars +- :pages +- :last +- :in +- :from +- :to +- :prev +- :next +- :series "[1] pagy/extras/metadata::#pagy_metadata for Pagy#test_0002_returns the full pagy metadata": :scaffold_url: "/foo?page=__pagy_page__" :first_url: "/foo?page=1" @@ -38,6 +64,7 @@ :fragment: '' :link_extra: '' :item_i18n_key: pagy.item_name + :page_i18n_key: pagy.page_label :cycle: false :request_path: '' :steps: false @@ -91,29 +118,3 @@ - 7 - :gap - 50 -"[1] pagy/extras/metadata::#pagy_metadata for Pagy#test_0001_defines all metadata": -- :scaffold_url -- :first_url -- :prev_url -- :page_url -- :next_url -- :last_url -- :count -- :page -- :items -- :vars -- :pages -- :last -- :in -- :from -- :to -- :prev -- :next -- :series -"[1] pagy/extras/metadata::#pagy_metadata for Pagy#test_0004_returns only specific metadata": - :scaffold_url: "/foo?page=__pagy_page__" - :page: 3 - :count: 1000 - :prev: 2 - :next: 4 - :pages: 50 diff --git a/test/pagy/extras/navs_test.rb b/test/pagy/extras/navs_test.rb index dfa2586c3..f48a7e57e 100644 --- a/test/pagy/extras/navs_test.rb +++ b/test/pagy/extras/navs_test.rb @@ -15,7 +15,7 @@ _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch end - it 'renders first page when used with Pagy::Countless' do + it 'renders single page when used with Pagy::Countless' do require 'pagy/extras/countless' pagy, = Pagy::Countless.new(page: 1).finalize(0) @@ -23,6 +23,14 @@ _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch end + it 'renders first page of multiple when used with Pagy::Countless' do + require 'pagy/extras/countless' + + pagy, = Pagy::Countless.new(page: 1).finalize(23) + _(app.pagy_nav_js(pagy)).must_rematch + _(app.pagy_nav_js(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra', + steps: { 0 => [1, 2, 2, 1], 600 => [1, 3, 3, 1] })).must_rematch + end it 'renders intermediate page' do pagy = Pagy.new(size: [1, 4, 4, 1], count: 1000, page: 20) _(app.pagy_nav_js(pagy)).must_rematch diff --git a/test/pagy/extras/navs_test.rb.rematch b/test/pagy/extras/navs_test.rb.rematch index 91a6c61f8..3bf03f684 100644 --- a/test/pagy/extras/navs_test.rb.rematch +++ b/test/pagy/extras/navs_test.rb.rematch @@ -1,70 +1,65 @@ --- -"[1] pagy/extras/navs::#pagy_nav_js#test_0003_renders last page": -"[2] pagy/extras/navs::#pagy_nav_js#test_0003_renders last page": -"[1] pagy/extras/navs::#pagy_nav_js#test_0004_renders with :steps": -"[2] pagy/extras/navs::#pagy_nav_js#test_0004_renders with :steps": +"[1] pagy/extras/navs::#pagy_nav_js#test_0004_renders intermediate page": +"[2] pagy/extras/navs::#pagy_nav_js#test_0004_renders intermediate page": +"[1] pagy/extras/navs::#pagy_nav_js#test_0003_renders first page of multiple when used with Pagy::Countless": +"[2] pagy/extras/navs::#pagy_nav_js#test_0003_renders first page of multiple when used with Pagy::Countless": +"[1] pagy/extras/navs::#pagy_nav_js#test_0005_renders last page": +"[2] pagy/extras/navs::#pagy_nav_js#test_0005_renders last page": +"[1] pagy/extras/navs::#pagy_nav_js#test_0002_renders single page when used with Pagy::Countless": +"[2] pagy/extras/navs::#pagy_nav_js#test_0002_renders single page when used with Pagy::Countless": +"[1] pagy/extras/navs::#pagy_nav_js#test_0006_renders with :steps": +"[2] pagy/extras/navs::#pagy_nav_js#test_0006_renders with :steps": "[1] pagy/extras/navs::#pagy_nav_js#test_0001_renders first page": + pagination" aria-label="Pages" data-pagy="WyJuYXYiLHsiYmVmb3JlIjoiPHNwYW4gY2xhc3M9XCJwYWdlIHByZXYgZGlzYWJsZWRcIj48YSByb2xlPVwibGlua1wiIGFyaWEtZGlzYWJsZWQ9XCJ0cnVlXCIgcmVsPVwicHJldlwiPiZsc2FxdW87Jm5ic3A7UHJldjwvYT48L3NwYW4+ICIsImxpbmsiOiI8c3BhbiBjbGFzcz1cInBhZ2VcIj48YSBocmVmPVwiL2Zvbz9wYWdlPV9fcGFneV9wYWdlX19cIiAgID5fX3BhZ3lfbGFiZWxfXzwvYT48L3NwYW4+ICIsImFjdGl2ZSI6IjxzcGFuIGNsYXNzPVwicGFnZSBhY3RpdmVcIj48YSByb2xlPVwibGlua1wiIGFyaWEtZGlzYWJsZWQ9XCJ0cnVlXCIgYXJpYS1jdXJyZW50PVwicGFnZVwiPl9fcGFneV9sYWJlbF9fPC9hPjwvc3Bhbj4gIiwiZ2FwIjoiPHNwYW4gY2xhc3M9XCJwYWdlIGdhcFwiPiZoZWxsaXA7PC9zcGFuPiAiLCJhZnRlciI6IjxzcGFuIGNsYXNzPVwicGFnZSBuZXh0XCI+PGEgaHJlZj1cIi9mb28/cGFnZT0yXCIgICByZWw9XCJuZXh0XCIgPk5leHQmbmJzcDsmcnNhcXVvOzwvYT48L3NwYW4+In0seyIwIjpbIjEiLDIsMyw0LDUsImdhcCIsNTBdfSxudWxsXQ=="> "[2] pagy/extras/navs::#pagy_nav_js#test_0001_renders first page": -"[1] pagy/extras/navs::#pagy_nav_js#test_0002_renders intermediate page": -"[2] pagy/extras/navs::#pagy_nav_js#test_0002_renders intermediate page": + class="pagy-rjs pagy-nav-js pagination" aria-label="Pages" data-pagy="WyJuYXYiLHsiYmVmb3JlIjoiPHNwYW4gY2xhc3M9XCJwYWdlIHByZXYgZGlzYWJsZWRcIj48YSByb2xlPVwibGlua1wiIGFyaWEtZGlzYWJsZWQ9XCJ0cnVlXCIgcmVsPVwicHJldlwiPiZsc2FxdW87Jm5ic3A7UHJldjwvYT48L3NwYW4+ICIsImxpbmsiOiI8c3BhbiBjbGFzcz1cInBhZ2VcIj48YSBocmVmPVwiL2Zvbz9wYWdlPV9fcGFneV9wYWdlX19cIiAgbGluay1leHRyYSA+X19wYWd5X2xhYmVsX188L2E+PC9zcGFuPiAiLCJhY3RpdmUiOiI8c3BhbiBjbGFzcz1cInBhZ2UgYWN0aXZlXCI+PGEgcm9sZT1cImxpbmtcIiBhcmlhLWRpc2FibGVkPVwidHJ1ZVwiIGFyaWEtY3VycmVudD1cInBhZ2VcIj5fX3BhZ3lfbGFiZWxfXzwvYT48L3NwYW4+ICIsImdhcCI6IjxzcGFuIGNsYXNzPVwicGFnZSBnYXBcIj4maGVsbGlwOzwvc3Bhbj4gIiwiYWZ0ZXIiOiI8c3BhbiBjbGFzcz1cInBhZ2UgbmV4dFwiPjxhIGhyZWY9XCIvZm9vP3BhZ2U9MlwiICBsaW5rLWV4dHJhIHJlbD1cIm5leHRcIiA+TmV4dCZuYnNwOyZyc2FxdW87PC9hPjwvc3Bhbj4ifSx7IjAiOlsiMSIsMiwzLCJnYXAiLDUwXSwiNjAwIjpbIjEiLDIsMyw0LCJnYXAiLDUwXX0sbnVsbF0="> +"[1] pagy/extras/navs::#pagy_combo_nav_js#test_0003_renders last page": '' +"[2] pagy/extras/navs::#pagy_combo_nav_js#test_0003_renders last page": '' "[1] pagy/extras/navs::#pagy_combo_nav_js#test_0002_renders intermediate page": '' + of 6 ' "[2] pagy/extras/navs::#pagy_combo_nav_js#test_0002_renders intermediate page": '' + >Next ›' "[1] pagy/extras/navs::#pagy_combo_nav_js#test_0001_renders first page": '' -"[2] pagy/extras/navs::#pagy_combo_nav_js#test_0001_renders first page": '' -"[1] pagy/extras/navs::#pagy_combo_nav_js#test_0003_renders last page": '' -"[2] pagy/extras/navs::#pagy_combo_nav_js#test_0003_renders last page": '' +"[2] pagy/extras/navs::#pagy_combo_nav_js#test_0001_renders first page": '' -"[1] pagy/extras/navs::#pagy_nav_js#test_0002_renders first page when used with Pagy::Countless": -"[2] pagy/extras/navs::#pagy_nav_js#test_0002_renders first page when used with Pagy::Countless": -"[1] pagy/extras/navs::#pagy_nav_js#test_0004_renders last page": -"[2] pagy/extras/navs::#pagy_nav_js#test_0004_renders last page": -"[1] pagy/extras/navs::#pagy_nav_js#test_0003_renders intermediate page": -"[2] pagy/extras/navs::#pagy_nav_js#test_0003_renders intermediate page": -"[1] pagy/extras/navs::#pagy_nav_js#test_0005_renders with :steps": -"[2] pagy/extras/navs::#pagy_nav_js#test_0005_renders with :steps": + min="1" max="6" value="1" style="padding: 0; text-align: center; width: 2rem;"> + of 6 ' diff --git a/test/pagy/extras/support_test.rb b/test/pagy/extras/support_test.rb index 755b3ce49..b0ae7b650 100644 --- a/test/pagy/extras/support_test.rb +++ b/test/pagy/extras/support_test.rb @@ -63,39 +63,39 @@ end end - describe '#pagy_prev_link' do + describe '#pagy_prev_html' do it 'renders the prev link for page 1' do pagy = Pagy.new count: 1000, page: 1 pagy_countless = Pagy::Countless.new(page: 1).finalize(21) - _(app.pagy_prev_link(pagy)).must_rematch - _(app.pagy_prev_link(pagy_countless)).must_rematch - _(app.pagy_prev_link(pagy, text: 'PREV', link_extra: 'link-extra')).must_rematch - _(app.pagy_prev_link(pagy_countless, text: 'PREV', link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy)).must_rematch + _(app.pagy_prev_html(pagy_countless)).must_rematch + _(app.pagy_prev_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy_countless, link_extra: 'link-extra')).must_rematch end it 'renders the prev link for page 3' do pagy = Pagy.new count: 1000, page: 3 pagy_countless = Pagy::Countless.new(page: 3).finalize(21) - _(app.pagy_prev_link(pagy)).must_rematch - _(app.pagy_prev_link(pagy_countless)).must_rematch - _(app.pagy_prev_link(pagy, text: 'PREV', link_extra: 'link-extra')).must_rematch - _(app.pagy_prev_link(pagy_countless, text: 'PREV', link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy)).must_rematch + _(app.pagy_prev_html(pagy_countless)).must_rematch + _(app.pagy_prev_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy_countless, link_extra: 'link-extra')).must_rematch end it 'renders the prev link for page 6' do pagy = Pagy.new count: 1000, page: 6 pagy_countless = Pagy::Countless.new(page: 6).finalize(21) - _(app.pagy_prev_link(pagy)).must_rematch - _(app.pagy_prev_link(pagy_countless)).must_rematch - _(app.pagy_prev_link(pagy, text: 'PREV', link_extra: 'link-extra')).must_rematch - _(app.pagy_prev_link(pagy_countless, text: 'PREV', link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy)).must_rematch + _(app.pagy_prev_html(pagy_countless)).must_rematch + _(app.pagy_prev_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy_countless, link_extra: 'link-extra')).must_rematch end it 'renders the prev link for last page' do pagy = Pagy.new count: 1000, page: 50 pagy_countless = Pagy::Countless.new(page: 50).finalize(20) - _(app.pagy_prev_link(pagy)).must_rematch - _(app.pagy_prev_link(pagy_countless)).must_rematch - _(app.pagy_prev_link(pagy, text: 'PREV', link_extra: 'link-extra')).must_rematch - _(app.pagy_prev_link(pagy_countless, text: 'PREV', link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy)).must_rematch + _(app.pagy_prev_html(pagy_countless)).must_rematch + _(app.pagy_prev_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_prev_html(pagy_countless, link_extra: 'link-extra')).must_rematch end end @@ -103,34 +103,34 @@ it 'renders the next link for page 1' do pagy = Pagy.new count: 1000, page: 1 pagy_countless = Pagy::Countless.new(page: 1).finalize(21) - _(app.pagy_next_link(pagy)).must_rematch - _(app.pagy_next_link(pagy_countless)).must_rematch - _(app.pagy_next_link(pagy, text: 'NEXT', link_extra: 'link-extra')).must_rematch - _(app.pagy_next_link(pagy_countless, text: 'NEXT', link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy)).must_rematch + _(app.pagy_next_html(pagy_countless)).must_rematch + _(app.pagy_next_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy_countless, link_extra: 'link-extra')).must_rematch end it 'renders the next link for page 3' do pagy = Pagy.new count: 1000, page: 3 pagy_countless = Pagy::Countless.new(page: 3).finalize(21) - _(app.pagy_next_link(pagy)).must_rematch - _(app.pagy_next_link(pagy_countless)).must_rematch - _(app.pagy_next_link(pagy, text: 'NEXT', link_extra: 'link-extra')).must_rematch - _(app.pagy_next_link(pagy_countless, text: 'NEXT', link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy)).must_rematch + _(app.pagy_next_html(pagy_countless)).must_rematch + _(app.pagy_next_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy_countless, link_extra: 'link-extra')).must_rematch end it 'renders the next link for page 6' do pagy = Pagy.new count: 1000, page: 6 pagy_countless = Pagy::Countless.new(page: 6).finalize(21) - _(app.pagy_next_link(pagy)).must_rematch - _(app.pagy_next_link(pagy_countless)).must_rematch - _(app.pagy_next_link(pagy, text: 'NEXT', link_extra: 'link-extra')).must_rematch - _(app.pagy_next_link(pagy_countless, text: 'NEXT', link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy)).must_rematch + _(app.pagy_next_html(pagy_countless)).must_rematch + _(app.pagy_next_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy_countless, link_extra: 'link-extra')).must_rematch end it 'renders the next link for last page' do pagy = Pagy.new count: 1000, page: 50 pagy_countless = Pagy::Countless.new(page: 50).finalize(20) - _(app.pagy_next_link(pagy)).must_rematch - _(app.pagy_next_link(pagy_countless)).must_rematch - _(app.pagy_next_link(pagy, text: 'NEXT', link_extra: 'link-extra')).must_rematch - _(app.pagy_next_link(pagy_countless, text: 'NEXT', link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy)).must_rematch + _(app.pagy_next_html(pagy_countless)).must_rematch + _(app.pagy_next_html(pagy, link_extra: 'link-extra')).must_rematch + _(app.pagy_next_html(pagy_countless, link_extra: 'link-extra')).must_rematch end end diff --git a/test/pagy/extras/support_test.rb.rematch b/test/pagy/extras/support_test.rb.rematch index ea889d1d2..ca96edf34 100644 --- a/test/pagy/extras/support_test.rb.rematch +++ b/test/pagy/extras/support_test.rb.rematch @@ -1,48 +1,52 @@ --- -"[1] pagy/extras/support::#pagy_prev_link#test_0002_renders the prev link for page 3": -"[2] pagy/extras/support::#pagy_prev_link#test_0002_renders the prev link for page 3": -"[3] pagy/extras/support::#pagy_prev_link#test_0002_renders the prev link for page 3": -"[4] pagy/extras/support::#pagy_prev_link#test_0002_renders the prev link for page 3": -"[1] pagy/extras/support::#pagy_prev_link#test_0001_renders the prev link for page 1": ‹ Prev -"[2] pagy/extras/support::#pagy_prev_link#test_0001_renders the prev link for page 1": ‹ Prev -"[3] pagy/extras/support::#pagy_prev_link#test_0001_renders the prev link for page 1": PREV -"[4] pagy/extras/support::#pagy_prev_link#test_0001_renders the prev link for page 1": PREV -"[1] pagy/extras/support::#pagy_prev_link#test_0003_renders the prev link for page 6": -"[2] pagy/extras/support::#pagy_prev_link#test_0003_renders the prev link for page 6": -"[3] pagy/extras/support::#pagy_prev_link#test_0003_renders the prev link for page 6": -"[4] pagy/extras/support::#pagy_prev_link#test_0003_renders the prev link for page 6": -"[1] pagy/extras/support::#pagy_prev_link#test_0004_renders the prev link for last page": -"[2] pagy/extras/support::#pagy_prev_link#test_0004_renders the prev link for last page": -"[3] pagy/extras/support::#pagy_prev_link#test_0004_renders the prev link for last page": -"[4] pagy/extras/support::#pagy_prev_link#test_0004_renders the prev link for last page": -"[1] pagy/extras/support::#pagy_prev_link_tag#test_0003_renders the prev link tag for page 6": -"[2] pagy/extras/support::#pagy_prev_link_tag#test_0003_renders the prev link tag for page 6": +"[1] pagy/extras/support::#pagy_prev_html#test_0002_renders the prev link for page 3": ' ' +"[2] pagy/extras/support::#pagy_prev_html#test_0002_renders the prev link for page 3": ' ' +"[3] pagy/extras/support::#pagy_prev_html#test_0002_renders the prev link for page 3": ' ' +"[4] pagy/extras/support::#pagy_prev_html#test_0002_renders the prev link for page 3": ' ' +"[1] pagy/extras/support::#pagy_prev_html#test_0003_renders the prev link for page 6": ' ' +"[2] pagy/extras/support::#pagy_prev_html#test_0003_renders the prev link for page 6": ' ' +"[3] pagy/extras/support::#pagy_prev_html#test_0003_renders the prev link for page 6": ' ' +"[4] pagy/extras/support::#pagy_prev_html#test_0003_renders the prev link for page 6": ' ' +"[1] pagy/extras/support::#pagy_prev_html#test_0004_renders the prev link for last page": ' ' +"[2] pagy/extras/support::#pagy_prev_html#test_0004_renders the prev link for last page": ' ' +"[3] pagy/extras/support::#pagy_prev_html#test_0004_renders the prev link for last page": ' ' +"[4] pagy/extras/support::#pagy_prev_html#test_0004_renders the prev link for last page": ' ' +"[1] pagy/extras/support::#pagy_prev_html#test_0001_renders the prev link for page 1": ' ' +"[2] pagy/extras/support::#pagy_prev_html#test_0001_renders the prev link for page 1": ' ' +"[3] pagy/extras/support::#pagy_prev_html#test_0001_renders the prev link for page 1": ' ' +"[4] pagy/extras/support::#pagy_prev_html#test_0001_renders the prev link for page 1": ' ' "[1] pagy/extras/support::#pagy_prev_link_tag#test_0002_renders the prev link tag for page 3": "[2] pagy/extras/support::#pagy_prev_link_tag#test_0002_renders the prev link tag for page 3": +"[1] pagy/extras/support::#pagy_prev_link_tag#test_0003_renders the prev link tag for page 6": +"[2] pagy/extras/support::#pagy_prev_link_tag#test_0003_renders the prev link tag for page 6": "[1] pagy/extras/support::#pagy_prev_link_tag#test_0004_renders the prev link tag for last page": "[2] pagy/extras/support::#pagy_prev_link_tag#test_0004_renders the prev link tag for last page": +"[1] pagy/extras/support::#pagy_next_link_tag#test_0002_renders the next link tag for page 3": +"[2] pagy/extras/support::#pagy_next_link_tag#test_0002_renders the next link tag for page 3": "[1] pagy/extras/support::#pagy_next_link_tag#test_0003_renders the next link tag for page 6": "[2] pagy/extras/support::#pagy_next_link_tag#test_0003_renders the next link tag for page 6": "[2] pagy/extras/support::#pagy_next_link_tag#test_0001_renders the next link tag for page 1": -"[1] pagy/extras/support::#pagy_next_link_tag#test_0002_renders the next link tag for page 3": -"[2] pagy/extras/support::#pagy_next_link_tag#test_0002_renders the next link tag for page 3": -"[1] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": -"[2] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": -"[3] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": -"[4] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": +"[1] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": +"[2] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": +"[3] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": +"[4] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": "[1] pagy/extras/support::#pagy_next_link#test_0003_renders the next link for page 6": + class="page next"> "[2] pagy/extras/support::#pagy_next_link#test_0003_renders the next link for page 6": + class="page next"> "[3] pagy/extras/support::#pagy_next_link#test_0003_renders the next link for page 6": + class="page next"> "[4] pagy/extras/support::#pagy_next_link#test_0003_renders the next link for page 6": + class="page next"> "[1] pagy/extras/support::#pagy_next_link#test_0004_renders the next link for last page": Next › + class="page next disabled"> "[2] pagy/extras/support::#pagy_next_link#test_0004_renders the next link for last page": Next › + class="page next disabled"> "[3] pagy/extras/support::#pagy_next_link#test_0004_renders the next link for last page": NEXT + class="page next disabled"> "[4] pagy/extras/support::#pagy_next_link#test_0004_renders the next link for last page": NEXT -"[1] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": -"[2] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": -"[3] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": -"[4] pagy/extras/support::#pagy_next_link#test_0002_renders the next link for page 3": + class="page next disabled"> +"[1] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": +"[2] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": +"[3] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": +"[4] pagy/extras/support::#pagy_next_link#test_0001_renders the next link for page 1": diff --git a/test/pagy/frontend_test.rb b/test/pagy/frontend_test.rb index 918737bb8..c304e2be1 100644 --- a/test/pagy/frontend_test.rb +++ b/test/pagy/frontend_test.rb @@ -22,6 +22,7 @@ def i18n_load(*locales) _(app.pagy_nav(pagy)).must_rematch _(app.pagy_nav(pagy, pagy_id: 'test-nav-id', link_extra: 'link-extra')).must_rematch end + it 'renders page 3' do pagy = Pagy.new count: 103, page: 3 _(app.pagy_nav(pagy)).must_rematch diff --git a/test/pagy/frontend_test.rb.rematch b/test/pagy/frontend_test.rb.rematch index c50bd24c6..1fbf569f8 100644 --- a/test/pagy/frontend_test.rb.rematch +++ b/test/pagy/frontend_test.rb.rematch @@ -1,67 +1,75 @@ --- -"[1] pagy/frontend::#pagy_nav#test_0004_renders page 10": "[2] pagy/frontend::#pagy_nav#test_0004_renders page 10": -"[1] pagy/frontend::#pagy_nav#test_0002_renders page 3": -"[2] pagy/frontend::#pagy_nav#test_0002_renders page 3": -"[1] pagy/frontend::#pagy_nav#test_0001_renders page 1": -"[2] pagy/frontend::#pagy_nav#test_0001_renders page 1": -"[1] pagy/frontend::#pagy_nav#test_0003_renders page 6": +"[1] pagy/frontend::#pagy_nav#test_0003_renders page 6": + active">6 "[2] pagy/frontend::#pagy_nav#test_0003_renders page 6": + rel="prev" >5 6