Skip to content

Commit

Permalink
rename :prev_label to :previous_label for consistency. old name still…
Browse files Browse the repository at this point in the history
… functions but is deprecated
  • Loading branch information
mislav committed Aug 13, 2008
1 parent 7a3b81b commit 9a93720
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
32 changes: 18 additions & 14 deletions lib/will_paginate/view_helpers.rb
Expand Up @@ -14,24 +14,24 @@ module WillPaginate
# WillPaginate::ViewHelpers.pagination_options hash. You can write to this hash to
# override default options on the global level:
#
# WillPaginate::ViewHelpers.pagination_options[:prev_label] = 'Previous page'
# WillPaginate::ViewHelpers.pagination_options[:previous_label] = 'Previous page'
#
# By putting this into your environment.rb you can easily translate link texts to previous
# and next pages, as well as override some other defaults to your liking.
module ViewHelpers
# default options that can be overridden on the global level
@@pagination_options = {
:class => 'pagination',
:prev_label => '« Previous',
:next_label => 'Next »',
:inner_window => 4, # links around the current page
:outer_window => 1, # links around beginning and end
:separator => ' ', # single space is friendly to spiders and non-graphic browsers
:param_name => :page,
:params => nil,
:renderer => 'WillPaginate::LinkRenderer',
:page_links => true,
:container => true
:class => 'pagination',
:previous_label => '« Previous',
:next_label => 'Next »',
:inner_window => 4, # links around the current page
:outer_window => 1, # links around beginning and end
:separator => ' ', # single space is friendly to spiders and non-graphic browsers
:param_name => :page,
:params => nil,
:renderer => 'WillPaginate::LinkRenderer',
:page_links => true,
:container => true
}
mattr_reader :pagination_options

Expand All @@ -41,7 +41,7 @@ module ViewHelpers
#
# ==== Options
# * <tt>:class</tt> -- CSS class name for the generated DIV (default: "pagination")
# * <tt>:prev_label</tt> -- default: "« Previous"
# * <tt>:previous_label</tt> -- default: "« Previous"
# * <tt>:next_label</tt> -- default: "Next »"
# * <tt>:inner_window</tt> -- how many links are shown around the current page (default: 4)
# * <tt>:outer_window</tt> -- how many links are around the first and the last page (default: 1)
Expand Down Expand Up @@ -92,6 +92,10 @@ def will_paginate(collection = nil, options = {})
return nil unless WillPaginate::ViewHelpers.total_pages_for_collection(collection) > 1

options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
if options[:prev_label]
WillPaginate::Deprecation::warn(":prev_label view parameter is now :previous_label; the old name has been deprecated.")
options[:previous_label] = options.delete(:prev_label)
end

# get the renderer instance
renderer = case options[:renderer]
Expand Down Expand Up @@ -214,7 +218,7 @@ def prepare(collection, options, template)
def to_html
links = @options[:page_links] ? windowed_links : []
# previous/next buttons
links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:prev_label])
links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])

html = links.join(@options[:separator])
Expand Down
10 changes: 9 additions & 1 deletion test/view_test.rb
Expand Up @@ -36,7 +36,7 @@ def test_no_pagination_when_page_count_is_one

def test_will_paginate_with_options
paginate({ :page => 2 },
:class => 'will_paginate', :prev_label => 'Prev', :next_label => 'Next') do
:class => 'will_paginate', :previous_label => 'Prev', :next_label => 'Next') do
assert_select 'a[href]', 4 do |elements|
validate_page_numbers [1,1,3,3], elements
# test rel attribute values:
Expand Down Expand Up @@ -80,6 +80,14 @@ def test_prev_next_links_have_classnames
assert_select 'a.next_page[href]:last-child'
end
end

def test_prev_label_deprecated
assert_deprecated ':previous_label' do
paginate({ :page => 2 }, :prev_label => 'Deprecated') do
assert_select 'a[href]:first-child', 'Deprecated'
end
end
end

def test_full_output
paginate
Expand Down

0 comments on commit 9a93720

Please sign in to comment.