Class: WillPaginate::ViewHelpers::LinkRenderer

### Home Classes Methods

### In Files

- lib/will_paginate/view_helpers/link_renderer.rb

### Parent

LinkRendererBase

### Methods

- #container_attributes
- #gap
- #html_container
- #next_page
- #page_number
- #prepare
- #previous_or_next_page
- #previous_page
- #to_html
- #url

### Class/Module Index

Quicksearch

- WillPaginate
- WillPaginate::ActionView
- WillPaginate::ActionView::LinkRenderer
- WillPaginate::ActiveRecord
- WillPaginate::ActiveRecord::BaseMethods
- WillPaginate::ActiveRecord::Pagination
- WillPaginate::ActiveRecord::RelationMethods
- WillPaginate::Collection
- WillPaginate::CollectionMethods
- WillPaginate::DataMapper
- WillPaginate::DataMapper::CollectionMethods
- WillPaginate::DataMapper::Pagination
- WillPaginate::Deprecation
- WillPaginate::Deprecation::Hash
- WillPaginate::I18n
- WillPaginate::InvalidPage
- WillPaginate::Merb
- WillPaginate::Merb::LinkRenderer
- WillPaginate::PageNumber
- WillPaginate::PerPage
- WillPaginate::PerPage::Inheritance
- WillPaginate::Railtie
- WillPaginate::Railtie::ControllerRescuePatch
- WillPaginate::Railtie::ShowExceptionsPatch
- WillPaginate::SequelMethods
- WillPaginate::Sinatra
- WillPaginate::Sinatra::Helpers
- WillPaginate::Sinatra::LinkRenderer
- WillPaginate::ViewHelpers
- WillPaginate::ViewHelpers::LinkRenderer
- WillPaginate::ViewHelpers::LinkRendererBase
- Array
- Object

No matching classes.

# WillPaginate::ViewHelpers::LinkRenderer

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

### Public Instance Methods

container_attributes() click to toggle source

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

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 37
    def container_attributes
      @container_attributes ||= @options.except(*(ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
    end

prepare(collection, options, template) click to toggle source

- `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

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 16
    def prepare(collection, options, template)
      super(collection, options)
      @template = template
      @container_attributes = @base_url_params = nil
    end

to_html() click to toggle source

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.

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 25
    def to_html
      html = pagination.map do |item|
        item.is_a?(Fixnum) ?
          page_number(item) :
          send(item)
      end.join(@options[:link_separator])

      @options[:container] ? html_container(html) : html
    end

### Protected Instance Methods

gap() click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 51
    def gap
      text = @template.will_paginate_translate(:page_gap) { '&hellip;' }
      %(<span class="gap">#{text}</span>)
    end

html_container(html) click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 74
    def html_container(html)
      tag(:div, html, container_attributes)
    end

next_page() click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 61
    def next_page
      num = @collection.current_page < total_pages && @collection.current_page + 1
      previous_or_next_page(num, @options[:next_label], 'next_page')
    end

page_number(page) click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 43
    def page_number(page)
      unless page == current_page
        link(page, page, :rel => rel_value(page))
      else
        tag(:em, page, :class => 'current')
      end
    end

previous_or_next_page(page, text, classname) click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 66
    def previous_or_next_page(page, text, classname)
      if page
        link(text, page, :class => classname)
      else
        tag(:span, text, :class => classname + ' disabled')
      end
    end

previous_page() click to toggle source

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 56
    def previous_page
      num = @collection.current_page > 1 && @collection.current_page - 1
      previous_or_next_page(num, @options[:previous_label], 'previous_page')
    end

url(page) click to toggle source

Returns URL params for `page_link_or_span`, taking the current GET params and `:params` option into account.

    # File lib/will_paginate/view_helpers/link_renderer.rb, line 80
    def url(page)
      raise NotImplementedError
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.