lib/pagy.rb in pagy-2.1.5 vs lib/pagy.rb in pagy-3.0.0
- old
+ new
@@ -2,19 +2,19 @@
# encoding: utf-8
# frozen_string_literal: true
require 'pathname'
-class Pagy ; VERSION = '2.1.5'
+class Pagy ; VERSION = '3.0.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; @root ||= Pathname.new(__FILE__).dirname.freeze 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', cycle: false }
+ VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page, params:{}, anchor:'', link_extra:'', i18n_key:'pagy.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)
@@ -39,10 +39,10 @@
4.times{|i| (size[i]>=0 rescue nil) or raise(ArgumentError, "expected 4 items >= 0 in :size; got #{size.inspect}")}
[*0..size[0], *@page-size[1]..@page+size[2], *@last-size[3]+1..@last+1].sort!.each_cons(2) do |a, b|
if a<0 || a==b || a>@last # skip out of range and duplicates
elsif a+1 == b; series.push(a) # no gap -> no additions
elsif a+2 == b; series.push(a, a+1) # 1 page gap -> fill with missing page
- else series.push(a, :gap) # n page gap -> add :gap
+ else series.push(a, :gap) # n page gap -> add gap
end # skip the end boundary (last+1)
end # shift the start boundary (0) and
series.shift; series[series.index(@page)] = @page.to_s; series # convert the current page to String
end