tiny_paginate 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/MIT-LICENSE +20 -0
- data/README.md +70 -0
- data/Rakefile +3 -0
- data/lib/generators/tiny_paginate/install_generator.rb +15 -0
- data/lib/generators/tiny_paginate/templates/navigation_partial.erb.html +5 -0
- data/lib/tasks/tiny_paginate_tasks.rake +4 -0
- data/lib/tiny_paginate/controller_helper_methods.rb +13 -0
- data/lib/tiny_paginate/page.rb +36 -0
- data/lib/tiny_paginate/railtie.rb +20 -0
- data/lib/tiny_paginate/version.rb +3 -0
- data/lib/tiny_paginate.rb +8 -0
- metadata +112 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e6b2caec64c2c5c746781cbc9e57bfac292c34545568337a420822a3a295da1f
|
|
4
|
+
data.tar.gz: 83d07ec849f9ccddcb4b383e5e9b52caefde77f4b694857d7ade9764842bf729
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b8ccb5e57cc60d4d7359b8967288aec7c7d2aca5796b28b030c1fc2073979471c36921003e6456b422f59e07ca43ad62800c37e8717e7ea4ee3d6835ac005553
|
|
7
|
+
data.tar.gz: c756481b59e8504ac5570b8648154725a73d8214ef171df224beede9d8114b8955daa2cf9692d29605762048652020b97120c06cb5c50695b1cbb46e54f1f79d
|
data/CHANGELOG.md
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright Enow Mbi
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# tiny\_paginate
|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
tiny_paginate is a lightweight and easy-to-use pagination gem for Ruby on Rails. Designed for simplicity and minimal overhead, it provides basic pagination functionality with clean helpers and minimal configuration—perfect for small projects or developers who want to avoid the complexity of larger pagination libraries.
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
`tiny_paginate` is simple to use. Follow the steps below to install and use it.
|
|
8
|
+
|
|
9
|
+
### Installation
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem "tiny_paginate"
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
And then execute:
|
|
17
|
+
```bash
|
|
18
|
+
$ bundle
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or install it yourself as:
|
|
22
|
+
```bash
|
|
23
|
+
$ gem install tiny_paginate
|
|
24
|
+
```
|
|
25
|
+
To work with this gem in your application, execute the following command:
|
|
26
|
+
```bash
|
|
27
|
+
$ rails g tiny_paginate:install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Modify controller
|
|
31
|
+
Here, we'll add the following line to setup page instance variable and extract portion of the records:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
@recordings = set_page_and_extract_portion_from(collection: Recording.all)
|
|
35
|
+
```
|
|
36
|
+
`set_page_and_extract_partion` returns records and also @page instance variable which is available to the views
|
|
37
|
+
|
|
38
|
+
#### Modify the view
|
|
39
|
+
In the page where you want to display the records, paste the following entries, assumming that you have a model called recording:
|
|
40
|
+
```
|
|
41
|
+
<p>
|
|
42
|
+
<%= link_to("Previous Page", recordings_path(page: @page.previous_page)) unless @page.first_page? %>
|
|
43
|
+
<%= link_to("Next Page", recordings_path(page: @page.next_page)) unless @page.last_page? %>
|
|
44
|
+
</p>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Change settings
|
|
48
|
+
Upon installation, a tiny_paginate.rb file is created with a single configuration option: `max_records_per_page`, which defaults to 30. You can easily modify this value to suit the needs of your application.
|
|
49
|
+
|
|
50
|
+
### Update
|
|
51
|
+
After installation, you can use the most recent version of `tiny_paginate` by running the following commands:
|
|
52
|
+
```bash
|
|
53
|
+
$ bundle update --conservative tiny_paginate
|
|
54
|
+
```
|
|
55
|
+
and then execute:
|
|
56
|
+
```bash
|
|
57
|
+
$ rails g tiny_paginate:install
|
|
58
|
+
```
|
|
59
|
+
Continue to update the controller and view if you've not done so already.
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## Contributing
|
|
63
|
+
* Close the Repo
|
|
64
|
+
* Create a branch with the changes you desire
|
|
65
|
+
* Create a PR against the main branch
|
|
66
|
+
|
|
67
|
+
PR will be approved and merged upon review by the repo gem owner.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "rails/generators"
|
|
2
|
+
|
|
3
|
+
module TinyPaginate
|
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
|
5
|
+
def install
|
|
6
|
+
initializer("tiny_paginate.rb") do
|
|
7
|
+
<<-RUBY
|
|
8
|
+
# frozen_string_literal: true
|
|
9
|
+
|
|
10
|
+
# TinyPaginate.max_records_per_page = 30 # uncomment to change(default = 30)
|
|
11
|
+
RUBY
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module TinyPaginate
|
|
2
|
+
module ControllerHelperMethods
|
|
3
|
+
private
|
|
4
|
+
def set_page_and_extract_portion_from(collection:)
|
|
5
|
+
@page = TinyPaginate::Page.new(page_number: page_number_param, collection: collection)
|
|
6
|
+
@page.records
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def page_number_param
|
|
10
|
+
params[:page].to_i > 0 ? params[:page].to_i : 1
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module TinyPaginate
|
|
2
|
+
class Page
|
|
3
|
+
attr_accessor :page_number, :collection
|
|
4
|
+
|
|
5
|
+
def initialize(page_number:, collection:)
|
|
6
|
+
@page_number = page_number
|
|
7
|
+
@collection = collection
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def records
|
|
11
|
+
collection.offset(offset).limit(TinyPaginate.max_records_per_page)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def next_page
|
|
15
|
+
page_number + 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def previous_page
|
|
19
|
+
page_number - 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def first_page?
|
|
23
|
+
page_number == 1
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def last_page?
|
|
27
|
+
page_number >= (collection.length.to_f / TinyPaginate.max_records_per_page).ceil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def offset
|
|
33
|
+
TinyPaginate.max_records_per_page * (page_number - 1)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module TinyPaginate
|
|
2
|
+
class Railtie < ::Rails::Railtie
|
|
3
|
+
initializer "tiny_paginate.controller_helper_methods" do
|
|
4
|
+
ActiveSupport.on_load(:action_controller_base) do
|
|
5
|
+
include TinyPaginate::ControllerHelperMethods
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# if defined?(FactoryBotRails)
|
|
10
|
+
# config.factory_bot.definition_file_paths +=
|
|
11
|
+
# [ File.expand_path("spec/factories", __dir__) ]
|
|
12
|
+
# end
|
|
13
|
+
|
|
14
|
+
# config.generators do |g|
|
|
15
|
+
# g.test_framework :rspec
|
|
16
|
+
# g.fixture_replacement :factory_bot
|
|
17
|
+
# g.factory_bot dir: "spec/factories"
|
|
18
|
+
# end
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tiny_paginate
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Enow Mbi
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 8.0.3
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 8.0.3
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: simplecov
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.22.0
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.22.0
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: rspec-rails
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 8.0.2
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 8.0.2
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: factory_bot_rails
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 6.5.1
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 6.5.1
|
|
68
|
+
description: Simple pagination plugin
|
|
69
|
+
email:
|
|
70
|
+
- benowmbi@yahoo.com
|
|
71
|
+
executables: []
|
|
72
|
+
extensions: []
|
|
73
|
+
extra_rdoc_files: []
|
|
74
|
+
files:
|
|
75
|
+
- CHANGELOG.md
|
|
76
|
+
- MIT-LICENSE
|
|
77
|
+
- README.md
|
|
78
|
+
- Rakefile
|
|
79
|
+
- lib/generators/tiny_paginate/install_generator.rb
|
|
80
|
+
- lib/generators/tiny_paginate/templates/navigation_partial.erb.html
|
|
81
|
+
- lib/tasks/tiny_paginate_tasks.rake
|
|
82
|
+
- lib/tiny_paginate.rb
|
|
83
|
+
- lib/tiny_paginate/controller_helper_methods.rb
|
|
84
|
+
- lib/tiny_paginate/page.rb
|
|
85
|
+
- lib/tiny_paginate/railtie.rb
|
|
86
|
+
- lib/tiny_paginate/version.rb
|
|
87
|
+
homepage: https://github.com/enowmbi/tiny_paginate
|
|
88
|
+
licenses:
|
|
89
|
+
- MIT
|
|
90
|
+
metadata:
|
|
91
|
+
allowed_push_host: https://rubygems.org
|
|
92
|
+
homepage_uri: https://github.com/enowmbi/tiny_paginate
|
|
93
|
+
source_code_uri: https://github.com/enowmbi/tiny_paginate
|
|
94
|
+
changelog_uri: https://github.com/enowmbi/tiny_paginate/CHANGELOG.md
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubygems_version: 3.7.1
|
|
110
|
+
specification_version: 4
|
|
111
|
+
summary: Simple pagination plugin
|
|
112
|
+
test_files: []
|