Skip to content

Commit

Permalink
Merge branch 'backport-to-2.5' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 8, 2021
2 parents 934f602 + 001f22f commit b5b500a
Show file tree
Hide file tree
Showing 39 changed files with 224 additions and 34 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/pagy-ci.yml
Expand Up @@ -33,6 +33,15 @@ jobs:
strategy:
matrix:
include:
- ruby-version: 2.5
env:
NONE: true
- ruby-version: 2.6
env:
NONE: true
- ruby-version: 2.7
env:
NONE: true
- ruby-version: 3.0
env:
CODECOV: true
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -6,7 +6,7 @@ require:

# trying to be good O:)
AllCops:
TargetRubyVersion: 3.0.1
TargetRubyVersion: 2.5
NewCops: enable
Exclude:
- ___*/**/* # '___' prefixed dirs are excluded
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Expand Up @@ -10,7 +10,7 @@ GEM
benchmark-ips (2.9.1)
codecov (0.5.2)
simplecov (>= 0.15, < 0.22)
concurrent-ruby (1.1.8)
concurrent-ruby (1.1.9)
docile (1.4.0)
ffi (1.15.1)
i18n (1.8.10)
Expand Down Expand Up @@ -45,7 +45,7 @@ GEM
ffi (~> 1.0)
rbzip2 (0.2.0)
regexp_parser (2.1.1)
rematch (1.3.0)
rematch (1.3.1)
rerun (0.13.1)
listen (~> 3.0)
rexml (3.2.5)
Expand Down
2 changes: 1 addition & 1 deletion apps/pagy_standalone_app.ru
Expand Up @@ -70,7 +70,7 @@ class MockCollection < Array
@collection = clone
end
def offset(value)
@collection = self[value..]
@collection = self[value..-1]
self
end
def limit(value)
Expand Down
4 changes: 3 additions & 1 deletion lib/pagy/exceptions.rb
Expand Up @@ -16,7 +16,9 @@ def variable
Regexp.last_match(1)&.to_sym
end

def value = pagy.vars[variable]
def value
pagy.vars[variable]
end
end

# specific overflow error
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/bulma.rb
Expand Up @@ -66,7 +66,7 @@ def pagy_bulma_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '
private

def pagy_bulma_prev_next_html(pagy, link)
html = if (p_prev = pagy.prev)
html = +if (p_prev = pagy.prev)
link.call p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"'
else
%(<a class="pagination-previous" disabled>#{pagy_t 'pagy.nav.prev'}</a>)
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/headers.rb
Expand Up @@ -25,10 +25,10 @@ def pagy_headers_hash(pagy)
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
rels['last'] = pagy.last unless countless
url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: true)
hash = { 'Link' => rels.filter_map do |rel, num|
hash = { 'Link' => rels.map do |rel, num| # filter_map if ruby >=2.7
next unless num
[ rel, url_str.sub(PAGE_PLACEHOLDER, num.to_s) ]
end.to_h }
end.compact.to_h }
headers = pagy.vars[:headers]
hash[headers[:page]] = pagy.page.to_s if headers[:page]
hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
Expand Down
4 changes: 3 additions & 1 deletion lib/pagy/extras/i18n.rb
Expand Up @@ -14,7 +14,9 @@ module Frontend
end

module UseI18nGem
def pagy_t(key, **opts) = ::I18n.t(key, **opts)
def pagy_t(key, **opts)
::I18n.t(key, **opts)
end
end
prepend UseI18nGem

Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/items.rb
Expand Up @@ -40,7 +40,7 @@ def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil
link = pagy_marked_link(pagy_link_proc(pagy, link_extra: link_extra))
p_vars[:items] = p_items # restore the items

