Module: Folio::WillPaginate::ViewHelpers

Defined in:
lib/folio/will_paginate/view_helpers.rb,
lib/folio/will_paginate/view_helpers/link_renderer.rb,
lib/folio/will_paginate/view_helpers/link_renderer_base.rb

Defined Under Namespace

Modules: LinkRenderer, LinkRendererBase

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



47
48
49
50
51
52
# 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

Instance Method Details

#page_entries_info_with_folio(collection, options = {}) ⇒ Object



40
41
42
43
44
45
# 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 = {}) ⇒ Object

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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