Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 10, 2021
2 parents c178c6f + 6ba1d6e commit 45e8769
Show file tree
Hide file tree
Showing 82 changed files with 950 additions and 763 deletions.
26 changes: 20 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,38 @@ require:
- rubocop-rake
- rubocop-minitest

# trying to be good O:)
AllCops:
TargetRubyVersion: 3.0
NewCops: enable

# No, thank you!
Layout:
Enabled: false

# affect performance
Metrics:
Enabled: false

Style:
# not cool
Style/CommentedKeyword:
Enabled: false

Bundler/OrderedGems:
Style/EmptyCaseCondition:
Enabled: false
Style/Documentation:
Enabled: false

Lint/RaiseException:
# these cops are disabled only in the test files in order to
# allow to copy and paste the failed output for test reconciliation
Style/StringLiterals:
Enabled: true

Lint/StructNewOverride:
Exclude:
- test/**/*
Style/HashSyntax:
Enabled: true
Exclude:
- test/**/*
Style/SymbolArray:
Enabled: true
Exclude:
- test/**/*
17 changes: 11 additions & 6 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
if ENV['RUN_SIMPLECOV'] == 'true'
SimpleCov.command_name 'main'
SimpleCov.start do
add_filter %r{^/test/}
add_group 'Core', %w[lib/pagy.rb lib/pagy/backend.rb lib/pagy/frontend.rb ]
add_group 'Extras', %w[lib/pagy/countless.rb lib/pagy/extras]
SimpleCov.start do
if ENV['RUN_CODECOV'] == 'true'
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
elsif ENV['SILENT_SIMPLECOV'] == 'true'
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
end
SimpleCov.command_name "Task##{$PROCESS_ID}"
SimpleCov.merge_timeout 20
add_group 'Core', %w[lib/pagy.rb lib/pagy/countless.rb lib/pagy/backend.rb lib/pagy/frontend.rb lib/pagy/exceptions.rb]
add_group 'Extras', 'lib/pagy/extras'
add_group 'Tests', 'test'
end
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ matrix:
- rvm: 3.0
gemfile: ci-gemfiles/ruby-3.0
env:
- ENABLE_OJ=true
- RUN_SIMPLECOV=true
- RUN_RUBOCOP=true
- RUN_CODECOV=true
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
# CHANGELOG

## Version 4.2.0

### Changes

- Fix for `Pagy::Frontend::I18n` conflicting with rthe `I18n` gem namespace after inclusion and safer renaming of other modules
- Fix the simplecov setup reporting less coverage than what's actually covered
- Updated Tailwind styles
- Included the test dir in the coverage check, refactoring and additions of tests
- Big code restyling following ruby 3.0 syntax and cops; tried to make the code simpler, more readable and verbose with almost negligible performance loss.

### Commits

