Skip to content

Commit

Permalink
Use proper attributes for "previous" links (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
marckohlbrugge authored Jun 6, 2020
1 parent c433649 commit 28913d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
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

0 comments on commit 28913d6

Please sign in to comment.