Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper attributes for "previous" links #244

Merged
merged 2 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pagy/extras/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def pagy_next_url(pagy)
end

def pagy_prev_link(pagy, text = pagy_t('pagy.nav.prev'), link_extra = '')
pagy.prev ? %(<span class="page prev"><a href="#{pagy_prev_url(pagy)}" rel="next" aria-label="next" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
pagy.prev ? %(<span class="page prev"><a href="#{pagy_prev_url(pagy)}" rel="prev" aria-label="previous" #{pagy.vars[:link_extra]} #{link_extra}>#{text}</a></span>)
: %(<span class="page prev disabled">#{text}</span>)
end

Expand Down
13 changes: 6 additions & 7 deletions test/pagy/extras/support_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@
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)
_(view.pagy_prev_link(pagy)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=2\" rel=\"next\" aria-label=\"next\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy_countless)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=2\" rel=\"next\" aria-label=\"next\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=2\" rel=\"prev\" aria-label=\"previous\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy_countless)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=2\" rel=\"prev\" aria-label=\"previous\" >&lsaquo;&nbsp;Prev</a></span>"
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)
_(view.pagy_prev_link(pagy)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=5\" rel=\"next\" aria-label=\"next\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy_countless)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=5\" rel=\"next\" aria-label=\"next\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=5\" rel=\"prev\" aria-label=\"previous\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy_countless)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=5\" rel=\"prev\" aria-label=\"previous\" >&lsaquo;&nbsp;Prev</a></span>"
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)
_(view.pagy_prev_link(pagy)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=49\" rel=\"next\" aria-label=\"next\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy_countless)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=49\" rel=\"next\" aria-label=\"next\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=49\" rel=\"prev\" aria-label=\"previous\" >&lsaquo;&nbsp;Prev</a></span>"
_(view.pagy_prev_link(pagy_countless)).must_equal "<span class=\"page prev\"><a href=\"/foo?page=49\" rel=\"prev\" aria-label=\"previous\" >&lsaquo;&nbsp;Prev</a></span>"
end

end
Expand Down Expand Up @@ -140,4 +140,3 @@
end

end