Class: Kaminari::Helpers::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/kaminari/helpers/tags.rb

Overview

A tag stands for an HTML tag inside the paginator. Basically, a tag has its own partial template file, so every tag can be rendered into String using its partial template.

The template file should be placed in your app/views/kaminari/ directory with underscored class name (besides the “Tag” class. Tag is an abstract class, so _tag parital is not needed).

e.g.)  PrevLink  ->  app/views/kaminari/_prev_link.html.erb

When no matching template were found in your app, the engine’s pre installed template will be used.

e.g.)  Paginator  ->  $GEM_HOME/kaminari-x.x.x/app/views/kaminari/_paginator.html.erb

Direct Known Subclasses

FirstPage, Gap, LastPage, NextPage, Page, Paginator, PrevPage

Instance Method Summary collapse

Constructor Details

#initialize(template, options = {}) ⇒ Tag

:nodoc:



16
17
18
19
20
21
# File 'lib/kaminari/helpers/tags.rb', line 16

def initialize(template, options = {}) #:nodoc:
  @template, @options = template, options.dup
  @param_name = @options.delete(:param_name)
  @theme = @options[:theme] ? "#{@options.delete(:theme)}/" : ''
  @params = @options[:params] ? template.params.merge(@options.delete :params) : template.params
end

Instance Method Details

#page_url_for(page) ⇒ Object



27
28
29
# File 'lib/kaminari/helpers/tags.rb', line 27

def page_url_for(page)
  @template.url_for @params.merge(@param_name => (page <= 1 ? nil : page))
end

#to_s(locals = {}) ⇒ Object

:nodoc:



23
24
25
# File 'lib/kaminari/helpers/tags.rb', line 23

def to_s(locals = {}) #:nodoc:
  @template.render :partial => "kaminari/#{@theme}#{self.class.name.demodulize.underscore}", :locals => @options.merge(locals)
end