Class: Leaf::ViewHelpers::LinkRenderer

Inherits:
LinkRendererBase show all
Defined in:
lib/leaf/view_helpers/link_renderer.rb

Overview

This class does the heavy lifting of actually building the pagination links. It is used by leaf helper internally.

Direct Known Subclasses

ListRenderer

Instance Method Summary collapse

Methods inherited from LinkRendererBase

#pagination

Instance Method Details

#container_attributesObject

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



35
36
37
38
39
40
41
42
43
44
# File 'lib/leaf/view_helpers/link_renderer.rb', line 35

def container_attributes
  @container_attributes ||= begin
    attributes = @options.except *(Leaf::ViewHelpers.pagination_options.keys - [:class])
    # pagination of Post models will have the ID of "posts_pagination"
    if @options[:container] and @options[:id] === true
      attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
    end
    attributes
  end
end

#prepare(collection, options, template) ⇒ Object

  • collection is a Leaf::Collection instance or any other object that conforms to that API

  • options are forwarded from leaf view helper

  • template is the reference to the template being rendered



14
15
16
17
18
# File 'lib/leaf/view_helpers/link_renderer.rb', line 14

def prepare(collection, options, template)
  super(collection, options)
  @template = template
  @container_attributes = @base_url_params = 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.



23
24
25
26
27
28
29
30
31
# File 'lib/leaf/view_helpers/link_renderer.rb', line 23

def to_html
  html = pagination.map do |item|
    item.is_a?(Fixnum) ?
      page_number(item) :
      send(item)
  end.join(@options[:separator])
  
  @options[:container] ? html_container(html) : html
end