This class does the heavy lifting of actually building the pagination
links. It is used by will_paginate helper internally.
Returns the subset of options this instance was initialized
with that represent HTML attributes for the container element of pagination
links.
# File lib/will_paginate/view_helpers/link_renderer.rb, line 36 def container_attributes @container_attributes ||= begin attributes = @options.except *(WillPaginate::ViewHelpers.pagination_options.keys - [:class]) # pagination of Post models will have the ID of "posts_pagination" if @options[:container] and @options[:id] === true attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination' end attributes end end
collection is a WillPaginate::Collection instance or any
other object that conforms to that API
options are forwarded from will_paginate view
helper
template is the reference to the template being rendered
# File lib/will_paginate/view_helpers/link_renderer.rb, line 15 def prepare(collection, options, template) super(collection, options) @template = template @container_attributes = @base_url_params = nil end
Process it! This method returns the complete HTML string which contains pagination links. Feel free to subclass LinkRenderer and change this method as you see fit.
# File lib/will_paginate/view_helpers/link_renderer.rb, line 24 def to_html html = pagination.map do |item| item.is_a?(Fixnum) ? page_number(item) : send(item) end.join(@options[:separator]) @options[:container] ? html_container(html) : html end
# File lib/will_paginate/view_helpers/link_renderer.rb, line 57 def gap '<span class="gap">…</span>' end
# File lib/will_paginate/view_helpers/link_renderer.rb, line 77 def html_container(html) tag(:div, html, container_attributes) end
# File lib/will_paginate/view_helpers/link_renderer.rb, line 65 def next_page previous_or_next_page(@collection.next_page, @options[:next_label], 'next_page') end
# File lib/will_paginate/view_helpers/link_renderer.rb, line 49 def page_number(page) unless page == current_page link(page, page, :rel => rel_value(page)) else tag(:em, page) end end
# File lib/will_paginate/view_helpers/link_renderer.rb, line 69 def previous_or_next_page(page, text, classname) if page link(text, page, :class => classname) else tag(:span, text, :class => classname + ' disabled') end end
# File lib/will_paginate/view_helpers/link_renderer.rb, line 61 def previous_page previous_or_next_page(@collection.previous_page, @options[:previous_label], 'previous_page') end
Returns URL params for page_link_or_span, taking the current
GET params and :params option into account.
# File lib/will_paginate/view_helpers/link_renderer.rb, line 83 def url(page) raise NotImplementedError end