1 # This handy simplification is adapted from SphinxSearch (thanks)
2 # and originally came from Ultrasphinx
3 # it saves us a lot of including and bodging to make will_paginate's template calls work in the Page model
4
5 module Radiant
6 module Pagination
7 class LinkRenderer < WillPaginate::LinkRenderer
8 def initialize(url_stem)
9 @url_stem = url_stem
10 end
11
12 def to_html
13 links = @options[:page_links] ? windowed_links : []
14 links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
15 links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])
16 html = links.join(@options[:separator])
17 @options[:container] ? %{<div class="pagination">#{html}</div>} : html
18 end
19
20 # this is rather crude compared to the WillPaginate link-builder,
21 # but it can get by without much context to draw on
22 def page_link(page, text, attributes = {})
23 linkclass = %{ class="#{attributes[:class]}"} if attributes[:class]
24 linkrel = %{ rel="#{attributes[:rel]}"} if attributes[:rel]
25 param_name = WillPaginate::ViewHelpers.pagination_options[:param_name]
26 %Q{<a href="#{@url_stem}?#{param_name}=#{page}"#{linkrel}#{linkclass}>#{text}</a>}
27 end
28
29 def page_span(page, text, attributes = {})
30 %{<span class="#{attributes[:class]}">#{text}</span>}
31 end
32 end
33 end
34 en