Skip to content

Commit

Permalink
WIP: *_a -> *_anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Feb 6, 2025
1 parent 82ae454 commit 8da6d54
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-10.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Your app likely uses just a little fraction of the renamed things in the list be
| Method/args | `label_for(page` | `label(page: page` | Simpler name: `page` is now a keywork argument |
| Method/args | `label(page` | `label(page: page` | Same name: `page` is now a keywork argument |
| Naming | `*prev*` | `*previous*` | Unabbreviated word everywhere (option, accessor, methods, CSS class) |
| Method | `pagy_prev_a` | `pagy_previous_anchor` | Unabbreviated words |
| Method | `pagy_next_a` | `pagy_next_anchor` | Unabbreviated words |

#### Replace your `pagy.rb` config file

Expand Down
18 changes: 9 additions & 9 deletions docs/extras/pagy.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ require 'pagy/extras/pagy'
```

```erb View (helper)
<%== pagy_nav_js(@pagy, **vars) %>
<%== pagy_combo_nav_js(@pagy, **vars) %>
<%== pagy_prev_a(@pagy, **vars) %>
<%== pagy_next_a(@pagy, **vars) %>
<%== pagy_prev_link(@pagy, **vars) %>
<%== pagy_next_link(@pagy, **vars) %>
<%== pagy_nav_js(@pagy, **opts) %>
<%== pagy_combo_nav_js(@pagy, **opts) %>
<%== pagy_prev_a(@pagy, **opts) %>
<%== pagy_next_anchor(@pagy, **opts) %>
<%== pagy_prev_link(@pagy, **opts) %>
<%== pagy_next_link(@pagy, **opts) %>
```

```ruby URL helpers
Expand Down Expand Up @@ -85,7 +85,7 @@ The keyord argument used from `vars` are:
- `aria_label: pagy_t('pagy.aria_label.prev)`
- `anchor_string: nil`

==- `pagy_next_a(pagy, **vars)`
==- `pagy_next_anchor(pagy, **opts)`

Return the enabled/disabled next page anchor tag. It is the same next link string which is part of the
`pagy_nav` helper.
Expand Down Expand Up @@ -164,7 +164,7 @@ end

```erb _next_link.html.erb (partial)
<!-- Wrapped in a "pagy" class to apply the pagy CSS style -->
<span id: 'next_link' class="pagy"><%== pagy_next_a(@pagy, text: 'More...', anchor_string: 'data-remote="true"') %><span>
<span id: 'next_link' class="pagy"><%== pagy_next_anchor(@pagy, text: 'More...', anchor_string: 'data-remote="true"') %><span>
```

