Class: Yuzu::PostProcessors::PaginationPostProcessor

Inherits:
PostProcessor show all
Defined in:
lib/yuzu/postprocessors/pagination.rb

Instance Attribute Summary

Attributes inherited from PostProcessor

#name

Instance Method Summary collapse

Methods inherited from PostProcessor

#match, postprocessors, #regex, registry

Constructor Details

#initializePaginationPostProcessor

Returns a new instance of PaginationPostProcessor.



6
7
8
9
# File 'lib/yuzu/postprocessors/pagination.rb', line 6

def initialize
  @name = :pagination
  @directive = "PAGINATION"
end

Instance Method Details

#value(website_file) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/yuzu/postprocessors/pagination.rb', line 11

def value(website_file)
  root_file = website_file.paginated? ? website_file.original_file : website_file
  pagination_catalog = root_file.stash[:catalog]
  return "" if pagination_catalog.nil?
  num_pages = pagination_catalog.num_pages

  pages = [root_file] + root_file.stash[:paginated_siblings]

  links = pages.collect do |page|
    page_num = pages.find_index(page) + 1
    is_current_page = page == website_file
    if is_current_page
      Html::Span.new << page_num.to_s
    else
      Html::Link.new(:href => page.link_url) << page_num.to_s
    end
  end

  return Html::Div.new(:class => "pagination-links") << links.join(" ")
end