Skip to content

Commit

Permalink
Add rel="prev|next|start" to page links. Closes #196 [swdyh]
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Mar 4, 2008
1 parent 4598470 commit 8a906a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/will_paginate/view_helpers.rb
Expand Up @@ -183,7 +183,7 @@ def visible_page_numbers
def page_link_or_span(page, span_class = 'current', text = nil)
text ||= page.to_s
if page and page != current_page
@template.link_to text, url_options(page)
@template.link_to text, url_options(page), :rel => rel_value(page)
else
@template.content_tag :span, text, :class => span_class
end
Expand All @@ -199,6 +199,14 @@ def url_options(page)

private

def rel_value(page)
case page
when @collection.previous_page; 'prev' + (page == 1 ? ' start' : '')
when @collection.next_page; 'next'
when 1; 'start'
end
end

def current_page
@collection.current_page
end
Expand Down
12 changes: 10 additions & 2 deletions test/pagination_test.rb
Expand Up @@ -75,8 +75,16 @@ def test_will_paginate_with_options
assert_select 'div.will_paginate', 1, 'no main DIV' do
assert_select 'a[href]', 4 do |elements|
validate_page_numbers [1,1,3,3], elements
assert_select elements.first, 'a', "Prev"
assert_select elements.last, 'a', "Next"
# test rel attribute values:
assert_select elements[1], 'a', '1' do |link|
assert_equal 'prev start', link.first['rel']
end
assert_select elements.first, 'a', "Prev" do |link|
assert_equal 'prev start', link.first['rel']
end
assert_select elements.last, 'a', "Next" do |link|
assert_equal 'next', link.first['rel']
end
end
assert_select 'span.current', entries.current_page.to_s
end
Expand Down

0 comments on commit 8a906a2

Please sign in to comment.