Class: TrustyCms::Pagination::LinkRenderer

Inherits:
WillPaginate::LinkRenderer
  • Object
show all
Defined in:
lib/trusty_cms/pagination/link_renderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(url_stem) ⇒ LinkRenderer

Returns a new instance of LinkRenderer.



8
9
10
# File 'lib/trusty_cms/pagination/link_renderer.rb', line 8

def initialize(url_stem)
  @url_stem = url_stem
end

Instance Method Details

this is rather crude compared to the WillPaginate link-builder, but it can get by without much context to draw on



22
23
24
25
26
27
# File 'lib/trusty_cms/pagination/link_renderer.rb', line 22

def page_link(page, text, attributes = {})
  linkclass = %{ class="#{attributes[:class]}"} if attributes[:class]
  linkrel = %{ rel="#{attributes[:rel]}"} if attributes[:rel]
  param_name = WillPaginate::ViewHelpers.pagination_options[:param_name]
  %{<a href="#{@url_stem}?#{param_name}=#{page}"#{linkrel}#{linkclass}>#{text}</a>}
end

#page_span(_page, text, attributes = {}) ⇒ Object



29
30
31
# File 'lib/trusty_cms/pagination/link_renderer.rb', line 29

def page_span(_page, text, attributes = {})
  %{<span class="#{attributes[:class]}">#{text}</span>}
end

#to_htmlObject



12
13
14
15
16
17
18
# File 'lib/trusty_cms/pagination/link_renderer.rb', line 12

def to_html
  links = @options[:page_links] ? windowed_links : []
  links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
  links.push    page_link_or_span(@collection.next_page,     'disabled next_page', @options[:next_label])
  html = links.join(@options[:separator])
  @options[:container] ? %{<div class="pagination">#{html}</div>} : html
end