aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-15 20:27:38 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-15 20:27:38 +0000
commit45804e2c86228efcfb7d635525f0d1635a1b25c1 (patch)
treef286bddb5813d6d49ee251428058cda2c0f62539 /actionpack/lib/action_view
parent1708a863a5ed9ea37010de099fbe68193e67f4ba (diff)
downloadrails-45804e2c86228efcfb7d635525f0d1635a1b25c1.tar.gz
rails-45804e2c86228efcfb7d635525f0d1635a1b25c1.tar.bz2
rails-45804e2c86228efcfb7d635525f0d1635a1b25c1.zip
More pagination speed #1334 [Stefan Kaes]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1839 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/pagination_helper.rb42
1 files changed, 24 insertions, 18 deletions
diff --git a/actionpack/lib/action_view/helpers/pagination_helper.rb b/actionpack/lib/action_view/helpers/pagination_helper.rb
index 6f6380ec70..51510599fb 100644
--- a/actionpack/lib/action_view/helpers/pagination_helper.rb
+++ b/actionpack/lib/action_view/helpers/pagination_helper.rb
@@ -18,7 +18,8 @@ module ActionView
}
end
- # Creates a basic HTML link bar for the given +paginator+.
+ # Creates a basic HTML link bar for the given +paginator+.
+ # +html_options+ are passed to +link_to+.
#
# +options+ are:
# <tt>:name</tt>:: the routing name for this paginator
@@ -33,20 +34,25 @@ module ActionView
# +false+)
# <tt>:params</tt>:: any additional routing parameters
# for page URLs
- def pagination_links(paginator, options={})
- options.merge!(DEFAULT_OPTIONS) {|key, old, new| old}
+ def pagination_links(paginator, options={}, html_options={})
+ name = options[:name] || DEFAULT_OPTIONS[:name]
+ params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
- pagination_links_each(paginator, options[:window_size], options[:always_show_anchors], options[:link_to_current_page]) do |n|
- link_to(n.to_s, { options[:name] => n }.update(options[:params]))
+ pagination_links_each(paginator, options) do |n|
+ params[name] = n
+ link_to(n.to_s, params, html_options)
end
end
# Iterate through the pages of a given +paginator+, invoking a
# block for each page number that needs to be rendered as a link.
+ def pagination_links_each(paginator, options)
+ options = DEFAULT_OPTIONS.merge(options)
+ link_to_current_page = options[:link_to_current_page]
+ always_show_anchors = options[:always_show_anchors]
- def pagination_links_each(paginator, window_size=2, always_show_anchors=true, link_to_current_page=false)
current_page = paginator.current_page
- window_pages = current_page.window(window_size).pages
+ window_pages = current_page.window(options[:window_size]).pages
return if window_pages.length <= 1 unless link_to_current_page
first, last = paginator.first, paginator.last
@@ -55,26 +61,26 @@ module ActionView
if always_show_anchors and not (wp_first = window_pages[0]).first?
html << yield(first.number)
html << ' ... ' if wp_first.number - first.number > 1
- html << ' '
- end
+ html << ' '
+ end
- window_pages.each do |page|
+ window_pages.each do |page|
if current_page == page && !link_to_current_page
- html << page.number.to_s
- else
+ html << page.number.to_s
+ else
html << yield(page.number)
- end
- html << ' '
end
-
+ html << ' '
+ end
+
if always_show_anchors and not (wp_last = window_pages[-1]).last?
html << ' ... ' if last.number - wp_last.number > 1
html << yield(last.number)
+ end
+
+ html
end
- html
- end
-
end # PaginationHelper
end # Helpers
end # ActionView