module Folio::WillPaginate::ViewHelpers

Public Class Methods

included(klass) click to toggle source
# File lib/folio/will_paginate/view_helpers.rb, line 47
def self.included(klass)
  [:will_paginate, :page_entries_info].each do |method|
    klass.send(:alias_method, :"#{method}_without_folio", method)
    klass.send(:alias_method, method, :"#{method}_with_folio")
  end
end

Public Instance Methods

page_entries_info_with_folio(collection, options = {}) click to toggle source
# File lib/folio/will_paginate/view_helpers.rb, line 40
def page_entries_info_with_folio(collection, options = {})
  # skip outputting anything unless the collection has ordinal pages (to
  # be able to get an offset) *and* a known total count.
  return unless collection.total_entries && collection.ordinal_pages
  page_entries_info_without_folio(collection, options)
end
will_paginate_with_folio(collection, options = {}) click to toggle source

just copied from ::WillPaginate::ViewHelpers except line 14 (changed from “unless value > 1” to “if value == 1” to be friendly to unknown total_pages)

# File lib/folio/will_paginate/view_helpers.rb, line 12
def will_paginate_with_folio(collection, options = {})
  # early exit if there is nothing to render
  return nil if collection.total_pages == 1

  options = ::WillPaginate::ViewHelpers.pagination_options.merge(options)

  options[:previous_label] ||= will_paginate_translate(:previous_label) { '← Previous' }
  options[:next_label]     ||= will_paginate_translate(:next_label) { 'Next →' }

  # get the renderer instance
  renderer = case options[:renderer]
  when nil
    raise ArgumentError, ":renderer not specified"
  when String
    klass = if options[:renderer].respond_to? :constantize then options[:renderer].constantize
      else Object.const_get(options[:renderer]) # poor man's constantize
      end
    klass.new
  when Class then options[:renderer].new
  else options[:renderer]
  end
  # render HTML for pagination
  renderer.prepare collection, options, self
  output = renderer.to_html
  output = output.html_safe if output.respond_to?(:html_safe)
  output
end