Module: Folio::WillPaginate::ViewHelpers::LinkRenderer

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



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

def self.included(klass)
  [:prepare, :windowed_links, :total_pages, :rel_value].each do |method|
    klass.send(:alias_method, :"#{method}_without_folio", method)
    klass.send(:alias_method, method, :"#{method}_with_folio")
  end
end

Instance Method Details

#prepare_with_folio(collection, options, template) ⇒ Object



8
9
10
11
12
13
# File 'lib/folio/will_paginate/view_helpers/link_renderer.rb', line 8

def prepare_with_folio(collection, options, template)
  # only include page_links if we're in a collection with ordinal
  # pages; otherwise stick to just prev/next.
  options = options.merge(page_links: false) unless collection.ordinal_pages?
  prepare_without_folio(collection, options, template)
end

#rel_value_with_folio(page) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/folio/will_paginate/view_helpers/link_renderer.rb', line 32

def rel_value_with_folio(page)
  # don't check against mathed out values, just check the values on the
  # collection
  rels = []
  rels << 'prev' if page == @collection.previous_page
  rels << 'next' if page == @collection.next_page
  rels << 'start' if page == @collection.first_page
  rels.empty? ? nil : rels.join(' ')
end

#total_pages_with_folioObject



24
25
26
27
28
29
30
# File 'lib/folio/will_paginate/view_helpers/link_renderer.rb', line 24

def total_pages_with_folio
  # the collection may not have a known last page. if so, there must be
  # a next page; count that as the last known page. it's ok to use
  # these page identifiers as a page count because (after fixing
  # LinkRenderer) it's only called when ordinal_pages is true.
  @collection.last_page || @collection.next_page
end


15
16
17
18
19
20
21
22
# File 'lib/folio/will_paginate/view_helpers/link_renderer.rb', line 15

def windowed_links_with_folio
  links = windowed_links_without_folio
  unless @collection.last_page
    # the last page is not known, so add a trailing gap
    links << gap_marker
  end
  links
end