Skip to content

Commit

Permalink
Renaming of support helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Mar 29, 2024
1 parent 2f35312 commit cfb86e6
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 93 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ None
- The `classes:` and `aria_label:` keyword arguments have been added to the returned lambda
- The `nav_aria_label_attr` method has been renamed as `nav_aria_label`
- The internal `prev_aria_label_attr` and `next_aria_label_attr` methods have been removed
-
- The `gap` in the nav bars is a disabled anchor element (`a` tag without a `href` attribute`)
- The `pagy_prev_html` and `pagy_next_html` have been renamed as `pagy_prev_a` and `pagy_next_a`
- The `pagy_prev_link_tag` and `pagy_next_link_tag` have been renamed as `pagy_prev_link` and `pagy_next_link`
- The `*combo_nav_js` and `pagy_items_selector_js` helpers use a more efficient mechanism
- The `src/pagy.ts` and relative built javascript files have been adapted to the above changes
- The stylesheets are a lot simpler as a consequence of the changes above
Expand Down
16 changes: 8 additions & 8 deletions lib/pagy/extras/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ def pagy_next_url(pagy, absolute: false)
pagy_url_for(pagy, pagy.next, absolute:) if pagy.next
end

# Return the HTML string for the enabled/disabled previous page link
def pagy_prev_html(pagy, text: pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))
# Return the enabled/disabled previous page anchor tag
def pagy_prev_a(pagy, text: pagy_t('pagy.prev'), aria_label: pagy_t('pagy.aria_label.prev'))
a = pagy_anchor(pagy)
prev_html(pagy, a, text:, aria_label:)
end

# Return the HTML string for the enabled/disabled next page link
def pagy_next_html(pagy, text: pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.prev'))
# Return the enabled/disabled next page anchor tag
def pagy_next_a(pagy, text: pagy_t('pagy.next'), aria_label: pagy_t('pagy.aria_label.prev'))
a = pagy_anchor(pagy)
next_html(pagy, a, text:, aria_label:)
end

# Conditionally return the HTML link tag string for the previous page
def pagy_prev_link_tag(pagy, absolute: false)
# Conditionally return the previous page link tag
def pagy_prev_link(pagy, absolute: false)
%(<link href="#{pagy_url_for(pagy, pagy.prev, absolute:)}"/>) if pagy.prev
end

# Conditionally return the HTML link tag string for the next page
def pagy_next_link_tag(pagy, absolute: false)
# Conditionally return the next page link tag
def pagy_next_link(pagy, absolute: false)
%(<link href="#{pagy_url_for(pagy, pagy.next, absolute:)}"/>) if pagy.next
end
end
Expand Down
14 changes: 7 additions & 7 deletions test/pagy/extras/support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def self.tests_for(method, page_finalize, **others)
describe '#pagy_next_url' do
tests_for(:pagy_next_url, [[1, 21], [3, 21], [6, 21], [50, 20]], absolute: true)
end
describe '#pagy_prev_link_tag' do
tests_for(:pagy_prev_link_tag, [[1, 21], [3, 21], [6, 21], [50, 20]], absolute: true)
describe '#pagy_prev_link' do
tests_for(:pagy_prev_link, [[1, 21], [3, 21], [6, 21], [50, 20]], absolute: true)
end
describe '#pagy_next_link_tag' do
tests_for(:pagy_next_link_tag, [[1, 21], [3, 21], [6, 21], [50, 20]], absolute: true)
describe '#pagy_next_link' do
tests_for(:pagy_next_link, [[1, 21], [3, 21], [6, 21], [50, 20]], absolute: true)
end
describe '#pagy_prev_html' do
tests_for(:pagy_prev_html, [[1, 0], [3, 21], [6, 21], [50, 20]],
describe '#pagy_prev_a' do
tests_for(:pagy_prev_a, [[1, 0], [3, 21], [6, 21], [50, 20]],
text: 'PREV', aria_label: 'My prev page')
end
describe '#pagy_next_html' do
tests_for(:pagy_next_html, [[1, 0], [3, 21], [6, 21], [50, 20]],
tests_for(:pagy_next_a, [[1, 0], [3, 21], [6, 21], [50, 20]],
text: 'NEXT', aria_label: 'My next page')
end
end
154 changes: 77 additions & 77 deletions test/pagy/extras/support_test.rb.rematch
Original file line number Diff line number Diff line change
@@ -1,74 +1,29 @@
---
pagy/extras/support::#pagy_prev_html#test_0001_renders the pagy_prev_html 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 prev page">PREV</a>
:r4: <a role="link" aria-disabled="true" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_html#test_0004_renders the pagy_prev_html for page 50:
:r1: <a href="/foo?page=49" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=49" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=49" aria-label="My prev page">PREV</a>
:r4: <a href="/foo?page=49" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_html#test_0002_renders the pagy_prev_html for page 3:
:r1: <a href="/foo?page=2" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=2" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=2" aria-label="My prev page">PREV</a>
:r4: <a href="/foo?page=2" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_html#test_0003_renders the pagy_prev_html for page 6:
:r1: <a href="/foo?page=5" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=5" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=5" aria-label="My prev page">PREV</a>
:r4: <a href="/foo?page=5" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_url#test_0001_renders the pagy_prev_url for page 1:
pagy/extras/support::#pagy_prev_link#test_0001_renders the pagy_prev_link for page 1:
:r1:
:r2:
:r3:
:r4:
pagy/extras/support::#pagy_prev_url#test_0004_renders the pagy_prev_url for page 50:
:r1: "/foo?page=49"
:r2: "/foo?page=49"
:r3: http://example.com:3000/foo?page=49
:r4: http://example.com:3000/foo?page=49
pagy/extras/support::#pagy_prev_url#test_0002_renders the pagy_prev_url for page 3:
:r1: "/foo?page=2"
:r2: "/foo?page=2"
:r3: http://example.com:3000/foo?page=2
:r4: http://example.com:3000/foo?page=2
pagy/extras/support::#pagy_prev_url#test_0003_renders the pagy_prev_url for page 6:
:r1: "/foo?page=5"
:r2: "/foo?page=5"
:r3: http://example.com:3000/foo?page=5
:r4: http://example.com:3000/foo?page=5
pagy/extras/support::#pagy_next_link_tag#test_0001_renders the pagy_next_link_tag for page 1:
pagy/extras/support::#pagy_prev_link#test_0002_renders the pagy_prev_link for page 3:
:r1: <link href="/foo?page=2"/>
:r2: <link href="/foo?page=2"/>
:r3: <link href="http://example.com:3000/foo?page=2"/>
:r4: <link href="http://example.com:3000/foo?page=2"/>
pagy/extras/support::#pagy_next_link_tag#test_0004_renders the pagy_next_link_tag for page 50:
:r1:
:r2:
:r3:
:r4:
pagy/extras/support::#pagy_next_link_tag#test_0002_renders the pagy_next_link_tag for page 3:
:r1: <link href="/foo?page=4"/>
:r2: <link href="/foo?page=4"/>
:r3: <link href="http://example.com:3000/foo?page=4"/>
:r4: <link href="http://example.com:3000/foo?page=4"/>
pagy/extras/support::#pagy_next_link_tag#test_0003_renders the pagy_next_link_tag for page 6:
:r1: <link href="/foo?page=7"/>
:r2: <link href="/foo?page=7"/>
:r3: <link href="http://example.com:3000/foo?page=7"/>
:r4: <link href="http://example.com:3000/foo?page=7"/>
pagy/extras/support::#pagy_prev_link#test_0003_renders the pagy_prev_link for page 6:
:r1: <link href="/foo?page=5"/>
:r2: <link href="/foo?page=5"/>
:r3: <link href="http://example.com:3000/foo?page=5"/>
:r4: <link href="http://example.com:3000/foo?page=5"/>
pagy/extras/support::#pagy_prev_link#test_0004_renders the pagy_prev_link for page 50:
:r1: <link href="/foo?page=49"/>
:r2: <link href="/foo?page=49"/>
:r3: <link href="http://example.com:3000/foo?page=49"/>
:r4: <link href="http://example.com:3000/foo?page=49"/>
pagy/extras/support::#pagy_next_url#test_0001_renders the pagy_next_url for page 1:
:r1: "/foo?page=2"
:r2: "/foo?page=2"
:r3: http://example.com:3000/foo?page=2
:r4: http://example.com:3000/foo?page=2
pagy/extras/support::#pagy_next_url#test_0004_renders the pagy_next_url for page 50:
:r1:
:r2:
:r3:
:r4:
pagy/extras/support::#pagy_next_url#test_0002_renders the pagy_next_url for page 3:
:r1: "/foo?page=4"
:r2: "/foo?page=4"
Expand All @@ -79,43 +34,88 @@ pagy/extras/support::#pagy_next_url#test_0003_renders the pagy_next_url for page
:r2: "/foo?page=7"
:r3: http://example.com:3000/foo?page=7
:r4: http://example.com:3000/foo?page=7
pagy/extras/support::#pagy_prev_link_tag#test_0001_renders the pagy_prev_link_tag for page 1:
pagy/extras/support::#pagy_next_url#test_0004_renders the pagy_next_url for page 50:
:r1:
:r2:
:r3:
:r4:
pagy/extras/support::#pagy_prev_link_tag#test_0004_renders the pagy_prev_link_tag for page 50:
:r1: <link href="/foo?page=49"/>
:r2: <link href="/foo?page=49"/>
:r3: <link href="http://example.com:3000/foo?page=49"/>
:r4: <link href="http://example.com:3000/foo?page=49"/>
pagy/extras/support::#pagy_prev_link_tag#test_0002_renders the pagy_prev_link_tag for page 3:
pagy/extras/support::#pagy_prev_url#test_0001_renders the pagy_prev_url for page 1:
:r1:
:r2:
:r3:
:r4:
pagy/extras/support::#pagy_prev_url#test_0002_renders the pagy_prev_url for page 3:
:r1: "/foo?page=2"
:r2: "/foo?page=2"
:r3: http://example.com:3000/foo?page=2
:r4: http://example.com:3000/foo?page=2
pagy/extras/support::#pagy_prev_url#test_0003_renders the pagy_prev_url for page 6:
:r1: "/foo?page=5"
:r2: "/foo?page=5"
:r3: http://example.com:3000/foo?page=5
:r4: http://example.com:3000/foo?page=5
pagy/extras/support::#pagy_prev_url#test_0004_renders the pagy_prev_url for page 50:
:r1: "/foo?page=49"
:r2: "/foo?page=49"
:r3: http://example.com:3000/foo?page=49
:r4: http://example.com:3000/foo?page=49
pagy/extras/support::#pagy_prev_a#test_0001_renders the pagy_prev_a 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 prev page">PREV</a>
:r4: <a role="link" aria-disabled="true" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_a#test_0002_renders the pagy_prev_a for page 3:
:r1: <a href="/foo?page=2" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=2" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=2" aria-label="My prev page">PREV</a>
:r4: <a href="/foo?page=2" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_a#test_0003_renders the pagy_prev_a for page 6:
:r1: <a href="/foo?page=5" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=5" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=5" aria-label="My prev page">PREV</a>
:r4: <a href="/foo?page=5" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_prev_a#test_0004_renders the pagy_prev_a for page 50:
:r1: <a href="/foo?page=49" aria-label="Previous">&lt;</a>
:r2: <a href="/foo?page=49" aria-label="Previous">&lt;</a>
:r3: <a href="/foo?page=49" aria-label="My prev page">PREV</a>
:r4: <a href="/foo?page=49" aria-label="My prev page">PREV</a>
pagy/extras/support::#pagy_next_link#test_0001_renders the pagy_next_link for page 1:
:r1: <link href="/foo?page=2"/>
:r2: <link href="/foo?page=2"/>
:r3: <link href="http://example.com:3000/foo?page=2"/>
:r4: <link href="http://example.com:3000/foo?page=2"/>
pagy/extras/support::#pagy_prev_link_tag#test_0003_renders the pagy_prev_link_tag for page 6:
:r1: <link href="/foo?page=5"/>
:r2: <link href="/foo?page=5"/>
:r3: <link href="http://example.com:3000/foo?page=5"/>
:r4: <link href="http://example.com:3000/foo?page=5"/>
pagy/extras/support::#pagy_next_html#test_0001_renders the pagy_next_html for page 1:
pagy/extras/support::#pagy_next_link#test_0002_renders the pagy_next_link for page 3:
:r1: <link href="/foo?page=4"/>
:r2: <link href="/foo?page=4"/>
:r3: <link href="http://example.com:3000/foo?page=4"/>
:r4: <link href="http://example.com:3000/foo?page=4"/>
pagy/extras/support::#pagy_next_link#test_0003_renders the pagy_next_link for page 6:
:r1: <link href="/foo?page=7"/>
:r2: <link href="/foo?page=7"/>
:r3: <link href="http://example.com:3000/foo?page=7"/>
:r4: <link href="http://example.com:3000/foo?page=7"/>
pagy/extras/support::#pagy_next_link#test_0004_renders the pagy_next_link for page 50:
:r1:
:r2:
:r3:
:r4:
pagy/extras/support::#pagy_next_html#test_0001_renders the pagy_next_a for page 1:
:r1: <a href="/foo?page=2" aria-label="Previous">&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label=Previous>&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/extras/support::#pagy_next_html#test_0004_renders the pagy_next_html for page 50:
:r1: <a role="link" aria-disabled="true" aria-label=Previous>&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label=Previous>&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/extras/support::#pagy_next_html#test_0002_renders the pagy_next_html for page 3:
pagy/extras/support::#pagy_next_html#test_0002_renders the pagy_next_a for page 3:
:r1: <a href="/foo?page=4" aria-label="Previous">&gt;</a>
:r2: <a href="/foo?page=4" aria-label="Previous">&gt;</a>
:r3: <a href="/foo?page=4" aria-label="My next page">NEXT</a>
:r4: <a href="/foo?page=4" aria-label="My next page">NEXT</a>
pagy/extras/support::#pagy_next_html#test_0003_renders the pagy_next_html for page 6:
pagy/extras/support::#pagy_next_html#test_0003_renders the pagy_next_a for page 6:
:r1: <a href="/foo?page=7" aria-label="Previous">&gt;</a>
:r2: <a href="/foo?page=7" aria-label="Previous">&gt;</a>
:r3: <a href="/foo?page=7" aria-label="My next page">NEXT</a>
:r4: <a href="/foo?page=7" aria-label="My next page">NEXT</a>
pagy/extras/support::#pagy_next_html#test_0004_renders the pagy_next_a for page 50:
:r1: <a role="link" aria-disabled="true" aria-label=Previous>&gt;</a>
:r2: <a role="link" aria-disabled="true" aria-label=Previous>&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>

0 comments on commit cfb86e6

Please sign in to comment.