Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jan 18, 2024
2 parents e1e22d7 + 5185a21 commit 25fe110
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GEM=pagy
VERSION=6.4.1
VERSION=6.4.2
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ None

<hr>

## Version 6.4.2

- Better module overrides in jsonapi
- Replaced the is_a?(Hash) check for jsonapi reserved :page param with respond_to?(:Fetch) and prepended to the Frontend
- Docs improvements and fixes

## Version 6.4.1

- Remove dependency on base64 (#618)Ruby 3.3 prints a warning if base64 is used without specifying it in the gemfile.
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source 'https://rubygems.org'

gem 'rake'

gem 'readline-ext' # temporary fix for RM 3.3.2 console with ruby >= 3.3.0

group :test do
gem 'activesupport'
gem 'codecov', require: false
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
rbzip2 (0.3.0)
readline-ext (0.2.0)
regexp_parser (2.9.0)
rematch (1.4.2)
rerun (0.14.0)
Expand Down Expand Up @@ -137,6 +138,7 @@ DEPENDENCIES
rack
rake
rake-manifest
readline-ext
rematch
rerun
rubocop
Expand Down
2 changes: 1 addition & 1 deletion lib/config/pagy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Pagy initializer file (6.4.1)
# Pagy initializer file (6.4.2)
# Customize only what you really need and notice that the core Pagy works also without any of the following lines.
# Should you just cherry pick part of this file, please maintain the require-order of the extras

Expand Down
4 changes: 2 additions & 2 deletions lib/javascripts/pagy-dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/javascripts/pagy-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Pagy = (() => {
const trim = (link, param) => link.replace(new RegExp(`(\\?|&amp;)${param}=1\\b(?!&amp;)|\\b${param}=1&amp;`), "");
// Public interface
return {
version: "6.4.1",
version: "6.4.2",
// Scan for elements with a "data-pagy" attribute and call their init functions with the decoded args
init(arg) {
const target = arg instanceof Element ? arg : document;
Expand Down
2 changes: 1 addition & 1 deletion lib/javascripts/pagy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Core class
class Pagy
VERSION = '6.4.1'
VERSION = '6.4.2'

# Root pathname to get the path of Pagy files like templates or dictionaries
def self.root
Expand Down
82 changes: 51 additions & 31 deletions lib/pagy/extras/jsonapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,71 @@ module JsonApiExtra
class ReservedParamError < StandardError
# Inform about the actual value
def initialize(value)
super("expected reserved :page param to be nil or Hash; got #{value.inspect}")
super("expected reserved :page param to be nil or Hash-like; got #{value.inspect}")
end
end

private
# Module overriding Backend
module BackendOverride
private

include UrlHelpers
include UrlHelpers

# Return the jsonapi links
def pagy_jsonapi_links(pagy, **opts)
{ first: pagy_url_for(pagy, 1, **opts),
last: pagy_url_for(pagy, pagy.last, **opts),
prev: pagy_url_for(pagy, pagy.prev, **opts),
next: pagy_url_for(pagy, pagy.next, **opts) }
end
# Return the jsonapi links
def pagy_jsonapi_links(pagy, **opts)
{ first: pagy_url_for(pagy, 1, **opts),
last: pagy_url_for(pagy, pagy.last, **opts),
prev: pagy_url_for(pagy, pagy.prev, **opts),
next: pagy_url_for(pagy, pagy.next, **opts) }
end

# Should skip the jsonapi
def pagy_skip_jsonapi?(vars)
return true if vars[:jsonapi] == false || (vars[:jsonapi].nil? && DEFAULT[:jsonapi] == false)
# check the reserved :page param and raise PageParamError or return nil
raise ReservedParamError, params[:page] unless params[:page].is_a?(Hash) || params[:page].nil?
end
# Should skip the jsonapi
def pagy_skip_jsonapi?(vars)
return true if vars[:jsonapi] == false || (vars[:jsonapi].nil? && DEFAULT[:jsonapi] == false)
# check the reserved :page param
raise ReservedParamError, params[:page] unless params[:page].respond_to?(:fetch) || params[:page].nil?
end

# Override the Backend method
def pagy_get_page(vars)
return super if pagy_skip_jsonapi?(vars)
# Override the Backend method
def pagy_get_page(vars)
return super if pagy_skip_jsonapi?(vars)
return 1 if params[:page].nil?

((params[:page].is_a?(Hash) && params[:page][vars[:page_param] || DEFAULT[:page_param]]) || 1).to_i
params[:page][vars[:page_param] || DEFAULT[:page_param]].to_i
end
end
Backend.prepend BackendOverride

# Module overriding ItemsExtra
module ItemsExtraOverride
private

# Override the ItemsExtra::Backend method
def pagy_get_items_size(vars)
return super if pagy_skip_jsonapi?(vars)
# Override the ItemsExtra::Backend method
def pagy_get_items_size(vars)
return super if pagy_skip_jsonapi?(vars)
return if params[:page].nil?

params[:page][vars[:items_param] || DEFAULT[:items_param]] if params[:page].is_a?(Hash)
params[:page][vars[:items_param] || DEFAULT[:items_param]]
end
end
# Swap the next lines in ruby 3.0+ baseline
# ItemsExtra::Backend.prepend ItemsExtraOverride if defined?(ItemsExtra::Backend)
Backend.prepend ItemsExtraOverride if defined?(ItemsExtra::Backend)

# Override UrlHelper method
def pagy_set_query_params(page, vars, params)
return super unless vars[:jsonapi]
# Module overriding UrlHelper
module UrlHelperOverride
# Override UrlHelper method
def pagy_set_query_params(page, vars, params)
return super unless vars[:jsonapi]

params['page'] ||= {}
params['page'][vars[:page_param].to_s] = page
params['page'][vars[:items_param].to_s] = vars[:items] if vars[:items_extra]
params['page'] ||= {}
params['page'][vars[:page_param].to_s] = page
params['page'][vars[:items_param].to_s] = vars[:items] if vars[:items_extra]
end
end
# Swap the next lines in ruby 3.0+ baseline
UrlHelpers.prepend UrlHelperOverride
# Backend.prepend UrlHelperOverride
# Frontend.prepend UrlHelperOverride
end
Backend.prepend JsonApiExtra
end
2 changes: 1 addition & 1 deletion retype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url: https://ddnexus.github.io/pagy

branding:
title: Pagy
label: 6.4.1
label: 6.4.2
colors:
label:
text: "#FFFFFF"
Expand Down
2 changes: 1 addition & 1 deletion src/pagy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Pagy = (() => {

// Public interface
return {
version: "6.4.1",
version: "6.4.2",

// Scan for elements with a "data-pagy" attribute and call their init functions with the decoded args
init(arg?:Element|never) {
Expand Down

0 comments on commit 25fe110

Please sign in to comment.