Class: Jekyll::PaginateV2::Generator::Paginator
- Inherits:
-
Object
- Object
- Jekyll::PaginateV2::Generator::Paginator
- Defined in:
- lib/jekyll-paginate-v2-redux/generator/paginator.rb
Overview
Handles the preparation of all the posts based on the current page index
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.
-
#page_path ⇒ Object
readonly
Returns the value of attribute page_path.
-
#page_trail ⇒ Object
Returns the value of attribute page_trail.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#posts ⇒ Object
readonly
Returns the value of attribute posts.
-
#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.
Instance Method Summary collapse
-
#initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages) ⇒ Paginator
constructor
Initialize a new Paginator.
-
#to_liquid ⇒ Object
Convert this Paginator’s data to a Hash suitable for use by Liquid.
Constructor Details
#initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages) ⇒ Paginator
Initialize a new Paginator.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 21 def initialize(config_per_page, first_index_page_url, paginated_page_url, posts, cur_page_nr, num_pages) @page = cur_page_nr @per_page = config_per_page.to_i @total_pages = num_pages if @page > @total_pages raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}" end init = (@page - 1) * @per_page offset = (init + @per_page - 1) >= posts.size ? posts.size : (init + @per_page - 1) @total_posts = posts.size @posts = posts[init..offset] @page_path = @page == 1 ? first_index_page_url : Utils.format_page_number(paginated_page_url, cur_page_nr, @total_pages) @previous_page = @page != 1 ? @page - 1 : nil @previous_page_path = @page != 1 ? @page == 2 ? first_index_page_url : Utils.format_page_number(paginated_page_url, @previous_page, @total_pages) : nil @next_page = @page != @total_pages ? @page + 1 : nil @next_page_path = @page != @total_pages ? Utils.format_page_number(paginated_page_url, @next_page, @total_pages) : nil end |
Instance Attribute Details
#next_page ⇒ Object (readonly)
Returns the value of attribute next_page.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def next_page @next_page end |
#next_page_path ⇒ Object (readonly)
Returns the value of attribute next_page_path.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def next_page_path @next_page_path end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def page @page end |
#page_path ⇒ Object (readonly)
Returns the value of attribute page_path.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def page_path @page_path end |
#page_trail ⇒ Object
Returns the value of attribute page_trail.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def page_trail @page_trail end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def per_page @per_page end |
#posts ⇒ Object (readonly)
Returns the value of attribute posts.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def posts @posts end |
#previous_page ⇒ Object (readonly)
Returns the value of attribute previous_page.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def previous_page @previous_page end |
#previous_page_path ⇒ Object (readonly)
Returns the value of attribute previous_page_path.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def previous_page_path @previous_page_path end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def total_pages @total_pages end |
#total_posts ⇒ Object (readonly)
Returns the value of attribute total_posts.
8 9 10 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 8 def total_posts @total_posts end |
Instance Method Details
#to_liquid ⇒ Object
Convert this Paginator’s data to a Hash suitable for use by Liquid.
Returns the Hash representation of this Paginator.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jekyll-paginate-v2-redux/generator/paginator.rb', line 45 def to_liquid { 'per_page' => per_page, 'posts' => posts, 'total_posts' => total_posts, 'total_pages' => total_pages, 'page' => page, 'page_path' => page_path, 'previous_page' => previous_page, 'previous_page_path' => previous_page_path, 'next_page' => next_page, 'next_page_path' => next_page_path, 'page_trail' => page_trail } end |