html = %(<span#{p_id} class="pagy-items-selector-js" #{pagy_json_attr pagy, :items_selector, pagy.from, link}>)
html = +%(<span#{p_id} class="pagy-items-selector-js" #{pagy_json_attr pagy, :items_selector, pagy.from, link}>)
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
items_input: input,
Expand Down
4 changes: 3 additions & 1 deletion lib/pagy/extras/overflow.rb
Expand Up @@ -6,7 +6,9 @@ class Pagy
module UseOverflowExtra
VARS[:overflow] = :empty_page

def overflow? = @overflow
def overflow?
@overflow
end

def initialize(vars)
@overflow ||= false # don't override if :last_page re-run the method after an overflow
Expand Down
6 changes: 5 additions & 1 deletion lib/pagy/extras/standalone.rb
Expand Up @@ -46,7 +46,11 @@ def pagy_url_for(pagy, page, deprecated_url=nil, absolute: nil)
"#{url_string}#{query_string}#{p_vars[:fragment]}"
end
end
Helpers.prepend UseStandaloneExtra

# single line in order to avoid complicating simplecov already tested with other GitHub Actions
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0') \
&& Helpers.prepend(UseStandaloneExtra) \
|| ( Frontend.prepend(UseStandaloneExtra); Backend.prepend(UseStandaloneExtra) if defined?(Pagy::Backend::METADATA) ) # rubocop:disable Style/Semicolon

# defines a dummy #params method if not already defined in the including module
module Backend
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/trim.rb
Expand Up @@ -12,7 +12,7 @@ def pagy_link_proc(pagy, deprecated_link_extra=nil, link_extra: '')
link_proc = super(pagy, link_extra: link_extra)
return link_proc unless pagy.vars[:enable_trim_extra]
lambda do |num, text=num, extra=''|
link = link_proc.call(num, text, extra)
link = +link_proc.call(num, text, extra)
return link unless num == 1
link.sub!(/[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/, '')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/uikit.rb
Expand Up @@ -11,7 +11,7 @@ def pagy_uikit_nav(pagy, pagy_id: nil, link_extra: '')
p_id = %( id="#{pagy_id}") if pagy_id
link = pagy_link_proc(pagy, link_extra: link_extra)

html = %(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
html = +%(<ul#{p_id} class="pagy-uikit-nav uk-pagination uk-flex-center">#{pagy_uikit_prev_html pagy, link})
pagy.series.each do |item|
html << case item
when Integer then %(<li>#{link.call item}</li>)
Expand Down
4 changes: 3 additions & 1 deletion lib/pagy/frontend.rb
Expand Up @@ -25,7 +25,9 @@ def pagy_url_for(pagy, page, deprecated_url=nil, absolute: nil)
end

# Sub-method called only by #pagy_url_for: here for easy customization of params by overriding
def pagy_get_params(params) = params
def pagy_get_params(params)
params
end
end

# All the code here has been optimized for performance: it may not look very pretty
Expand Down
103 changes: 103 additions & 0 deletions pagy-on-docker/docker-compose-backport.yml
@@ -0,0 +1,103 @@
# Basic pagy-on-docker development environment
# it will keep the installed gems and HOME in the pagy_bundle and pagy_user_home pagy-on-docker volumes
# the pagy-jekill service will be updating a live preview for the docs

# USAGE
# cd pagy-on-docker
# docker-compose up pagy # only pagy service (running ruby development and test environment)
# docker-compose up pagy-jekyll # pagy and pagy-jekyll services (add the docs live site)
# docker-compose up pagy-cyress # pagy and pagy-cyress services (run the e2e tests and exit)

version: "3.8"

services:

# ruby dev and test pagy development
# It also runs a minimal sinatra app at http://0.0.0.0:8080
pagy:
image: pagy:4-backport
build:
context: .
dockerfile: pagy-backport.dockerfile
# set env variables with your user info
args:
user: $USER
group: $GROUP
uid: $UID
gid: $GID
password: "${PASSWORD:-rubydev}"
term: ${TERM:-xterm-256color}
container_name: pagy
volumes:
- ../.:/opt/project
- bundle:/usr/local/bundle
- user_home:/home/$USER
environment:
- COVERAGE_REPORT
stdin_open: true
tty: true

# Serve the docs site live at http://0.0.0.0:4000
# Use it to check/edit the rendered content in the docs dir
pagy-jekyll:
depends_on:
- pagy
image: pagy-jekyll:latest
build:
context: .
dockerfile: pagy-jekyll.dockerfile
container_name: pagy-jekyll
environment:
- JEKYLL_GITHUB_TOKEN
ports:
- "4000:4000"
- "35729:35729"
volumes:
- ../docs:/opt/docs
- docs_site:/opt/site
command: |
jekyll serve \
--incremental \
--livereload \
--watch \
--force-polling \
--host 0.0.0.0 \
--baseurl '' \
--source /opt/docs \
--destination /opt/site
stdin_open: true
tty: true

# you may want skip this service when you run the docker-compose.yml file
# and run it only on demand to run the tests and exit, or to interact with cypress
# using the additional open-cypress.yml (see the comments in the open-cypress.yml file)
# IMPORTANT: pick the build.dockerfile entry according to your UID
pagy-cypress:
depends_on:
- pagy
image: pagy-cypress:latest
build:
context: .
# switch between the following 2 lines if your user id is 1000 or not
dockerfile: pagy-cypress-uid1000.dockerfile
# dockerfile: pagy-cypress.dockerfile
args:
user: $USER
group: $GROUP
uid: $UID
gid: $GID
container_name: pagy-cypress
environment:
- CYPRESS_baseUrl=http://pagy:4567
working_dir: /test/e2e
volumes:
- ../test/e2e:/test/e2e

volumes:
bundle:
name: pagy_backport_bundle
user_home:
name: pagy_backport_user_home
docs_site:
name: pagy_docs_site

55 changes: 55 additions & 0 deletions pagy-on-docker/pagy-backport.dockerfile
@@ -0,0 +1,55 @@
FROM ruby:2.7

ARG term
ENV TERM="${term:-xterm-256color}"

# install required packages
RUN apt-get update && apt-get install -y locales \
&& sed -i 's/^# *\(en_US.UTF-8\)/\1/' /etc/locale.gen \
&& locale-gen \
&& apt-get install -y \
nodejs \
git \
nano

ARG user
ARG group
ARG uid
ARG gid
ARG password=rubydev

# setup users and .bashrc
# - same pasword for user and root
# - color prompt for user and root
RUN groupadd --gid=$gid --force $group \
&& useradd --uid=$uid --gid=$gid --shell=/bin/bash --create-home $user \
&& echo $user:$password | chpasswd \
&& echo root:$password | chpasswd \
&& sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/' /home/$user/.bashrc \
&& sed -i 's/\\u@\\h\\\[\\033\[00m\\\]:\\\[\\033\[01;34m\\\]\\w\\\[\\033\[00m\\\]/\\u \\\[\\033\[01;34m\\\]\\w\\\[\\033\[00m\\\] /' /home/$user/.bashrc \
&& cp /home/$user/.bashrc /root/.bashrc

ENV \
BUNDLE_PATH=/usr/local/bundle \
GEM_HOME=/usr/local/bundle \
BUNDLE_APP_CONFIG=/usr/local/bundle \
BUNDLE_BIN=/usr/local/bundle/bin \
BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_CACHE_ALL=1 \
LS_OPTIONS='--color=auto' \
EDITOR=nano \
TERM=${term:-xterm-256color} \
SHELL=/bin/bash \
LANG=en_US.UTF-8 \
LANGUAGE=en_US.UTF-8 \
LC_ALL=en_US.UTF-8

RUN chown -R $uid:$gid $BUNDLE_PATH

WORKDIR /opt/project

VOLUME \
/home/$user \
$BUNDLE_PATH

USER $user
2 changes: 1 addition & 1 deletion pagy.gemspec
Expand Up @@ -14,5 +14,5 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/ddnexus/pagy'
s.license = 'MIT'
s.files = File.read('pagy.manifest').split
s.required_ruby_version = '>= 3.0'
s.required_ruby_version = '>= 2.5'
end
2 changes: 1 addition & 1 deletion tasks/coverage_summary.rake
Expand Up @@ -4,7 +4,7 @@ require 'json'

desc 'Display SimpleCov coverage summary'
task :coverage_summary do
last_run = JSON.load_file('coverage/.last_run.json')
last_run = JSON.parse(File.read('coverage/.last_run.json'))
result = last_run['result']['line']
puts "\n>>> SimpleCov Coverage: #{result}% <<<"
if result < 100.0
Expand Down
2 changes: 1 addition & 1 deletion test/mock_helpers/collection.rb
Expand Up @@ -8,7 +8,7 @@ def initialize(arr=Array(1..1000))
end

def offset(value)
@collection = self[value..]
@collection = self[value..-1]
self
end

Expand Down
4 changes: 2 additions & 2 deletions test/mock_helpers/searchkick.rb
Expand Up @@ -33,8 +33,8 @@ def total_count

class Model

def self.search(...)
Results.new(...)
def self.search(*args, &block)
Results.new(*args, &block)
end

extend Pagy::Searchkick
Expand Down
3 changes: 2 additions & 1 deletion test/mock_helpers/view.rb
Expand Up @@ -17,7 +17,8 @@ def request

class Overridden < MockView
def pagy_get_params(params)
params.except(:a).merge!(k: 'k')
params.delete(:a)
params.merge!(k: 'k')
end
end
end
1 change: 1 addition & 0 deletions test/pagy/extras/bootstrap_test.rb
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/bootstrap'

describe 'pagy/extras/bootstrap' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_bootstrap_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/bulma_test.rb
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/bulma'

describe 'pagy/extras/bulma' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_bulma_nav' do
Expand Down
1 change: 1 addition & 0 deletions test/pagy/extras/foundation_test.rb
Expand Up @@ -4,6 +4,7 @@
require 'pagy/extras/foundation'

describe 'pagy/extras/foundation' do
require_relative '../../mock_helpers/view'
let(:view) { MockView.new }

describe '#pagy_foundation_nav' do
Expand Down

0 comments on commit b5b500a

Please sign in to comment.