Module: Dimples::Pagination
- Included in:
- Site
- Defined in:
- lib/dimples/pagination.rb
Overview
A module that supports pagination.
Defined Under Namespace
Classes: Pager
Instance Method Summary collapse
Instance Method Details
#paginate(site, items, path, layout, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dimples/pagination.rb', line 6 def paginate(site, items, path, layout, = {}) context = [:context] || {} url = path.gsub(site.output_paths[:site], '') + '/' per_page = [:per_page] || site.config['pagination']['per_page'] pager = Pager.new(url, items, per_page) pager.each do |index, page_items| page = Dimples::Page.new(site) page.output_directory = if index == 1 path else File.join(path, "page#{index}") end page.layout = layout page.title = [:title] || site.templates[layout]&.title page.extension = [:extension] if [:extension] context[:items] = page_items context[:pagination] = pager.to_h page.write(context) end end |