Created
May 23, 2012 01:00
-
-
Save Epictetus/2772626 to your computer and use it in GitHub Desktop.
Link renderer and helper method to be used with will_paginate to render links to work with Twitter Bootstrap
This file contains 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 ApplicationHelper | |
def paginate *params | |
params[1] = {} if params[1].nil? | |
params[1][:renderer] = BootstrapPaginationHelper::LinkRenderer | |
will_paginate *params | |
end | |
end |
This file contains 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 BootstrapPaginationHelper | |
class LinkRenderer < WillPaginate::ActionView::LinkRenderer | |
protected | |
def page_number(page) | |
unless page == current_page | |
link(page, page, :rel => rel_value(page)) | |
else | |
link(page, "#", :class => 'active') | |
end | |
end | |
def gap | |
text = @template.will_paginate_translate(:page_gap) { '…' } | |
%(<li class="disabled"><a>#{text}</a></li>) | |
end | |
def next_page | |
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1 | |
previous_or_next_page(num, @options[:next_label], 'next') | |
end | |
def previous_or_next_page(page, text, classname) | |
if page | |
link(text, page, :class => classname) | |
else | |
link(text, "#", :class => classname + ' disabled') | |
end | |
end | |
def html_container(html) | |
tag(:div, tag(:ul, html), container_attributes) | |
end | |
private | |
def link(text, target, attributes = {}) | |
if target.is_a? Fixnum | |
attributes[:rel] = rel_value(target) | |
target = url(target) | |
end | |
unless target == "#" | |
attributes[:href] = target | |
end | |
classname = attributes[:class] | |
attributes.delete(:classname) | |
tag(:li, tag(:a, text, attributes), :class => classname) | |
end | |
end | |
end |
This file contains 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
- news.each do |n| | |
= n.author | |
= n.date | |
= n.abstract | |
= paginate news, :param_name => :news_page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment