Skip to content

Instantly share code, notes, and snippets.

@chebyte
Created March 18, 2009 14:13
Show Gist options
  • Save chebyte/81142 to your computer and use it in GitHub Desktop.
Save chebyte/81142 to your computer and use it in GitHub Desktop.
class VbsLinkRenderer < WillPaginate::LinkRenderer
def to_html
links = @options[:page_links] ? windowed_links : []
links.unshift(page_link_or_span(@collection.previous_page, 'prev', @options[:previous_label]))
links.push(page_link_or_span(@collection.next_page, 'next', @options[:next_label]))
html = links.join(@options[:separator])
@options[:container] ? @template.content_tag(:ul, html, html_attributes) : html
end
protected
def windowed_links
visible_page_numbers.map { |n| page_link_or_span(n, (n == current_page ? 'current' : nil)) }
end
def page_link_or_span(page, span_class, text = nil)
text ||= page.to_s
if page && page != current_page
page_link(page, text, :class => span_class)
elsif current_page == 1 && span_class == 'prev'
page_disable(text, "disable", :class => span_class)
elsif current_page == total_pages && span_class == 'next'
page_disable(text, "disable", :class => span_class)
else
page_link(page, text, :class => span_class)
end
end
def page_link(page, text, attributes = {})
@template.content_tag(:li, @template.link_to(text, url_for(page)), attributes)
end
def page_span(page, text, attributes = {})
@template.content_tag(:li, text, attributes)
end
def page_disable(text, span_class, attributes = {})
@template.content_tag(:li, @template.link_to(text, "#", :class => span_class), attributes)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment