lib/pagy.rb in pagy-1.1.0 vs lib/pagy.rb in pagy-1.2.0

- old
+ new

@@ -1,19 +1,19 @@ # See Pagy API documentation: https://ddnexus.github.io/pagy/api/pagy # frozen_string_literal: true require 'pathname' -class Pagy ; VERSION = '1.1.0' +class Pagy ; VERSION = '1.2.0' class OverflowError < StandardError; attr_reader :pagy; def initialize(pagy) @pagy = pagy end; end # Root pathname to get the path of Pagy files like templates or dictionaries def self.root; Pathname.new(__FILE__).dirname end # default vars - VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', item_path:'pagy.info.item_name' } + VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', item_path:'pagy.info.item_name', cycle: false } attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next # Merge and validate the options, do some simple arithmetic and set the instance variables def initialize(vars) @@ -27,10 +27,10 @@ @offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset) @items = @count - ((@pages-1) * @items) if @page == @last && @count > 0 # adjust items for last non-empty page @from = @count == 0 ? 0 : @offset+1 - @outset # page begins from item @to = @count == 0 ? 0 : @offset + @items - @outset # page ends to item @prev = (@page-1 unless @page == 1) # nil if no prev page - @next = (@page+1 unless @page == @last) # nil if no next page + @next = @page == @last ? (1 if @vars[:cycle]) : @page+1 # nil if no next page, 1 if :cycle end # Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36] def series(size=@vars[:size]) (series = []) and size.empty? and return series