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 partial is not needed).

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

When no matching templates 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, params: {}, param_name: nil, theme: nil, views_prefix: nil, **options) ⇒ Tag

:nodoc:



20
21
22
23
24
25
26
27
28
29
# File 'lib/kaminari/helpers/tags.rb', line 20

def initialize(template, params: {}, param_name: nil, theme: nil, views_prefix: nil, **options) #:nodoc:
  @template, @theme, @views_prefix, @options = template, theme, views_prefix, options
  @param_name = param_name || Kaminari.config.param_name
  @params = template.params
  # @params in Rails 5 no longer inherits from Hash
  @params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
  @params = @params.with_indifferent_access
  @params.except!(*PARAM_KEY_EXCEPT_LIST)
  @params.merge! params
end

Instance Method Details

#page_url_for(page) ⇒ Object



36
37
38
39
40
# File 'lib/kaminari/helpers/tags.rb', line 36

def page_url_for(page)
  params = params_for(page)
  params[:only_path] = true
  @template.url_for params
end

#to_s(locals = {}) ⇒ Object

:nodoc:



31
32
33
34
# File 'lib/kaminari/helpers/tags.rb', line 31

def to_s(locals = {}) #:nodoc:
  formats = (@template.respond_to?(:formats) ? @template.formats : Array(@template.params[:format])) + [:html]
  @template.render partial: partial_path, locals: @options.merge(locals), formats: formats
end