- [a62ae94](http://github.com/ddnexus/pagy/commit/a62ae94): Updated README
- [9efb908](http://github.com/ddnexus/pagy/commit/9efb908): removed ENABLE_OJ from tests and travis config
- [dede255](http://github.com/ddnexus/pagy/commit/dede255): removed RUN_SIMPLECOV option
- [fc614bd](http://github.com/ddnexus/pagy/commit/fc614bd): fix/refactoring for simplecov setup reporting less coverage than what's actually covered
- [5e6ecf1](http://github.com/ddnexus/pagy/commit/5e6ecf1): refactoring of Rakefile
- [aea25a1](http://github.com/ddnexus/pagy/commit/aea25a1): code-restyling: test
- [cb67353](http://github.com/ddnexus/pagy/commit/cb67353): code-restyling: extras
- [b2dc35a](http://github.com/ddnexus/pagy/commit/b2dc35a): code-restyling: locales, config
- [b638764](http://github.com/ddnexus/pagy/commit/b638764): code-restyling: root files and Pagy Core
- [aac54aa](http://github.com/ddnexus/pagy/commit/aac54aa): Renaming prepended modules with more specific and safe naming convention (see Issue #290 PR #293)
- [3eef450](http://github.com/ddnexus/pagy/commit/3eef450): Simpler test for I18n namespace conflict
- [b2aaa01](http://github.com/ddnexus/pagy/commit/b2aaa01): README: fix typo (#289) [ci-skip]
- [3a9e70f](http://github.com/ddnexus/pagy/commit/3a9e70f): Fix extra i18n namespacing (#293)* Add a test that looks at i18n working in Modules included (fixes #290)
- [8cd25d2](http://github.com/ddnexus/pagy/commit/8cd25d2): renamed docker > pagy-on-docker
- [a8060b1](http://github.com/ddnexus/pagy/commit/a8060b1): fixed doc typos
- [f0e0d41](http://github.com/ddnexus/pagy/commit/f0e0d41): removed require for minitest/reporters
- [c178c6f](http://github.com/ddnexus/pagy/commit/c178c6f): docker README fixes [ci-skip]
- [ac988fd](http://github.com/ddnexus/pagy/commit/ac988fd): docs fixes
- [4d20d34](http://github.com/ddnexus/pagy/commit/4d20d34): Update Tailwind styles (#285)
- [9a14400](http://github.com/ddnexus/pagy/commit/9a14400): Small README addition [ci-skip]
- [9b40cdd](http://github.com/ddnexus/pagy/commit/9b40cdd): Update frontend.md (#284) [ci-skip]
- [2bbf204](http://github.com/ddnexus/pagy/commit/2bbf204): added Mike Rogers' screencast [ci-skip]
- [b24b86d](http://github.com/ddnexus/pagy/commit/b24b86d): Added note for brakeman false positive warnings (closes #243) [ci-skip]
- [df3c8d6](http://github.com/ddnexus/pagy/commit/df3c8d6): small syntax normalization
- [618d226](http://github.com/ddnexus/pagy/commit/618d226): docker README fix [ci-skip]

## Version 4.1.0

### Changes
Expand Down
16 changes: 7 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
source "https://rubygems.org"

gemspec
# gemspec

gem 'rake'
gem 'rack'
gem 'i18n'

gem 'oj', require: false # false is for testing with or without it
gem 'rack'
gem 'rake'

gem 'puma'

group :test do
gem 'codecov', require: false
gem 'minitest'
gem 'minitest-reporters'
gem 'rubocop', '~> 1.11', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'rubocop-minitest', require: false
gem 'simplecov', require: false
gem 'codecov', require: false
gem 'minitest'
gem 'minitest-reporters'
end
end

group :apps do
gem 'sinatra'
Expand All @@ -29,7 +28,6 @@ group :apps do
end

group :performance do
#benchmark/profiling
gem 'benchmark-ips'
gem 'kalibera'
gem 'memory_profiler'
Expand Down
6 changes: 0 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
PATH
remote: .
specs:
pagy (4.1.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -97,7 +92,6 @@ DEPENDENCIES
minitest
minitest-reporters
oj
pagy!
puma
rack
rake
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Pagy is the ultimate pagination gem that outperforms the others in each and ever
## New in 4.0+

- __This version requires `ruby 3.0+`. For `ruby <3.0` use `pagy <4.0` (see the [pagy3 branch](https://github.com/ddnexus/pagy/tree/pagy3))__
- Updating `pagy` from `3.0+` to `4.0+` require a single renaming in your code, but only if it uses the `searchkick` or the `elasticsearch_rails` extras (see the [Changelog](https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md))
- Updating `pagy` from `3.0+` to `4.0+` requires a single renaming in your code, but only if it uses the `searchkick` or the `elasticsearch_rails` extras (see the [Changelog](https://github.com/ddnexus/pagy/blob/master/CHANGELOG.md))
- Added the docker development environment to ease contributions
- Big code restyling following ruby 3.0 syntax and cops; tried to make the code simpler, more readable and verbose with almost negligible performance loss.

## Comparison with other gems

Expand Down Expand Up @@ -49,7 +50,7 @@ _The [IPS/Kb ratio](http://ddnexus.github.io/pagination-comparison/gems.html#eff

### Straightforward Code

- Pagy has a very slim core code of just ~100 lines of simple ruby, organized in 3 flat modules, very easy to understand and use _(see [more...](https://ddnexus.github.io/pagy/api))_
- Pagy has a very slim core code of just above 100 lines of simple ruby, organized in 3 flat modules, very easy to understand and use _(see [more...](https://ddnexus.github.io/pagy/api))_
- It has a quite fat set of optional extras that you can explicitly require for very efficient and modular customization _(see [extras](https://ddnexus.github.io/pagy/extras))_
- It has no dependencies: it produces its own HTML, URLs, i18n with its own specialized and fast code _(see [why...](https://ddnexus.github.io/pagy/index#specialized-code-instead-of-generic-helpers))_
- 100% of its methods are public API, accessible and overridable **right where you use them** (no pesky monkey-patching needed)
Expand Down Expand Up @@ -137,7 +138,7 @@ Besides the classic pagination offered by the `pagy_nav` helpers, you can use a

### Related Projects

- [pagy-cursor](https://github.com/Uysim/pagy-cursor) An early stage proget that implements cursor pagination for AR
- [pagy-cursor](https://github.com/Uysim/pagy-cursor) An early stage project that implements cursor pagination for AR

## Resources

Expand Down
126 changes: 39 additions & 87 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,99 +1,51 @@
# encoding: utf-8
# frozen_string_literal: true

require "bundler/setup"
require "bundler/gem_tasks"
require "rake/testtask"
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake/testtask'

# The extras that override the built-in methods need to be tested in isolation in order
# to prevent them to change also the behavior and the result of the built-in tests.
# We exclude them from the :test_main task and create a new task for them, then added to the :default task

Rake::TestTask.new(:test_main) do |t|
t.libs += %w[test lib]
t.test_files = FileList.new.include("test/**/*_test.rb")
.exclude('test/**/items_and_countless_test.rb',
'test/**/items_and_elasticsearch_test.rb',
'test/**/headers_test.rb',
'test/**/i18n_test.rb',
'test/**/overflow_test.rb',
'test/**/trim_test.rb',
'test/**/elasticsearch_rails_test.rb',
'test/**/searchkick_test.rb',
'test/**/support_test.rb',
'test/**/shared_test.rb',
'test/**/shared_combo_test.rb')
end

Rake::TestTask.new(:test_extra_items_and_countless) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/items_and_countless_test.rb']
end

Rake::TestTask.new(:test_extra_items_and_elasticsearch) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/items_and_elasticsearch_test.rb']
end

Rake::TestTask.new(:test_extra_headers) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/headers_test.rb']
end

Rake::TestTask.new(:test_extra_i18n) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/i18n_test.rb']
end

Rake::TestTask.new(:test_extra_overflow) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/overflow_test.rb']
end

Rake::TestTask.new(:test_extra_trim) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/trim_test.rb']
end

Rake::TestTask.new(:test_extra_elasticsearch) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/elasticsearch_rails_test.rb', 'test/**/searchkick_test.rb']
end

Rake::TestTask.new(:test_support) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/support_test.rb']
# We create a single task for each of them
@test_tasks = {}

def define_test_task(name, *files)
@test_tasks[name] = files
Rake::TestTask.new(name) do |t|
t.libs += %w[test lib]
t.test_files = FileList[*files]
end
end

Rake::TestTask.new(:test_shared) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/shared_test.rb']
end
define_test_task :test_extra_items_and_countless, 'test/**/items_and_countless_test.rb'
define_test_task :test_extra_items_and_elasticsearch, 'test/**/items_and_elasticsearch_test.rb'
define_test_task :test_extra_headers, 'test/**/headers_test.rb'
define_test_task :test_extra_i18n, 'test/**/i18n_test.rb'
define_test_task :test_extra_overflow, 'test/**/overflow_test.rb'
define_test_task :test_extra_trim, 'test/**/trim_test.rb'
define_test_task :test_extra_elasticsearch, 'test/**/elasticsearch_rails_test.rb', 'test/**/searchkick_test.rb'
define_test_task :test_support, 'test/**/support_test.rb'
define_test_task :test_shared,'test/**/oj_shared_test.rb'
define_test_task :test_shared,'test/**/shared_test.rb'
define_test_task :test_shared_items_trim, 'test/**/shared_items_trim_test.rb'

Rake::TestTask.new(:test_shared_combo) do |t|
# We exclude the files of the other tasks from the :test_main task
Rake::TestTask.new(:test_main) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/shared_combo_test.rb']
t.test_files = FileList.new
.include('test/**/*_test.rb')
.exclude(@test_tasks.values.flatten)
end

desc 'Run all the individual test tasks'
task test: [:test_main, *@test_tasks.keys]

task :test => [ :test_main,
:test_extra_items_and_countless,
:test_extra_items_and_elasticsearch,
:test_extra_headers,
:test_extra_i18n,
:test_extra_overflow,
:test_extra_trim,
:test_extra_elasticsearch,
:test_support,
:test_shared,
:test_shared_combo ]

if ENV['RUN_RUBOCOP'] == 'true'
require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = `git ls-files | grep -E '\\.rb$'`.split("\n") # limit rubocop to the files in the repo
end
task :default => [:test, :rubocop]
else
task :default => [:test]
end
task default: (if ENV['RUN_RUBOCOP'] == 'true'
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = `git ls-files | grep -E '\\.rb$'`.split("\n") # limit rubocop to the files in the repo
end
%i[test rubocop]
else
[:test]
end)
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: API
---
# API

The whole core structure of Pagy is very simple: it is organized around 3 small files of just ~100 lines of code in total:
The whole core structure of Pagy is very simple: it is organized around 3 small files of just above 100 lines of code in total:

| File | Description |
|:-------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion docs/api/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

All the methods in this module are prefixed with the `"pagy_"` string, to avoid any possible conflict with your own methods when you include the module in your controller. They are also all private, so they will not be available as actions. The methods prefixed with the `"pagy_get_"` string are sub-methods/getter methods that are intended to be overridden, not used directly.

Please, keep in mind that overriding any method is very easy with Pagy. Indeed you can do it right where you are using it: no need of monkey-patching or perform any tricky gymnic.
Please, keep in mind that overriding any method is very easy with Pagy. Indeed you can do it right where you are using it: no need of monkey-patching or perform any tricky gymmickry.

### pagy(collection, vars=nil)

Expand Down
2 changes: 1 addition & 1 deletion docs/api/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use some of its method in some view:

All the methods in this module are prefixed with the `"pagy_"` string in order to avoid any possible conflict with your own methods when you include the module in your helper. The methods prefixed with the `"pagy_get_"` string are sub-methods/getter methods that are intended to be overridden and not used directly.

Please, keep in mind that overriding any method is very easy with Pagy. Indeed you can do it right where you are using it: no need of monkey-patching or tricky gymnic.
Please, keep in mind that overriding any method is very easy with Pagy. Indeed you can do it right where you are using it: no need of monkey-patching or tricky gymmickry.

### pagy_nav(pagy)

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Basically, a pagination gem needs to calculate a series of 10-20 sequencial inte

Pagy keeps pagination as straightforward as it could be: there are no "declarative DSL" to learn, no "global pollution" to avoid, no need for any special module or adapter. There are no nested modules, classes nor countless methods and many hundreds lines of code... all really difficult to justify for such a simple task.

Including all the features, validations, exceptions, etc., the Pagy core code is just 3 small files of just ~100 lines in total, easy to understand and use. Just take a look at the source: [pagy.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy.rb), [pagy/backend.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/backend.rb), [pagy/frontend.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/frontend.rb) .
Including all the features, validations, exceptions, etc., the Pagy core code is just 3 small files of just above 100 lines in total, easy to understand and use. Just take a look at the source: [pagy.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy.rb), [pagy/backend.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/backend.rb), [pagy/frontend.rb](https://github.com/ddnexus/pagy/blob/master/lib/pagy/frontend.rb) .

Its size and simplicity is one of the reasons of its stunning performance.

Expand Down Expand Up @@ -41,6 +41,6 @@ You could even use it directly (without using any other Pagy code) in a small pa

## Really easy to customize

If options and configuration are not enough, you have a few specialized [extras](extras.md), and if all that is still not enough, any other special customization is at most _one step far_ from your own code. All the Pagy helpers are contained in 2 plain modules with no nesting. You include them in your code, so you can override any method right where you use it: no tricky gymnic required.
If options and configuration are not enough, you have a few specialized [extras](extras.md), and if all that is still not enough, any other special customization is at most _one step far_ from your own code. All the Pagy helpers are contained in 2 plain modules with no nesting. You include them in your code, so you can override any method right where you use it: no tricky gymmickry required.

What could be easier?
3 changes: 1 addition & 2 deletions lib/config/pagy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
# frozen_string_literal: true

# Pagy initializer file (4.1.0)
# Pagy initializer file (4.2.0)
# Customize only what you really need and notice that 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

0 comments on commit 45e8769

Please sign in to comment.