Module: Folio::WillPaginate::ViewHelpers

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

Defined Under Namespace

Modules: LinkRenderer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



49
50
51
52
53
54
# File 'lib/folio/will_paginate/view_helpers.rb', line 49

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



42
43
44
45
46
47
# File 'lib/folio/will_paginate/view_helpers.rb', line 42

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 = nil, options = {}) ⇒ Object

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



11
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
39
40
# File 'lib/folio/will_paginate/view_helpers.rb', line 11

def will_paginate_with_folio(collection = nil, options = {})
  options, collection = collection, nil if collection.is_a? Hash
  unless collection or !controller
    collection_name = "@#{controller.controller_name}"
    collection = instance_variable_get(collection_name)
    raise ArgumentError, "The #{collection_name} variable appears to be empty. Did you " +
      "forget to pass the collection object for will_paginate?" unless collection
  end
  # early exit if there is nothing to render
  return nil if ::WillPaginate::ViewHelpers.total_pages_for_collection(collection) == 1

  options = options.symbolize_keys.reverse_merge ::WillPaginate::ViewHelpers.pagination_options
  if options[:prev_label]
    WillPaginate::Deprecation::warn(":prev_label view parameter is now :previous_label; the old name has been deprecated", caller)
    options[:previous_label] = options.delete(:prev_label)
  end

  # get the renderer instance
  renderer = case options[:renderer]
  when String
    options[:renderer].to_s.constantize.new
  when Class
    options[:renderer].new
  else
    options[:renderer]
  end
  # render HTML for pagination
  renderer.prepare collection, options, self
  renderer.to_html
end