class UiKitLinkRenderer

Constants

GET_PARAMS_BLACKLIST

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_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 31
def container_attributes
  @container_attributes ||= @options.except(*(WillPaginate::ViewHelpers.pagination_options.keys + [:renderer] - [:class]))
end
default_url_params() click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 35
def default_url_params
  {}
end
gap() click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 51
def gap
  text = @template.will_paginate_translate(:page_gap) { '…' }
  tag(:li) do
    tag(:span, text)
  end
end
html_container(html) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 84
def html_container(html)
  tag(:ul, html, container_attributes)
end
next_page() click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 63
def next_page
  num = @collection.current_page < total_pages && @collection.current_page + 1
  previous_or_next_page(num, 'uk-pagination-next')
end
page_number(page) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 39
def page_number(page)
  if page == current_page
    tag(:li, nil, class: 'uk-active') do
      tag(:span, page)
    end
  else
    tag(:li) do
      tag(:a, page, href: url(page), rel: rel_value(page))
    end
  end
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

Calls superclass method
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 9
def prepare(collection, options, template)
  super(collection, options)
  @options[:class] = 'uk-pagination'
  @template = template
  @container_attributes = @base_url_params = nil
end
previous_or_next_page(page, attribute) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 68
def previous_or_next_page(page, attribute)
  if page
    tag(:li, nil) do
      tag(:a, nil, href: url(page), rel: rel_value(page)) do 
        tag(:span, '', attribute => '')
      end
    end
  else
    tag(:li, nil, class: 'uk-disabled') do
      tag(:a, nil, href: '#') do 
        tag(:span, '', attribute => '')
      end
    end
  end
end
previous_page() click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 58
def previous_page
  num = @collection.current_page > 1 && @collection.current_page - 1
  previous_or_next_page(num, 'uk-pagination-previous')
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_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 19
def to_html
  html = pagination.map do |item|
    item.is_a?(Integer) ?
      page_number(item) :
      send(item)
  end.join(@options[:link_separator])
  
  @options[:container] ? html_container(html) : html
end

Protected Instance Methods

add_current_page_param(url_params, page) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 115
def add_current_page_param(url_params, page)
  unless param_name.index(/[^\w-]/)
    url_params[param_name.to_sym] = page
  else
    page_param = parse_query_parameters("#{param_name}=#{page}")
    symbolized_update(url_params, page_param)
  end
end
merge_get_params(url_params) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 103
def merge_get_params(url_params)
  if @template.respond_to? :request and @template.request and @template.request.get?
    symbolized_update(url_params, @template.params, GET_PARAMS_BLACKLIST)
  end
  url_params
end
merge_optional_params(url_params) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 110
def merge_optional_params(url_params)
  symbolized_update(url_params, @options[:params]) if @options[:params]
  url_params
end
url(page) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 90
def url(page)
  @base_url_params ||= begin
    url_params = merge_get_params(default_url_params)
    url_params[:only_path] = true
    merge_optional_params(url_params)
  end

  url_params = @base_url_params.dup
  add_current_page_param(url_params, page)

  @template.url_for(url_params)
end

Private Instance Methods

param_name() click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 130
def param_name
  @options[:param_name].to_s
end
parse_query_parameters(params) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 126
def parse_query_parameters(params)
  Rack::Utils.parse_nested_query(params)
end
rel_value(page) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 156
def rel_value(page)
  case page
  when @collection.current_page - 1; 'prev'
  when @collection.current_page + 1; 'next'
  end
end
symbolized_update(target, other, blacklist = nil) click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 163
def symbolized_update(target, other, blacklist = nil)
  other.each_pair do |key, value|
    key = key.to_sym
    existing = target[key]
    next if blacklist && blacklist.include?(key)

    if value.respond_to?(:each_pair) and (existing.is_a?(Hash) or existing.nil?)
      symbolized_update(existing || (target[key] = {}), value)
    else
      target[key] = value
    end
  end
end
tag(name, value = '', attributes = {}) { || ... } click to toggle source
# File lib/will_paginate_ui_kit/view_helpers/ui_kit_link_renderer.rb, line 143
def tag(name, value = '', attributes = {}, &block)
  if block_given?
    value = yield
  end
  string_attributes = attributes.inject('') do |attrs, pair|
    unless pair.last.nil?
      attrs << %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
    end
    attrs
  end
  "<#{name}#{string_attributes}>#{value}</#{name}>"
end