Class: Pagination::LinkRenderer
- Inherits:
-
Object
- Object
- Pagination::LinkRenderer
- Defined in:
- lib/pagination/view_helpers.rb
Overview
This class does the heavy lifting of actually building the pagination links. It is used by the paginate
helper internally.
Instance Attribute Summary collapse
-
#gap_marker ⇒ Object
The gap in page links is represented by:.
Instance Method Summary collapse
-
#html_attributes ⇒ Object
Returns the subset of
options
this instance was initialized with that represent HTML attributes for the container element of pagination links. -
#initialize ⇒ LinkRenderer
constructor
A new instance of LinkRenderer.
-
#prepare(collection, options, template) ⇒ Object
-
collection
is a Pagination::Collection instance or any other object that conforms to that API *options
are forwarded frompaginate
view helper *template
is the reference to the template being rendered.
-
-
#to_html ⇒ Object
Process it! This method returns the complete HTML string which contains pagination links.
Constructor Details
#initialize ⇒ LinkRenderer
Returns a new instance of LinkRenderer.
129 130 131 |
# File 'lib/pagination/view_helpers.rb', line 129 def initialize @gap_marker = '<span class="gap">…</span>' end |
Instance Attribute Details
#gap_marker ⇒ Object
The gap in page links is represented by:
…
127 128 129 |
# File 'lib/pagination/view_helpers.rb', line 127 def gap_marker @gap_marker end |
Instance Method Details
#html_attributes ⇒ Object
Returns the subset of options
this instance was initialized with that represent HTML attributes for the container element of pagination links.
161 162 163 164 165 166 167 168 169 |
# File 'lib/pagination/view_helpers.rb', line 161 def html_attributes return @html_attributes if @html_attributes @html_attributes = @options.except *(Pagination::ViewHelpers..keys - [:class]) # pagination of Post models will have the ID of "posts_pagination" if @options[:container] and @options[:id] === true @html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination' end @html_attributes end |
#prepare(collection, options, template) ⇒ Object
-
collection
is a Pagination::Collection instance or any other object that conforms to that API -
options
are forwarded frompaginate
view helper -
template
is the reference to the template being rendered
137 138 139 140 141 142 143 144 |
# File 'lib/pagination/view_helpers.rb', line 137 def prepare(collection, , template) @collection = collection @options = @template = template # reset values in case we're re-using this instance @total_pages = @param_name = @url_string = nil end |
#to_html ⇒ Object
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.
149 150 151 152 153 154 155 156 157 |
# File 'lib/pagination/view_helpers.rb', line 149 def to_html links = @options[:page_links] ? windowed_links : [] # previous/next buttons 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]).html_safe @options[:container] ? @template.content_tag(:div, html, html_attributes) : html end |