source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/classes/offset/offset_test.rb
Ruby
mit
4,963
master
3,040
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::Offset Specs' do let(:pagy_class) { Pagy::Offset } describe 'initialization' do it 'initializes with defaults' do pagy = pagy_class.new(count: 100) _(pagy.page).must_equal 1 _(pagy.limit).must_equal 20 _(pagy.las...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/classes/offset/countish_test.rb
Ruby
mit
4,963
master
720
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::Offset::Countish Specs' do let(:pagy_class) { Pagy::Offset::Countish } it 'composes page param with count' do pagy = pagy_class.new(count: 100) param = pagy.send(:compose_page_param, 2) _(param).must_be_kind_of Pagy::EscapedVal...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/classes/offset/countless_test.rb
Ruby
mit
4,963
master
4,448
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::Offset::Countless Specs' do let(:pagy_class) { Pagy::Offset::Countless } describe 'initialization' do it 'initializes with defaults' do pagy = pagy_class.new _(pagy.page).must_equal 1 _(pagy.limit).must_equal 20 ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/console_test.rb
Ruby
mit
4,963
master
1,752
# frozen_string_literal: true require 'unit/test_helper' require 'pagy/modules/console' # Create a mock class to simulate including the Pagy::Console module class MockContext include Pagy::Console end describe 'Pagy::Console' do before do @mock_context = MockContext.new end describe 'params' do it '...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/searcher_test.rb
Ruby
mit
4,963
master
1,650
# frozen_string_literal: true require 'unit/test_helper' require 'pagy/modules/searcher' describe 'Pagy::Searcher Specs' do let(:searcher) { Pagy::Searcher } # Mock Request object let(:mock_request_class) do Struct.new(:page, :limit) do def resolve_page = page def resolve_limit = limit end ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/b64_test.rb
Ruby
mit
4,963
master
2,218
# frozen_string_literal: true require 'unit/test_helper' require 'pagy/modules/b64' describe 'Pagy::B64 Specs' do let(:b64) { Pagy::B64 } describe 'standard methods' do it 'encodes and decodes simple strings' do str = 'Simple String' # 'm0' should not add newlines encoded = b64.encode(str) ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/abilities/countable_test.rb
Ruby
mit
4,963
master
2,536
# frozen_string_literal: true require 'unit/test_helper' require 'pagy/modules/abilities/countable' describe 'Pagy::Countable Specs' do let(:countable) { Pagy::Countable } it 'counts arrays using size' do _(countable.get_count([1, 2, 3, 4], {})).must_equal 4 end describe 'Sequel Dataset Logic' do # ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/abilities/linkable_test.rb
Ruby
mit
4,963
master
5,353
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::Linkable Specs' do describe 'QueryUtils' do let(:utils) { Pagy::Linkable::QueryUtils } it 'escapes strings' do _(utils.escape('a b')).must_equal 'a+b' _(utils.escape('/?&')).must_equal '%2F%3F%26' end it 'builds s...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/abilities/shiftable_test.rb
Ruby
mit
4,963
master
1,011
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::Offset::Shiftable Specs' do let(:shiftable_class) do Class.new do include Pagy::Offset::Shiftable attr_accessor :page, :last, :previous, :next def run assign_previous_and_next end end end let(:moc...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/abilities/rangeable_test.rb
Ruby
mit
4,963
master
1,559
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::Offset::Rangeable Specs' do # Use an anonymous class to test the mixin without namespace pollution let(:rangeable_class) do Class.new do include Pagy::Offset::Rangeable attr_reader :options, :last, :page def initializ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/abilities/configurable_test.rb
Ruby
mit
4,963
master
4,743
# frozen_string_literal: true require 'unit/test_helper' require 'fileutils' require 'pathname' require 'i18n' require 'pagy/toolbox/helpers/info_tag' # Required for the integration test describe 'Pagy::Configurable Specs' do describe 'sync_javascript' do let(:destination) { Dir.mktmpdir } let(:all_files) {...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/i18n_test.rb
Ruby
mit
4,963
master
5,419
# frozen_string_literal: true require 'unit/test_helper' require 'fileutils' # Mock P11n class for testing custom dictionaries module Pagy::I18n::P11n # rubocop:disable Style/ClassAndModuleChildren module TestRule def self.plural_for(count) case count when 0 then 'zero' when 1 then 'one' ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/locales_test.rb
Ruby
mit
4,963
master
2,228
# frozen_string_literal: true require 'unit/test_helper' require 'yaml' describe 'locales' do # Define the expected keys for each pluralization rule let(:counts) do { 'Arabic' => %w[zero one two few many other], 'EastSlavic' => %w[one few many other], 'OneOther' => %w[one othe...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/west_slavic_test.rb
Ruby
mit
4,963
master
536
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::WestSlavic Specs' do let(:rule) { Pagy::I18n::P11n::WestSlavic } it 'returns :one for 1' do _(rule.plural_for(1)).must_equal :one end it 'returns :few for 2, 3, 4' do [2, 3, 4].each do |n| _(rule.plural_for(n)...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/one_other_test.rb
Ruby
mit
4,963
master
499
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::OneOther Specs' do let(:rule) { Pagy::I18n::P11n::OneOther } it 'returns :one for 1' do _(rule.plural_for(1)).must_equal :one end it 'returns :other for 0' do _(rule.plural_for(0)).must_equal :other end it 'ret...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/arabic_test.rb
Ruby
mit
4,963
master
913
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::Arabic Specs' do let(:rule) { Pagy::I18n::P11n::Arabic } it 'returns :zero for 0' do _(rule.plural_for(0)).must_equal :zero end it 'returns :one for 1' do _(rule.plural_for(1)).must_equal :one end it 'returns :...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/polish_test.rb
Ruby
mit
4,963
master
960
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::Polish Specs' do let(:rule) { Pagy::I18n::P11n::Polish } it 'returns :one for 1' do _(rule.plural_for(1)).must_equal :one end it 'returns :few for 2-4 (excluding teens 12-14)' do # 2, 3, 4, 22, 23, 24, 102... [2...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/east_slavic_test.rb
Ruby
mit
4,963
master
1,159
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::EastSlavic Specs' do let(:rule) { Pagy::I18n::P11n::EastSlavic } it 'returns :one for numbers ending in 1 (except 11)' do [1, 21, 31, 41, 101, 1001].each do |n| _(rule.plural_for(n)).must_equal :one, "Failed for #{n}" ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/other_test.rb
Ruby
mit
4,963
master
288
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::Other Specs' do let(:rule) { Pagy::I18n::P11n::Other } it 'always returns :other' do [0, 1, 2, 5, 10, 100, -1, 1.5].each do |n| _(rule.plural_for(n)).must_equal :other end end end
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/unit/pagy/modules/i18n/p11n/one_upto_two_other_test.rb
Ruby
mit
4,963
master
570
# frozen_string_literal: true require 'unit/test_helper' describe 'Pagy::I18n::P11n::OneUptoTwoOther Specs' do let(:rule) { Pagy::I18n::P11n::OneUptoTwoOther } it 'returns :one for [0, 2)' do [0, 0.5, 1, 1.99].each do |n| _(rule.plural_for(n)).must_equal :one, "Failed for #{n}" end end it 'ret...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/keynav_test.rb
Ruby
mit
4,963
master
348
# frozen_string_literal: true require 'e2e/test_helper' describe 'Keynav App' do parallelize_me! unless ENV['CI'] pages = (1..13).map(&:to_s) + %w[10 13] it "checks series_nav" do check_nav('#series-nav', pages:) end it "checks series_nav_js responsive" do check_nav('#series-nav-js-responsive', p...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/demo_test.rb
Ruby
mit
4,963
master
768
# frozen_string_literal: true require 'e2e/test_helper' describe 'Demo App' do parallelize_me! unless ENV['CI'] it "checks series_nav" do %w[/pagy /bootstrap /bulma].each do |path| check_nav('#series-nav', path:) end end it "checks series_nav_js responsive" do %w[/pagy /bootstrap /bulma].e...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/calendar_test.rb
Ruby
mit
4,963
master
1,094
# frozen_string_literal: true require 'e2e/test_helper' describe 'Calendar App' do parallelize_me! unless ENV['CI'] ids = %w[#year-nav #month-nav #day-nav #pagy-info] it "checks the HTML elements (skip true/false)" do %w[true false].each do |val| browser.goto("?skip_counts=#{val}") # Test #go...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/repro_test.rb
Ruby
mit
4,963
master
498
# frozen_string_literal: true require 'e2e/test_helper' describe 'Repro App' do parallelize_me! unless ENV['CI'] it "checks series_nav" do check_nav('#series-nav') end it "checks series_nav_js responsive" do check_nav('#series-nav-js-responsive', rjs: true) end it "checks input_nav_js" do c...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/test_helper.rb
Ruby
mit
4,963
master
1,150
# frozen_string_literal: true ENV.delete('COVERAGE') # Allow to skip the coverage when used after its task require_relative '../test_helper' require 'ferrum' require 'minitest/hooks/default' require_relative 'helpers/e2e_app' require_relative 'helpers/functions' class E2eTest < Minitest::Spec include E2eFunction...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/rails_test.rb
Ruby
mit
4,963
master
493
# frozen_string_literal: true require 'e2e/test_helper' describe 'Rails App' do parallelize_me! unless ENV['CI'] it "checks series_nav" do check_nav('#series-nav', pages: %w[3]) end it "checks series_nav_js" do check_nav('#series-nav-js', pages: %w[3]) end it "checks input_nav_js" do check_...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/helpers/functions.rb
Ruby
mit
4,963
master
5,917
# frozen_string_literal: true require 'nokogiri' require 'json' require 'pagy/modules/b64' module E2eFunctions LOCATION_RE = %r{\Ahttp://#{Regexp.escape(E2eApp::IP)}:808\d/?} def goto_and_hold(id, path: '/', query: '') browser.goto("#{path}#{query}") hold_location hold_html(id) end def interact_...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/e2e/helpers/e2e_app.rb
Ruby
mit
4,963
master
1,326
# frozen_string_literal: true require 'concurrent' require 'childprocess' require 'socket' require_relative '../../../gem/lib/pagy' class E2eApp APPS = { repro: { port: 8080 }, rails: { port: 8081 }, keynav: { port: 8082 }, demo: { port: 8083 }, ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/api/next_test.rb
Ruby
mit
4,963
master
2,222
# frozen_string_literal: true ENV['PAGY_NEXT'] = 'true' require 'unit/test_helper' require 'pagy/classes/request' describe 'Pagy Next Mode' do it 'loads the next module' do _(ENV.fetch('PAGY_NEXT', nil)).must_equal 'true' end describe 'Deprecated :max_pages option' do it 'works with Offset' do #...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/api/current_test.rb
Ruby
mit
4,963
master
2,251
# frozen_string_literal: true require 'unit/test_helper' require 'pagy/classes/request' describe 'Pagy Deprecated Code' do it 'does not load the next module' do _(defined?(Pagy::Next)).must_be_nil end describe 'Deprecated :max_pages option' do it 'works with Offset' do assert_output(nil, /:max_pa...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
test/helpers/minitest_backtraces.rb
Ruby
mit
4,963
master
1,601
# frozen_string_literal: true # /usr/local/lib/ruby/gems/3.4.0/gems/minitest-5.25.4/lib/minitest.rb module Minitest module ShortenPaths def filter_backtrace(...) # :nodoc: super.map { _1.sub(%r{^#{pwd}/}, '') } end private def pwd @pwd = begin git = system('git --version'...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/pagy.gemspec
Ruby
mit
4,963
master
1,300
# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'pagy' s.version = '43.5.3' s.authors = ['Domizio Demichelis'] s.email = ['dd.nexus@gmail.com'] s.summary = 'Pagy 🐸 The Leaping Gem!' s.description = 'Agnostic pagination in plain ruby.' s.homepage = 'https:...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/config/pagy.rb
Ruby
mit
4,963
master
1,870
# frozen_string_literal: true # Pagy initializer file (43.5.3) # See https://ddnexus.github.io/pagy/toolbox/configuration/initializer/ ############ Global Options ################################################################ # See https://ddnexus.github.io/pagy/toolbox/configuration/options/ for details. # Exampl...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy.rb
Ruby
mit
4,963
master
3,121
# frozen_string_literal: true require 'pathname' require_relative 'pagy/classes/exceptions' require_relative 'pagy/modules/abilities/linkable' require_relative 'pagy/modules/abilities/configurable' require_relative 'pagy/toolbox/helpers/loaders' # Top superclass class Pagy VERSION = '43.5.3' ROOT = Pa...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/next.rb
Ruby
mit
4,963
master
802
# See https://ddnexus.github.io/pagy/guides/pagy-next/ # frozen_string_literal: true ENV['PAGY_NEXT'] = 'true' # :nocov: require_relative '../pagy' unless defined?(Pagy) # avoid circular require (also from pagy itself) # :nocov: class Pagy VERSION = "#{remove_const(:VERSION)}.next".freeze class NextError < Argu...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/deprecated.rb
Ruby
mit
4,963
master
2,293
# frozen_string_literal: true # This file relegates all the deprecation warnings and code. # Pagy already implements the next code and this file works as a compatibility layer # to avoid breaking changes in the current version, respecting the Semantic Version contract. class Pagy module Deprecated def self.clien...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/cli.rb
Ruby
mit
4,963
master
3,743
# frozen_string_literal: true require 'optparse' require 'fileutils' require 'rbconfig' require_relative '../pagy' require_relative '../../apps/index' class Pagy class CLI HOST = 'localhost' PORT = '8000' def start(args = ARGV) options = parse_options(args) run_command(args, options) en...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/console.rb
Ruby
mit
4,963
master
654
# frozen_string_literal: true class Pagy # Ready to use pagy environment when included in irb/rails console module Console class Collection < Array def initialize(arr = Array(1..1000)) super @collection = clone end def offset(value) tap { @collection = self[value..] }...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/b64.rb
Ruby
mit
4,963
master
612
# frozen_string_literal: true class Pagy # Cheap Base64 specialized methods to avoid dependencies module B64 module_function def encode(bin) [bin].pack('m0') end def decode(str) str.unpack1('m0') end def urlsafe_encode(bin) str = encode(bin) str.tr!('+/', '-_') ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/searcher.rb
Ruby
mit
4,963
master
428
# frozen_string_literal: true class Pagy module Searcher module_function # Common search logic def wrap(search_arguments, options) options[:page] ||= options[:request].resolve_page options[:limit] = options[:request].resolve_limit pagy, results = yield called = search_argumen...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/abilities/shiftable.rb
Ruby
mit
4,963
master
223
# frozen_string_literal: true class Pagy module Shiftable protected def assign_previous_and_next @previous = @page - 1 unless @page == 1 @next = @page + 1 unless @page == @last end end end
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/abilities/countable.rb
Ruby
mit
4,963
master
696
# frozen_string_literal: true class Pagy # Count a collection module Countable module_function def get_count(collection, options) return collection.size if collection.instance_of?(Array) return collection.count unless defined?(::ActiveRecord) && collection.is_a?(::ActiveRecord::Relation) ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/abilities/linkable.rb
Ruby
mit
4,963
master
2,296
# frozen_string_literal: true require 'uri' class Pagy # Support spaces in placeholder params class EscapedValue < String; end # Handle the url and anchor module Linkable module QueryUtils module_function # Extracted from Rack::Utils and reformatted for rubocop. # Allow unescaped Pagy:...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/abilities/rangeable.rb
Ruby
mit
4,963
master
351
# frozen_string_literal: true class Pagy # Support range checking, error and rescue module Rangeable def in_range? return @in_range if defined?(@in_range) return true if (@in_range = yield) raise RangeError.new(self, :page, "in 1..#{@last}", @page) if @options[:raise_range_error] @in_r...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/abilities/configurable.rb
Ruby
mit
4,963
master
1,153
# frozen_string_literal: true class Pagy # Configuration methods module Configurable # Sync the pagy resource targets. def sync(resource, destination, *targets) files = ROOT.join("#{resource}s").glob("{#{targets.join(',')}}") unknownn = targets - files.map { |f| f.basename.to_s } raise...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/i18n.rb
Ruby
mit
4,963
master
2,139
# frozen_string_literal: true require 'yaml' require_relative 'p11n' class Pagy # Faster and lighter Pagy i18n implementation, compatible with the I18n gem module I18n class KeyError < KeyError; end extend self def pathnames @pathnames ||= [ROOT.join('locales')] end def locales ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n.rb
Ruby
mit
4,963
master
538
# frozen_string_literal: true class Pagy module I18n module P11n path = ROOT.join('lib/pagy/modules/i18n/p11n') autoload :Arabic, path.join('arabic') autoload :EastSlavic, path.join('east_slavic') autoload :OneOther, path.join('one_other') autoload :OneUptoTwoOt...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n/one_upto_two_other.rb
Ruby
mit
4,963
master
238
# frozen_string_literal: true class Pagy module I18n module P11n module OneUptoTwoOther module_function def plural_for(n = 0) n >= 0 && n < 2 ? :one : :other end end end end end
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n/arabic.rb
Ruby
mit
4,963
master
564
# frozen_string_literal: true class Pagy module I18n module P11n module Arabic module_function def plural_for(n = 0) mod100 = n % 100 case when n == 0 # rubocop:disable Style/NumericPredicate :zero when n == 1 :one ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n/east_slavic.rb
Ruby
mit
4,963
master
612
# frozen_string_literal: true class Pagy module I18n module P11n module EastSlavic module_function def plural_for(n = 0) mod10 = n % 10 mod100 = n % 100 case when mod10 == 1 && mod100 != 11 :one when (2..4).to_a.include?(mod10...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n/polish.rb
Ruby
mit
4,963
master
539
# frozen_string_literal: true class Pagy module I18n module P11n module Polish module_function def plural_for(n = 0) mod10 = n % 10 mod100 = n % 100 case when n == 1 :one when [2, 3, 4].include?(mod10) && ![12, 13, 14].include...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n/one_other.rb
Ruby
mit
4,963
master
222
# frozen_string_literal: true class Pagy module I18n module P11n module OneOther module_function def plural_for(n = 0) n == 1 ? :one : :other end end end end end
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/modules/i18n/p11n/west_slavic.rb
Ruby
mit
4,963
master
330
# frozen_string_literal: true class Pagy module I18n module P11n module WestSlavic module_function def plural_for(n = 0) case n when 1 :one when 2, 3, 4 :few else :other end end end end ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/request.rb
Ruby
mit
4,963
master
1,489
# frozen_string_literal: true class Pagy # Decouple the request from the env, allowing non-rack apps to use pagy by passing a hash. # Resolve the :page and :limit options from params. class Request def initialize(options) @options = options request = @options[:request] @base_url, @path, @p...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/exceptions.rb
Ruby
mit
4,963
master
621
# frozen_string_literal: true class Pagy # Specific subclass of ArgumentError class OptionError < ArgumentError attr_reader :pagy, :option, :value # Prepare a useful feedback def initialize(pagy, option, description, value) @pagy = pagy @option = option @value = value super...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/unit.rb
Ruby
mit
4,963
master
3,541
# frozen_string_literal: true require_relative '../../modules/abilities/shiftable' require_relative '../../modules/abilities/rangeable' class Pagy class Calendar # Base class for time units subclasses (Year, Quarter, Month, Week, Day). # # To define a "bimester" unit you should: # - Define a `Pagy::...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/month.rb
Ruby
mit
4,963
master
873
# frozen_string_literal: true class Pagy # :nodoc: class Calendar # :nodoc: class Month < Unit DEFAULT = { slots: 12, compact: true, order: :asc, format: '%b' }.freeze protected def assign_unit_variables super @initial...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/day.rb
Ruby
mit
4,963
master
857
# frozen_string_literal: true class Pagy class Calendar class Day < Unit DEFAULT = { slots: 31, compact: true, order: :asc, format: '%d' }.freeze protected def assign_unit_variables super @initial = @starting.beginning...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/week.rb
Ruby
mit
4,963
master
804
# frozen_string_literal: true class Pagy class Calendar class Week < Unit DEFAULT = { order: :asc, format: '%Y-%W' }.freeze protected def assign_unit_variables super @initial = @starting.beginning_of_week @final = @ending.next_week.beginning_of_w...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/year.rb
Ruby
mit
4,963
master
848
# frozen_string_literal: true class Pagy # :nodoc: class Calendar # :nodoc: # Year unit subclass class Year < Unit DEFAULT = { slots: 10, compact: true, order: :asc, format: '%Y' }.freeze protected # Set up the calendar variables ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/quarter.rb
Ruby
mit
4,963
master
1,270
# frozen_string_literal: true class Pagy # :nodoc: class Calendar # :nodoc: class Quarter < Unit DEFAULT = { slots: 4, compact: true, order: :asc, format: 'Q%q' }.freeze # '%q' token protected # The label for any page, with the substi...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/calendar/calendar.rb
Ruby
mit
4,963
master
3,586
# frozen_string_literal: true require 'active_support' require 'active_support/core_ext/time' require 'active_support/core_ext/date_and_time/calculations' require 'active_support/core_ext/numeric/time' require 'active_support/core_ext/integer/time' class Pagy # Calendar class, subclass of Hash class Calendar < Ha...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/keyset/keynav.rb
Ruby
mit
4,963
master
2,656
# frozen_string_literal: true class Pagy class Keyset # Keyset pagination with broad UI support class Keynav < Keyset # Avoid conflicts between filter arguments in composite SQL fragments PRIOR_PREFIX = 'prior_' PAGE_PREFIX = 'page_' # Define empty subclasses to allow specific typin...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/keyset/keyset.rb
Ruby
mit
4,963
master
5,036
# frozen_string_literal: true require 'json' require_relative '../../modules/b64' class Pagy # Fast keyset pagination for big data class Keyset < Pagy # Autoload adapters only when const_get accesses them module Adapters path = Pathname.new(__dir__) autoload :ActiveRecord, path.join('adapters/...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/keyset/adapters/active_record.rb
Ruby
mit
4,963
master
1,320
# frozen_string_literal: true class Pagy class Keyset module Adapters # Keyset adapter for ActiveRecord module ActiveRecord def extract_keyset @set.order_values.each_with_object({}) do |node, keyset| keyset[node.value.name.to_sym] ||= node.direction end ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/keyset/adapters/sequel.rb
Ruby
mit
4,963
master
1,786
# frozen_string_literal: true class Pagy class Keyset module Adapters # Keyset adapter for Sequel ORM module Sequel def extract_keyset return {} unless @set.opts[:order] @set.opts[:order].each_with_object({}) do |item, keyset| case item when Symbol...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/offset/countless.rb
Ruby
mit
4,963
master
2,004
# frozen_string_literal: true class Pagy class Offset # Offset pagination without any COUNT query class Countless < Offset def initialize(**) assign_options(**) assign_and_check(limit: 1, page: 1) @last = @options[:last] unless @options[:headless] assign_offset end...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/offset/countish.rb
Ruby
mit
4,963
master
389
# frozen_string_literal: true class Pagy class Offset # Offset pagination with memoized count class Countish < Offset protected # Return page+count or page+count+epoch def compose_page_param(page) value = "#{page || 1}+#{@count}" value << "+#{@options[:epoch]}" if @options...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/offset/search.rb
Ruby
mit
4,963
master
810
# frozen_string_literal: true class Pagy module Search class Arguments < Array def respond_to_missing?(*) = true def method_missing(*) = push(*) end # Collect the search arguments to pass to the actual search def pagy_search(*arguments, **options, &block) Arguments.new([self, argu...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/classes/offset/offset.rb
Ruby
mit
4,963
master
1,514
# frozen_string_literal: true require_relative '../../modules/abilities/shiftable' require_relative '../../modules/abilities/rangeable' class Pagy # Implements Offset Pagination class Offset < Pagy DEFAULT = { page: 1 }.freeze autoload :Countless, Pathname.new(__dir__).join('countless') autoload :Cou...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/tasks/sync.rb
Ruby
mit
4,963
master
456
# frozen_string_literal: true require 'rake' require 'rake/tasklib' class Pagy class SyncTask < Rake::TaskLib # Define a rake task for syncing a specific resource on demand def initialize(resource, destination, *targets) namespace :pagy do namespace :sync do desc "Sync #{resource}" ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/series_nav_js.rb
Ruby
mit
4,963
master
722
# frozen_string_literal: true require_relative 'support/wrap_series_nav_js' class Pagy module NumericHelpers def series_nav_js(style = nil, **) return send(:"#{style}_series_nav_js", **) if style && style.to_s != 'pagy' a_lambda = a_lambda(**) tokens = { before: previous_tag(a_lambda), ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/loaders.rb
Ruby
mit
4,963
master
2,486
# frozen_string_literal: true class Pagy # The aliaser defines loader methods and aliases them. # When a method is called for the first time, its loader will load the full implementation, # which will overwrite the alias and will be executed. # Subsequent calls will run the full implementation directly. alia...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/anchor_tags.rb
Ruby
mit
4,963
master
535
# frozen_string_literal: true class Pagy module NumericHelpers def previous_tag(...) = anchor_tag_for(:previous, ...) end def next_tag(...) = anchor_tag_for(:next, ...) private def anchor_tag_for(which, a = nil, text: I18n.translate("pagy.#{which}"), aria_label: I18n.translate("pa...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/info_tag.rb
Ruby
mit
4,963
master
1,110
# frozen_string_literal: true class Pagy module NumericHelpers # Instances with count return "Displaying items 41-60 of 324 in total" or "Displaying Products 41-60 of 324 in total". # Instances with no count return only page info: "Page 3 of 100". def info_tag(id: nil, item_name: nil) i18n_key = i...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/series_nav.rb
Ruby
mit
4,963
master
1,000
# frozen_string_literal: true require_relative 'support/wrap_series_nav' class Pagy module NumericHelpers def series_nav(style = nil, **) return send(:"#{style}_series_nav", **) if style && style.to_s != 'pagy' a_lambda = a_lambda(**) html = previous_tag(a_lambda) series(**).each do |i...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/page_url.rb
Ruby
mit
4,963
master
450
# frozen_string_literal: true class Pagy def page_url(page, **) target = case page when :first then nil when :current, :page then @page when :previous then @previous when :next then @next when :last then @last ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/headers_hash.rb
Ruby
mit
4,963
master
957
# frozen_string_literal: true require_relative 'urls_hash' # Handle pagination response headers class Pagy DEFAULT_HEADERS_MAP = { page: 'current-page', limit: 'page-limit', count: 'total-count', pages: 'total-pages' }.freeze # Genera...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/input_nav_js.rb
Ruby
mit
4,963
master
737
# frozen_string_literal: true require_relative 'support/wrap_input_nav_js' class Pagy module NumericHelpers def input_nav_js(style = nil, **) return send(:"#{style}_input_nav_js", **) if style && style.to_s != 'pagy' a_lambda = a_lambda(**) input = %(<input name="page" type="number" min="1" ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/limit_tag_js.rb
Ruby
mit
4,963
master
990
# frozen_string_literal: true require_relative 'support/data_pagy_attribute' class Pagy module NumericHelpers def limit_tag_js(id: nil, item_name: nil, max_limit: @options[:max_limit], **) raise OptionError.new(self, :max_limit, 'to be truthy', max_limit) unless max_limit limit_input = %(<input nam...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/urls_hash.rb
Ruby
mit
4,963
master
378
# frozen_string_literal: true class Pagy def urls_hash(**) template = compose_page_url(PAGE_TOKEN, **) { first: compose_page_url(nil, **), previous: @previous && template.sub(PAGE_TOKEN, @previous.to_s), next: @next && template.sub(PAGE_TOKEN, @next.to_s), last: @count &&...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/data_hash.rb
Ruby
mit
4,963
master
1,195
# frozen_string_literal: true class Pagy DEFAULT_DATA_KEYS = %i[url_template first_url previous_url current_url page_url next_url last_url count page limit last in from to previous next options series].freeze # Generate a hash of the wanted internal data def data_hash(data_keys: @option...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bootstrap/series_nav_js.rb
Ruby
mit
4,963
master
1,023
# frozen_string_literal: true require_relative 'previous_next_html' require_relative '../support/wrap_series_nav_js' class Pagy module NumericHelpers private def bootstrap_series_nav_js(classes: 'pagination', **) a_lambda = a_lambda(**) tokens = { before: %(<ul class="#{classes}">#{bootstra...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bootstrap/series_nav.rb
Ruby
mit
4,963
master
1,262
# frozen_string_literal: true require_relative 'previous_next_html' require_relative '../support/wrap_series_nav' class Pagy module NumericHelpers private def bootstrap_series_nav(classes: 'pagination', **) a_lambda = a_lambda(**) html = %(<ul class="#{classes}">#{bootstrap_html_for(:previous,...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bootstrap/previous_next_html.rb
Ruby
mit
4,963
master
638
# frozen_string_literal: true class Pagy module NumericHelpers private def bootstrap_html_for(which, a_lambda) if send(which) %(<li class="page-item #{which}">#{ a_lambda.(send(which), I18n.translate("pagy.#{which}"), classes: 'page-link', a...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bootstrap/input_nav_js.rb
Ruby
mit
4,963
master
1,048
# frozen_string_literal: true require_relative 'previous_next_html' require_relative '../support/wrap_input_nav_js' class Pagy module NumericHelpers private def bootstrap_input_nav_js(classes: 'pagination', **) a_lambda = a_lambda(**) input = %(<input name="page" type="number" min="1" max="...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/wrap_series_nav_js.rb
Ruby
mit
4,963
master
1,235
# frozen_string_literal: true require_relative 'nav_aria_label_attribute' require_relative 'data_pagy_attribute' # Relegate internal functions. Make overriding navs easier. class Pagy private # The reverse-sorted array of widths, series, and labels generated from the :steps hash. # If :steps is false it will u...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/nav_aria_label_attribute.rb
Ruby
mit
4,963
master
216
# frozen_string_literal: true class Pagy private def nav_aria_label_attribute(aria_label: nil) aria_label ||= I18n.translate('pagy.aria_label.nav', count: @last) %(aria-label="#{aria_label}") end end
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/a_lambda.rb
Ruby
mit
4,963
master
1,441
# frozen_string_literal: true class Pagy protected def page_label(page, **options) return page.to_s unless calendar? options[:format] ||= @options[:format] localize(starting_time_for(page.to_i), **options) # page could be a string end # Return a performance optimized lambda to generate the anch...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/series.rb
Ruby
mit
4,963
master
1,340
# frozen_string_literal: true class Pagy SERIES_SLOTS = 7 protected # The array of page numbers and :gap e.g. [1, :gap, 8, "9", 10, :gap, 36] def series(slots: @options[:slots] || SERIES_SLOTS, compact: @options[:compact], **) raise OptionError.new(self, :slots, 'to be an Integer >= 0', slots) unless slo...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/wrap_input_nav_js.rb
Ruby
mit
4,963
master
516
# frozen_string_literal: true require_relative 'nav_aria_label_attribute' require_relative 'data_pagy_attribute' class Pagy private # Common input_nav_js logic def wrap_input_nav_js(html, nav_classes, id: nil, aria_label: nil, **) %(<nav#{%( id="#{id}") if id} class="#{nav_classes}" #{ nav_aria_label...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/data_pagy_attribute.rb
Ruby
mit
4,963
master
438
# frozen_string_literal: true require 'json' require_relative '../../../modules/b64' class Pagy private # Compose the data-pagy attribute, with the base64 encoded JSON-serialized args. Use the faster oj gem if defined. def data_pagy_attribute(*args) data = if defined?(Oj) Oj.dump(args, mode: :...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/support/wrap_series_nav.rb
Ruby
mit
4,963
master
429
# frozen_string_literal: true require_relative 'nav_aria_label_attribute' require_relative 'data_pagy_attribute' class Pagy private # Common series_nav logic def wrap_series_nav(html, nav_classes, id: nil, aria_label: nil, **) data = %( #{data_pagy_attribute(:k, @update)}) if keynav? %(<nav#{%( id="#{...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bulma/series_nav.rb
Ruby
mit
4,963
master
1,189
# frozen_string_literal: true require_relative 'previous_next_html' require_relative '../support/wrap_series_nav' class Pagy module NumericHelpers private def bulma_series_nav(classes: 'pagination', **) a_lambda = a_lambda(**) html = %(<ul class="pagination-list">#{bulma_html_for(:previous, a_...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bulma/series_nav_js.rb
Ruby
mit
4,963
master
924
# frozen_string_literal: true require_relative 'previous_next_html' require_relative '../support/wrap_series_nav_js' class Pagy module NumericHelpers private def bulma_series_nav_js(classes: 'pagination', **) a_lambda = a_lambda(**) tokens = { before: %(<ul class="pagination-list">#{bulma_h...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bulma/previous_next_html.rb
Ruby
mit
4,963
master
608
# frozen_string_literal: true class Pagy module NumericHelpers private def bulma_html_for(which, a_lambda) %(<li>#{ if send(which) a_lambda.(send(which), I18n.translate("pagy.#{which}"), classes: "pagination-#{which}", aria_label: I18n.trans...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/helpers/bulma/input_nav_js.rb
Ruby
mit
4,963
master
1,000
# frozen_string_literal: true require_relative 'previous_next_html' require_relative '../support/wrap_input_nav_js' class Pagy module NumericHelpers private def bulma_input_nav_js(classes: 'pagination', **) a_lambda = a_lambda(**) input = %(<input name="page" type="number" min="1" max="#{@l...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/paginators/offset.rb
Ruby
mit
4,963
master
630
# frozen_string_literal: true require_relative '../../modules/abilities/countable' class Pagy module OffsetPaginator module_function def paginate(collection, options) options[:page] ||= options[:request].resolve_page options[:limit] = options[:request].resolve_limit options[:count] ||=...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/paginators/keyset.rb
Ruby
mit
4,963
master
352
# frozen_string_literal: true class Pagy module KeysetPaginator module_function def paginate(set, options) options[:page] ||= options[:request].resolve_page(force_integer: false) # allow nil options[:limit] = options[:request].resolve_limit pagy = Keyset.new(set, **options) [pagy, ...
github
ddnexus/pagy
https://github.com/ddnexus/pagy
gem/lib/pagy/toolbox/paginators/keynav_js.rb
Ruby
mit
4,963
master
817
# frozen_string_literal: true require_relative '../../../pagy/modules/b64' class Pagy module KeynavJsPaginator module_function def paginate(set, options) page = options[:request].resolve_page(force_integer: false) # allow nil return CountlessPaginator.paginate(set, page:, **options) if page&.m...