Class: WillPaginate::LinkRenderer

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#gap_markerObject

The gap in page links is represented by:




292
293
294
295
296
297
# File 'lib/will_paginate/view_helpers.rb', line 292

def gap_marker
  @gap_marker ||= begin
    gap_text = @template.will_paginate_translate(:page_gap) { '…' }
    %(<span class="gap">#{gap_text}</span>)
  end
end

Instance Method Details

#html_attributesObject

Returns the subset of options this instance was initialized with that represent HTML attributes for the container element of pagination links.



277
278
279
280
281
282
283
284
285
# File 'lib/will_paginate/view_helpers.rb', line 277

def html_attributes
  return @html_attributes if @html_attributes
  @html_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
    @html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
  end
  @html_attributes
end

#prepare(collection, options, template) ⇒ Object

  • 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



252
253
254
255
256
257
258
259
# File 'lib/will_paginate/view_helpers.rb', line 252

def prepare(collection, options, template)
  @collection = collection
  @options    = options
  @template   = template

  # reset values in case we're re-using this instance
  @total_pages = @param_name = @url_string = nil
end

#to_htmlObject

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.



264
265
266
267
268
269
270
271
272
273
# File 'lib/will_paginate/view_helpers.rb', line 264

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 = html.html_safe if html.respond_to? :html_safe
  @options[:container] ? @template.(:div, html, html_attributes) : html
end