Created
September 30, 2010 13:36
-
-
Save aermolaev/604578 to your computer and use it in GitHub Desktop.
WillPaginate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WillPaginate | |
module ViewHelpers | |
# Настройки WillPaginate | |
pagination_options[:class] = 'g-pager' | |
pagination_options[:previous_label] = '← предыдущая' | |
pagination_options[:next_label] = 'следующая →' | |
# Поддержка TableView | |
def will_paginate_with_table_view(collection = nil, options = {}) | |
collection = collection.data if TableView === collection | |
will_paginate_without_table_view(collection, options) | |
end | |
alias_method_chain :will_paginate, :table_view | |
end | |
class LinkRenderer | |
def to_html | |
links = @options[:page_links] ? windowed_links : [] | |
html = [ | |
@template.content_tag(:b, 'Страницы'), | |
' ', | |
page_link_or_span(@collection.previous_page, %w(disabled prev_page), @options[:previous_label], :prev_page), | |
page_link_or_span(@collection.next_page, %w(disabled next_page), @options[:next_label], :next_page), | |
@template.content_tag(:div, links.join(@options[:separator]), :class => 'numbers') | |
].join | |
html = html.html_safe if html.respond_to? :html_safe | |
@template.content_tag(:div, html, html_attributes) | |
end | |
def page_link_or_span(page, span_class, text = nil, id = nil) | |
text ||= page.to_s | |
classnames = Array[*span_class] | |
if page && page != current_page | |
page_url = url_for(page) | |
if @options[:remote] | |
@template.link_to_remote text, { | |
:url => page_url, | |
:html => { :rel => rel_value(page), :class => classnames[1], :id => id } | |
} | |
else | |
@template.link_to(text, page_url, :rel => rel_value(page), :class => classnames[1], :id => id) | |
end | |
else | |
@template.content_tag(:span, text, :class => classnames.join(' ')) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment