module Middleman::Pagination

Public Class Methods

page_locals(page_num, num_pages, collection, items, page_start) click to toggle source
# File lib/middleman-core/core_extensions/collections/pagination.rb, line 40
def self.page_locals(page_num, num_pages, collection, items, page_start)
  per_page = items.length

  # Index into collection of the last item of this page
  page_end = (page_start + per_page) - 1

  ::Middleman::Util.recursively_enhance(page_number: page_num,
                                        num_pages: num_pages,
                                        per_page: per_page,

                                        # The range of item numbers on this page
                                        # (1-based, for showing "Items X to Y of Z")
                                        page_start: page_start + 1,
                                        page_end: [page_end + 1, collection.length].min,

                                        # Use "collection" in templates.
                                        collection: collection)
end