Class: WillPaginate::LinkRenderer
- Inherits:
-
Object
- Object
- WillPaginate::LinkRenderer
- Defined in:
- lib/will_paginate/view_helpers.rb
Overview
This class does the heavy lifting of actually building the pagination links. It is used by the will_paginate helper internally.
Direct Known Subclasses
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
optionsthis 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
collectionis a WillPaginate::Collection instance or any other object that conforms to that API *optionsare forwarded fromwill_paginateview helper *templateis 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.
220 221 222 |
# File 'lib/will_paginate/view_helpers.rb', line 220 def initialize @gap_marker = '<span class="gap">…</span>' end |
Instance Attribute Details
#gap_marker ⇒ Object
The gap in page links is represented by:
<span class="gap">…</span>
218 219 220 |
# File 'lib/will_paginate/view_helpers.rb', line 218 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.
253 254 255 256 257 258 259 260 261 |
# File 'lib/will_paginate/view_helpers.rb', line 253 def html_attributes return @html_attributes if @html_attributes @html_attributes = .except *(WillPaginate::ViewHelpers..keys - [:class]) # pagination of Post models will have the ID of "posts_pagination" if [:container] and [:id] === true @html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination' end @html_attributes end |
#prepare(collection, options, template) ⇒ Object
collectionis a WillPaginate::Collection instance or any other object that conforms to that APIoptionsare forwarded fromwill_paginateview helpertemplateis the reference to the template being rendered
228 229 230 231 232 233 234 235 |
# File 'lib/will_paginate/view_helpers.rb', line 228 def prepare(collection, , template) @collection = collection = @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.
240 241 242 243 244 245 246 247 248 249 |
# File 'lib/will_paginate/view_helpers.rb', line 240 def to_html links = [:page_links] ? windowed_links : [] # previous/next buttons links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', [:previous_label]) links.push page_link_or_span(@collection.next_page, 'disabled next_page', [:next_label]) html = links.join([:separator]) container_tag = [:semantic] ? [:semantic_container] : :div [:container] ? @template.content_tag(container_tag, html, html_attributes) : html end |