Class: BootstrapPager::Helpers::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap_pager/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/bootstrap_pager/ 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/bootstrap_pager/_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/bootstrap_pager-x.x.x/app/views/bootstrap_pager/_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
22
# File 'lib/bootstrap_pager/helpers/tags.rb', line 16

def initialize(template, options = {}) #:nodoc:
  @template, @options = template, options.dup
  @param_name = @options.delete(:param_name)
  @engine_namespace = @options.delete(:engine_namespace)
  @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


28
29
30
31
32
# File 'lib/bootstrap_pager/helpers/tags.rb', line 28

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

#to_s(locals = {}) ⇒ Object

:nodoc:


24
25
26
# File 'lib/bootstrap_pager/helpers/tags.rb', line 24

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