Class: Jekyll::Itafroma::ArchivePager
- Inherits:
-
Object
- Object
- Jekyll::Itafroma::ArchivePager
- Defined in:
- lib/jekyll/itafroma/archive_pager.rb
Overview
Represents the pager used for ArchivePages.
Instance Attribute Summary collapse
-
#next_page ⇒ Object
readonly
Returns the value of attribute next_page.
-
#next_page_path ⇒ Object
readonly
Returns the value of attribute next_page_path.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#previous_page ⇒ Object
readonly
Returns the value of attribute previous_page.
-
#previous_page_path ⇒ Object
readonly
Returns the value of attribute previous_page_path.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
-
#total_posts ⇒ Object
readonly
Returns the value of attribute total_posts.
Class Method Summary collapse
-
.paginate_path(posts, num_page) ⇒ Object
Static: Return the pagination path of the archive page.
Instance Method Summary collapse
-
#initialize(site, page, all_pages, num_pages = nil) ⇒ ArchivePager
constructor
Initialize a new Archive Pager.
-
#to_liquid ⇒ Object
Convert this Pager’s data to a Hash suitable for use by Liquid.
Constructor Details
#initialize(site, page, all_pages, num_pages = nil) ⇒ ArchivePager
Initialize a new Archive Pager.
site - the Jekyll::Site object page - The Integer page number. all_pages - The Array of the archive’s Posts. num_pages - The Integer number of pages or nil if you’d like the number
of pages calculated.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 42 def initialize(site, page, all_pages, num_pages = nil) @page = page @per_page = 1 @total_pages = num_pages || all_pages.size if @page > @total_pages fail "Jekyll Archive Generator: page number can't be greater than total pages: #{@page} > #{@total_pages}" end @pages = all_pages @previous_page = @page != 1 ? @page - 1 : nil @previous_page_path = ArchivePager.paginate_path(all_pages, @previous_page) @next_page = @page != @total_pages ? @page + 1 : nil @next_page_path = ArchivePager.paginate_path(all_pages, @next_page) end |
Instance Attribute Details
#next_page ⇒ Object (readonly)
Returns the value of attribute next_page.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def next_page @next_page end |
#next_page_path ⇒ Object (readonly)
Returns the value of attribute next_page_path.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def next_page_path @next_page_path end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def page @page end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def pages @pages end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def per_page @per_page end |
#previous_page ⇒ Object (readonly)
Returns the value of attribute previous_page.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def previous_page @previous_page end |
#previous_page_path ⇒ Object (readonly)
Returns the value of attribute previous_page_path.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def previous_page_path @previous_page_path end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def total_pages @total_pages end |
#total_posts ⇒ Object (readonly)
Returns the value of attribute total_posts.
18 19 20 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18 def total_posts @total_posts end |
Class Method Details
.paginate_path(posts, num_page) ⇒ Object
Static: Return the pagination path of the archive page
posts - The Array of the archive’s Posts. num_page - the pagination page number
Returns the pagination path as a string
28 29 30 31 32 33 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 28 def self.paginate_path(posts, num_page) return posts.first.url if num_page.nil? return nil if num_page < 1 return nil if num_page > posts.size posts[num_page - 1].url end |
Instance Method Details
#to_liquid ⇒ Object
Convert this Pager’s data to a Hash suitable for use by Liquid.
Returns the Hash representation of this Pager.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jekyll/itafroma/archive_pager.rb', line 61 def to_liquid { 'page' => page, 'per_page' => per_page, 'pages' => pages, 'total_pages' => total_pages, 'previous_page' => previous_page, 'previous_page_path' => previous_page_path, 'next_page' => next_page, 'next_page_path' => next_page_path } end |