```erb incremental.js.erb (javascript template)
Expand All @@ -190,7 +190,7 @@ of changes:
**1**. Hide the link in `_next_link.html.erb` by adding a style attribute:

```erb _next_link.html.erb (partial)
<span style="display: none;"><%== pagy_next_a(@pagy, text: 'More...') %></span>
<span style="display: none;"><%== pagy_next_anchor(@pagy, text: 'More...') %></span>
```

**2**. Add a javascript that will click the link when the listing-bottom appears in the viewport on load/resize/scroll. It will
Expand Down
4 changes: 2 additions & 2 deletions gem/apps/demo.ru
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ class PagyDemo < Sinatra::Base
<%= html = pagy_limit_selector_js(@pagy, id: 'limit-selector-js') %>
<%= highlight(html) %>
<h2>pagy_previous_a / pagy_next_a</h2>
<%= html = '<nav class="pagy" id="prev-next" aria-label="Pagy prev-next">' << pagy_previous_a(@pagy) << pagy_next_a(@pagy) << '</nav>' %>
<h2>pagy_previous_anchor / pagy_next_anchor</h2>
<%= html = '<nav class="pagy" id="prev-next" aria-label="Pagy prev-next">' << pagy_previous_anchor(@pagy) << pagy_next_anchor(@pagy) << '</nav>' %>
<%= highlight(html) %>
<h2>pagy_previous_link / pagy_next_link <span class="notes">Link not rendered<span></h2>
Expand Down
2 changes: 1 addition & 1 deletion gem/apps/keyset.ru
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class PagyKeyset < Sinatra::Base
</div>
<p>
<nav class="pagy" id="next" aria-label="Pagy next">
<%= pagy_next_a(@pagy, text: 'Next page &gt;') %>
<%= pagy_next_anchor(@pagy, text: 'Next page &gt;') %>
</nav>
</div>
ERB
Expand Down
2 changes: 1 addition & 1 deletion gem/apps/keyset_sequel.ru
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class PagyKeysetSequel < Sinatra::Base
</div>
<p>
<nav class="pagy" id="next" aria-label="Pagy next">
<%= pagy_next_a(@pagy, text: 'Next page &gt;') %>
<%= pagy_next_anchor(@pagy, text: 'Next page &gt;') %>
</nav>
</div>
ERB
Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/frontend/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module Loader
pagy_next_link: 'pagy/helpers',
pagy_info: 'pagy/info',
pagy_limit_selector_js: 'pagy/limit_selector',
pagy_previous_a: 'pagy/previous_next',
pagy_next_a: 'pagy/previous_next' }.freeze
pagy_previous_anchor: 'pagy/previous_next',
pagy_next_anchor: 'pagy/previous_next' }.freeze

define_method :pagy_load_frontend do |*args, **kwargs|
method_sym = __callee__
Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/frontend/pagy/combo_nav_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def pagy_combo_nav_js(pagy, **)
pages = pagy.pages
input = %(<input name="page" type="number" min="1" max="#{pages}" value="#{pagy.page}" aria-current="page" ) +
%(style="text-align: center; width: #{pages.to_s.length + 1}rem; padding: 0;">#{A_TAG})
html = %(#{pagy_previous_a(pagy, create_anchor)}<label>#{
html = %(#{pagy_previous_anchor(pagy, create_anchor)}<label>#{
pagy_translate('pagy.combo_nav_js', page_input: input, pages:)}</label>#{
pagy_next_a(pagy, create_anchor)})
pagy_next_anchor(pagy, create_anchor)})
ComboNavJs.tag(self, pagy, html, 'pagy combo-nav-js', **)
end
end
Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/frontend/pagy/nav.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Pagy
# Return the html with the series of links to the pages
def pagy_nav(pagy, **)
create_anchor = pagy_create_anchor_lambda(pagy, **)
html = pagy_previous_a(pagy, create_anchor)
html = pagy_previous_anchor(pagy, create_anchor)
pagy.series(**).each do |item|
# series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
html << case item
Expand All @@ -22,7 +22,7 @@ def pagy_nav(pagy, **)
raise InternalError, "expected item types in series to be Integer, String or :gap; got #{item.inspect}"
end
end
html << pagy_next_a(pagy, create_anchor)
html << pagy_next_anchor(pagy, create_anchor)
Nav.tag(self, pagy, html, 'pagy nav', **)
end
end
Expand Down
4 changes: 2 additions & 2 deletions gem/lib/pagy/frontend/pagy/nav_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Pagy
# Return a nav with a data-pagy attribute used by the pagy.js file
def pagy_nav_js(pagy, **)
create_anchor = pagy_create_anchor_lambda(pagy, **)
tokens = { before: pagy_previous_a(pagy, create_anchor),
tokens = { before: pagy_previous_anchor(pagy, create_anchor),
anchor: create_anchor.(PAGE_TOKEN, LABEL_TOKEN),
current: %(<a class="current" role="link" aria-current="page" aria-disabled="true">#{LABEL_TOKEN}</a>),
gap: %(<a class="gap" role="link" aria-disabled="true">#{pagy_translate('pagy.gap')}</a>),
after: pagy_next_a(pagy, create_anchor) }
after: pagy_next_anchor(pagy, create_anchor) }
NavJs.tag(self, pagy, tokens, 'pagy nav-js', **)
end
end
Expand Down
8 changes: 4 additions & 4 deletions gem/lib/pagy/frontend/pagy/previous_next.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class Pagy
Frontend.module_eval do
# Return the enabled/disabled previous page anchor tag
def pagy_previous_a(pagy, create_anchor = nil, text: pagy_translate('pagy.previous'),
aria_label: pagy_translate('pagy.aria_label.previous'), **)
def pagy_previous_anchor(pagy, create_anchor = nil, text: pagy_translate('pagy.previous'),
aria_label: pagy_translate('pagy.aria_label.previous'), **)
if pagy.previous
(create_anchor || pagy_create_anchor_lambda(pagy, **)).(pagy.previous, text, aria_label:)
else
Expand All @@ -13,8 +13,8 @@ def pagy_previous_a(pagy, create_anchor = nil, text: pagy_translate('pagy.previo
end

# Return the enabled/disabled next page anchor tag
def pagy_next_a(pagy, create_anchor = nil, text: pagy_translate('pagy.next'),
aria_label: pagy_translate('pagy.aria_label.next'), **)
def pagy_next_anchor(pagy, create_anchor = nil, text: pagy_translate('pagy.next'),
aria_label: pagy_translate('pagy.aria_label.next'), **)
if pagy.next
(create_anchor || pagy_create_anchor_lambda(pagy, **)).(pagy.next, text, aria_label:)
else
Expand Down
8 changes: 4 additions & 4 deletions test/pagy/frontend/pagy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def self.tests_for(method, page_finalize, **others)
describe '#pagy_next_link' do
tests_for(:pagy_next_link, [[1, 21], [3, 21], [6, 21], [50, 20]], absolute: true)
end
describe '#pagy_previous_a' do
tests_for(:pagy_previous_a, [[1, 0], [3, 21], [6, 21], [50, 20]],
describe '#pagy_previous_anchor' do
tests_for(:pagy_previous_anchor, [[1, 0], [3, 21], [6, 21], [50, 20]],
text: 'PREV', aria_label: 'My previous page')
end
describe '#pagy_next_a' do
tests_for(:pagy_next_a, [[1, 0], [3, 21], [6, 21], [50, 20]],
describe '#pagy_next_anchor' do
tests_for(:pagy_next_anchor, [[1, 0], [3, 21], [6, 21], [50, 20]],
text: 'NEXT', aria_label: 'My next page')
end
end
46 changes: 38 additions & 8 deletions test/pagy/frontend/pagy_test.rb.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
pagy___pagy_next_a_test_0004_renders_the_pagy_next_a_for_page_50:
pagy___pagy_next_anchor_test_0004_renders_the_pagy_next_anchor_for_page_50:
:r1: <a role="link" aria-disabled="true" aria-label="Next">&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label="Next">&gt;</a>
:r3: <a role="link" aria-disabled="true" aria-label="My next page">NEXT</a>
:r4: <a role="link" aria-disabled="true" aria-label="My next page">NEXT</a>
pagy___pagy_next_a_test_0003_renders_the_pagy_next_a_for_page_6:
pagy___pagy_next_anchor_test_0003_renders_the_pagy_next_anchor_for_page_6:
:r1: <a href="/foo?page=7" aria-label="Next">&gt;</a>
:r2: <a href="/foo?page=7+7" aria-label="Next">&gt;</a>
:r3: <a href="/foo?page=7" aria-label="My next page">NEXT</a>
:r4: <a href="/foo?page=7+7" aria-label="My next page">NEXT</a>
pagy___pagy_next_a_test_0001_renders_the_pagy_next_a_for_page_1:
pagy___pagy_next_anchor_test_0001_renders_the_pagy_next_anchor_for_page_1:
:r1: <a href="/foo?page=2" aria-label="Next">&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label="Next">&gt;</a>
:r3: <a href="/foo?page=2" aria-label="My next page">NEXT</a>
:r4: <a role="link" aria-disabled="true" aria-label="My next page">NEXT</a>
pagy___pagy_next_a_test_0002_renders_the_pagy_next_a_for_page_3:
pagy___pagy_next_anchor_test_0002_renders_the_pagy_next_anchor_for_page_3:
:r1: <a href="/foo?page=4" aria-label="Next">&gt;</a>
:r2: <a href="/foo?page=4+4" aria-label="Next">&gt;</a>
:r3: <a href="/foo?page=4" aria-label="My next page">NEXT</a>
Expand Down Expand Up @@ -191,22 +191,52 @@ pagy___pagy_next_link_test_0002_renders_the_pagy_next_link_for_page_3:
:r2: <link href="/foo?page=4+4"/>
:r3: <link href="http://example.com:3000/foo?page=4"/>
:r4: <link href="http://example.com:3000/foo?page=4+4"/>
pagy___pagy_previous_a_test_0004_renders_the_pagy_previous_a_for_page_50:
pagy___pagy_previous_anchor_test_0004_renders_the_pagy_previous_anchor_for_page_50:
:r1: <a href="/foo?page=49" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=49+50" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=49" aria-label="My previous page">PREV</a>
:r4: <a href="/foo?page=49+50" aria-label="My previous page">PREV</a>
pagy___pagy_previous_a_test_0003_renders_the_pagy_previous_a_for_page_6:
pagy___pagy_previous_anchor_test_0003_renders_the_pagy_previous_anchor_for_page_6:
:r1: <a href="/foo?page=5" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=5+7" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=5" aria-label="My previous page">PREV</a>
:r4: <a href="/foo?page=5+7" aria-label="My previous page">PREV</a>
pagy___pagy_previous_a_test_0001_renders_the_pagy_previous_a_for_page_1:
pagy___pagy_previous_anchor_test_0001_renders_the_pagy_previous_anchor_for_page_1:
:r1: <a role="link" aria-disabled="true" aria-label="Previous">&lt;</a>
:r2: <a role="link" aria-disabled="true" aria-label="Previous">&lt;</a>
:r3: <a role="link" aria-disabled="true" aria-label="My previous page">PREV</a>
:r4: <a role="link" aria-disabled="true" aria-label="My previous page">PREV</a>
pagy___pagy_previous_a_test_0002_renders_the_pagy_previous_a_for_page_3:
pagy___pagy_previous_anchor_test_0002_renders_the_pagy_previous_anchor_for_page_3:
:r1: <a href="/foo?page=2" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=2+4" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=2" aria-label="My previous page">PREV</a>
:r4: <a href="/foo?page=2+4" aria-label="My previous page">PREV</a>
pagy___pagy_next_anchornchor_test_0003_renders_the_pagy_next_anchornchor_for_page_6:
:r1: <a href="/foo?page=7" aria-label="Next">&gt;</a>
:r2: <a href="/foo?page=7+7" aria-label="Next">&gt;</a>
:r3: <a href="/foo?page=7" aria-label="My next page">NEXT</a>
:r4: <a href="/foo?page=7+7" aria-label="My next page">NEXT</a>
pagy___pagy_next_anchornchor_test_0002_renders_the_pagy_next_anchornchor_for_page_3:
:r1: <a href="/foo?page=4" aria-label="Next">&gt;</a>
:r2: <a href="/foo?page=4+4" aria-label="Next">&gt;</a>
:r3: <a href="/foo?page=4" aria-label="My next page">NEXT</a>
:r4: <a href="/foo?page=4+4" aria-label="My next page">NEXT</a>
pagy___pagy_next_anchornchor_test_0004_renders_the_pagy_next_anchornchor_for_page_50:
:r1: <a role="link" aria-disabled="true" aria-label="Next">&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label="Next">&gt;</a>
:r3: <a role="link" aria-disabled="true" aria-label="My next page">NEXT</a>
:r4: <a role="link" aria-disabled="true" aria-label="My next page">NEXT</a>
pagy___pagy_next_anchornchor_test_0001_renders_the_pagy_next_anchornchor_for_page_1:
:r1: <a href="/foo?page=2" aria-label="Next">&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label="Next">&gt;</a>
:r3: <a href="/foo?page=2" aria-label="My next page">NEXT</a>
:r4: <a role="link" aria-disabled="true" aria-label="My next page">NEXT</a>
pagy___pagy_previous_anchornchor_test_0003_renders_the_pagy_previous_anchornchor_for_page_6:
:r1: <a href="/foo?page=5" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=5+7" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=5" aria-label="My previous page">PREV</a>
:r4: <a href="/foo?page=5+7" aria-label="My previous page">PREV</a>
pagy___pagy_previous_anchornchor_test_0002_renders_the_pagy_previous_anchornchor_for_page_3:
:r1: <a href="/foo?page=2" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=2+4" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=2" aria-label="My previous page">PREV</a>
Expand Down

0 comments on commit 8da6d54

Please sign in to comment.