Class: Yuzu::PostProcessors::PaginationPostProcessor
- Inherits:
-
PostProcessor
- Object
- Register
- PostProcessor
- Yuzu::PostProcessors::PaginationPostProcessor
- Defined in:
- lib/yuzu/postprocessors/pagination.rb
Instance Attribute Summary
Attributes inherited from PostProcessor
Instance Method Summary collapse
-
#initialize ⇒ PaginationPostProcessor
constructor
A new instance of PaginationPostProcessor.
- #value(website_file) ⇒ Object
Methods inherited from PostProcessor
#match, postprocessors, #regex, registry
Constructor Details
#initialize ⇒ PaginationPostProcessor
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 |