pagers 3.1.5 → 4.0.0.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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +28 -15
- data/Rakefile +1 -16
- data/app/views/pagers/_main.html.erb +1 -1
- data/lib/generators/pagers/install/install_generator.rb +13 -0
- data/lib/generators/pagers/install/templates/initializer.rb +7 -0
- data/lib/pagers.rb +8 -13
- data/lib/pagers/configuration.rb +7 -0
- data/lib/pagers/extensions/action_view/base.rb +48 -0
- data/lib/pagers/extensions/active_record/base.rb +43 -0
- data/lib/pagers/extensions/active_record/relation.rb +43 -0
- data/lib/pagers/railtie.rb +7 -3
- data/lib/pagers/version.rb +1 -1
- data/test/dummy/Rakefile +1 -2
- data/test/dummy/app/assets/javascripts/application.js +2 -2
- data/test/dummy/app/assets/stylesheets/application.css +6 -4
- data/test/dummy/app/controllers/products_controller.rb +8 -0
- data/test/dummy/app/models/product.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/app/views/products/index.html.erb +1 -0
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +2 -1
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +3 -0
- data/test/dummy/config/boot.rb +1 -1
- data/test/dummy/config/database.yml +4 -22
- data/test/dummy/config/database.yml.travis +3 -0
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +15 -3
- data/test/dummy/config/environments/production.rb +21 -26
- data/test/dummy/config/environments/test.rb +10 -12
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/mime_types.rb +1 -2
- data/test/dummy/config/initializers/pagers.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/routes.rb +1 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20130820024335_create_products.rb +7 -0
- data/test/dummy/db/schema.rb +6 -4
- data/test/dummy/log/development.log +25 -0
- data/test/dummy/log/test.log +22127 -987
- data/test/dummy/public/404.html +58 -55
- data/test/dummy/public/422.html +58 -55
- data/test/dummy/public/500.html +57 -54
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/34/34l0xNON3WYrRP9HWkz5ZK9IQzIEVGYFn6VDMKiheeA.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/5L/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/OI/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/SG/SGNGr7AZfBE1q7ev2-YM1G-o0XAZ0pKqbsS3NvHtRcA.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/TO/TOCwj3wVkgMFleFRO8KMLE3Qq6FsXpCeZD56U1AEPEc.cache +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/YJ/YJjzVvL4dd5E1S5fIpCphDLf9mEWeGfhO-ALTZpJ8-c.cache +0 -0
- data/test/dummy/tmp/cache/{sprockets/v3.0/4qi4l6mZwh9hUfWOWITw6FuJ15NRpPcIgJ22C20Yrhw.cache → assets/sprockets/v3.0/fG/fG_uaNK13wisQiji91xNsGecGxX9QhMCF2eSX_aR0G0.cache} +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/gb/gbunrAFVOHPwl2npUgKv_C3f_qiJnZDd9zG5-h3jrpo.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/hZ/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/mv/mvqN6PphkrOOC8zbUEhpC_9E_4ybdO25MRy_gG6dq3Y.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/nm/nmcUZlKAIwyJ_35Nm9P8pukLeRX5aApP6NFj5MpNPgc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/pE/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
- data/test/dummy/tmp/cache/{sprockets/v3.0/IXhyhrFX9OAFbL6na95F8HncYlwJm9_DdZx3OGTlvjk.cache → assets/sprockets/v3.0/sB/sB6xWxBmgzVC0Co9__ANYrE58lr4WPwiwFa9mswooWM.cache} +0 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/va/vaNrIny9hchHD9eIJxAicyYLC7qeV4PTh4Nh40_Y6Vg.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/xd/xdBKQyhEAlDIstGvXw945PWJoEWi23rKuY7elOcWqHc.cache +1 -0
- data/test/dummy/tmp/cache/assets/sprockets/v3.0/yH/yHjEG5b89-DY37A9c_d90xiOarCQ4bJHa-i98W72DXI.cache +0 -0
- data/test/generator_test.rb +5 -5
- data/test/relation_test.rb +85 -0
- data/test/test_helper.rb +6 -13
- data/test/view_test.rb +47 -0
- metadata +75 -96
- data/lib/generators/pagers/install_generator.rb +0 -13
- data/lib/generators/pagers/templates/pagers.rb +0 -2
- data/lib/pagers/action_view/base.rb +0 -40
- data/lib/pagers/active_record/base.rb +0 -37
- data/lib/pagers/active_record/relation.rb +0 -41
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/app/controllers/pages_controller.rb +0 -7
- data/test/dummy/app/models/record.rb +0 -2
- data/test/dummy/app/views/pages/index.html.erb +0 -1
- data/test/dummy/config/initializers/secret_token.rb +0 -13
- data/test/dummy/db/migrate/20130820024335_create_records.rb +0 -9
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/4CacREYU-WtfLMBbdP-dhQGvv5x5m64f08AyEfpJQOo.cache +0 -1
- data/test/dummy/tmp/cache/sprockets/v3.0/92EHsdop8I2qLLTnyIPHKsBjC79WjGLaG37jVJyQVhk.cache +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/EWvcaZ9y1ATwOV77WPqF6MOVajQDzmhssysEljgt9Eo.cache +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/Ko7VnYzTp2dC_WWnmGeCA4HQFz0DP4BhGt3lwlHhHi8.cache +0 -1
- data/test/dummy/tmp/cache/sprockets/v3.0/LhsrcVSJd1rOgmBlzouy8hNPVwxmPKoQ-Gas3gSxTkI.cache +0 -1
- data/test/dummy/tmp/cache/sprockets/v3.0/V69Dt-aUrVqv_nmsS1zbhdjuZiJYjFhnrydvD2K2GUM.cache +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/_Ncty4f5wW4Cr2m5RgKKk4M1vjFREhRT4rNNa3xudJk.cache +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/aN14MzsGXl0Y-OLjTiDPq1Q4JIyN7HL8WxyvnCmR15s.cache +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/bK7xK7GDY9-6iymHURf47UyKHbhI_XkIoXheTZIkob8.cache +0 -1
- data/test/dummy/tmp/cache/sprockets/v3.0/hj8Ir9wcVSy1KYrnWu9bpD24vDhCG3tvt-nKbNxb1Wg.cache +0 -3
- data/test/dummy/tmp/cache/sprockets/v3.0/oCsZTGZyV4kH8Y4OeSDUdrwfkJFPzTODZjuBKZB8oGQ.cache +0 -2
- data/test/dummy/tmp/cache/sprockets/v3.0/pwlpdo053gu3Fg6oen1pnE9oV9ErbgrDW0VbKPLs098.cache +0 -0
- data/test/dummy/tmp/cache/sprockets/v3.0/q6BYa32YJF11eGVapO4ouNl6gayPIsARgMavlzZmoi0.cache +0 -3
- data/test/dummy/tmp/cache/sprockets/v3.0/x7KkTV3ibfIEysLB_ug5bfmnn2VLV_BldukPR3EoPBk.cache +0 -2
- data/test/empty_test.rb +0 -39
- data/test/first_test.rb +0 -43
- data/test/last_test.rb +0 -43
- data/test/middle_test.rb +0 -43
- data/test/padding_test.rb +0 -21
- data/test/route_test.rb +0 -69
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dfb6743176da1df0ec2e6260bd613767dc1838a5
|
|
4
|
+
data.tar.gz: 0db4191a5adc4f890dbeaa45c2784d761ff9da4d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f07d1fe0b714f634ee628e6a4857c8f54936979c527f44c18c0a3bd07b6a29f615511fdabbeff2286bbd8b78f12cb32212b9ff86f712f18db8f31dac57ca99c
|
|
7
|
+
data.tar.gz: 5e643b2c86deb135c728b16e459ac0c3d21471a4c26ecf27966b40c081a613d072cc3beca5c11530fc9cd9378e1023766383fa666479ad8ddbc4771ad720ae0d
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
# Pagers
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Scope based pagination engine for rails.
|
|
9
|
+
|
|
10
|
+
## Why
|
|
11
|
+
|
|
12
|
+
I did this gem to:
|
|
13
|
+
|
|
14
|
+
- Simplify code by keep close integration with rails.
|
|
15
|
+
- Have most common used settings set out of the box.
|
|
16
|
+
- Create a compatible pagination for [indexes gem](https://github.com/mmontossi/indexes).
|
|
9
17
|
|
|
10
18
|
## Install
|
|
11
19
|
|
|
@@ -23,48 +31,53 @@ $ bundle
|
|
|
23
31
|
|
|
24
32
|
Generate the configuration file:
|
|
25
33
|
```
|
|
26
|
-
rails g pagers:install
|
|
34
|
+
$ bundler exec rails g pagers:install
|
|
27
35
|
```
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
Set the global settings:
|
|
30
38
|
```ruby
|
|
31
39
|
Pagers.configure do |config|
|
|
40
|
+
|
|
32
41
|
config.length = 20
|
|
33
42
|
config.padding = 0
|
|
34
|
-
config.
|
|
35
|
-
|
|
43
|
+
config.links = 5
|
|
44
|
+
|
|
36
45
|
end
|
|
37
46
|
```
|
|
38
47
|
|
|
39
48
|
## Usage
|
|
40
49
|
|
|
50
|
+
### Relation
|
|
51
|
+
|
|
41
52
|
Call the page scope from your models:
|
|
42
53
|
```ruby
|
|
43
|
-
@
|
|
54
|
+
@products = Product.page(1)
|
|
44
55
|
```
|
|
45
56
|
|
|
46
|
-
|
|
57
|
+
You can override global options by passing a hash:
|
|
58
|
+
```ruby
|
|
59
|
+
@products = Product.page(1, length: 10, padding: 4)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Views
|
|
63
|
+
|
|
64
|
+
You can use paginate helper to generate a pager html:
|
|
47
65
|
```erb
|
|
48
66
|
<%= paginate @collection %>
|
|
49
67
|
```
|
|
50
68
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## SEO
|
|
69
|
+
### SEO
|
|
54
70
|
|
|
55
|
-
|
|
71
|
+
If you want to remove the page query parameter, add an optional parameter to the route:
|
|
56
72
|
```ruby
|
|
57
73
|
get 'search/:query/(:page)' => 'products#search'
|
|
58
74
|
```
|
|
59
75
|
|
|
60
|
-
|
|
76
|
+
That will produce links like this:
|
|
61
77
|
```
|
|
62
78
|
search/sample
|
|
63
79
|
search/sample/2
|
|
64
80
|
search/sample/3
|
|
65
|
-
.
|
|
66
|
-
.
|
|
67
|
-
.
|
|
68
81
|
```
|
|
69
82
|
|
|
70
83
|
## Credits
|
data/Rakefile
CHANGED
|
@@ -4,21 +4,6 @@ rescue LoadError
|
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
require 'rdoc/task'
|
|
8
|
-
|
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
-
rdoc.title = 'Pagers'
|
|
12
|
-
rdoc.options << '--line-numbers'
|
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
18
|
-
load 'rails/tasks/engine.rake'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
7
|
Bundler::GemHelper.install_tasks
|
|
23
8
|
|
|
24
9
|
require 'rake/testtask'
|
|
@@ -28,7 +13,7 @@ Rake::TestTask.new(:test) do |t|
|
|
|
28
13
|
t.libs << 'test'
|
|
29
14
|
t.pattern = 'test/**/*_test.rb'
|
|
30
15
|
t.verbose = false
|
|
16
|
+
t.warning = false
|
|
31
17
|
end
|
|
32
18
|
|
|
33
|
-
|
|
34
19
|
task default: :test
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
link_to(
|
|
20
20
|
page,
|
|
21
21
|
page_path(page, options),
|
|
22
|
-
rel: (collection.next_page == page ? 'next' : collection.previous_page == page ? 'prev' : nil)
|
|
22
|
+
rel: (collection.next_page == page ? 'next' : (collection.previous_page == page ? 'prev' : nil))
|
|
23
23
|
)
|
|
24
24
|
%>
|
|
25
25
|
</li>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module Pagers
|
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
5
|
+
|
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
7
|
+
|
|
8
|
+
def create_initializer_file
|
|
9
|
+
copy_file 'initializer.rb', 'config/initializers/pagers.rb'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/pagers.rb
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
require 'pagers/action_view/base'
|
|
2
|
-
require 'pagers/active_record/base'
|
|
3
|
-
require 'pagers/active_record/relation'
|
|
1
|
+
require 'pagers/extensions/action_view/base'
|
|
2
|
+
require 'pagers/extensions/active_record/base'
|
|
3
|
+
require 'pagers/extensions/active_record/relation'
|
|
4
|
+
require 'pagers/configuration'
|
|
4
5
|
require 'pagers/engine'
|
|
5
6
|
require 'pagers/railtie'
|
|
7
|
+
require 'pagers/version'
|
|
6
8
|
|
|
7
9
|
module Pagers
|
|
8
10
|
class << self
|
|
9
11
|
|
|
10
12
|
def configure
|
|
11
|
-
yield
|
|
13
|
+
yield configuration
|
|
12
14
|
end
|
|
13
15
|
|
|
14
|
-
def
|
|
15
|
-
@
|
|
16
|
-
ActiveSupport::OrderedOptions.new.tap do |config|
|
|
17
|
-
config.length = 20
|
|
18
|
-
config.padding = 0
|
|
19
|
-
config.parameter = :page
|
|
20
|
-
config.pages = 5
|
|
21
|
-
end
|
|
22
|
-
end
|
|
16
|
+
def configuration
|
|
17
|
+
@configuration ||= Configuration.new
|
|
23
18
|
end
|
|
24
19
|
|
|
25
20
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Pagers
|
|
2
|
+
module Extensions
|
|
3
|
+
module ActionView
|
|
4
|
+
module Base
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
def page_path(number, options={})
|
|
8
|
+
if number == 1
|
|
9
|
+
number = nil
|
|
10
|
+
end
|
|
11
|
+
url_for request.query_parameters.merge(page: number)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def paginate(collection, options={})
|
|
15
|
+
links = (options[:links] || Pagers.configuration.links)
|
|
16
|
+
if collection.total_pages >= links
|
|
17
|
+
middle = (links / 2).ceil
|
|
18
|
+
if collection.current_page > (collection.total_pages - middle)
|
|
19
|
+
starts_at = (collection.total_pages - links + 1)
|
|
20
|
+
ends_at = collection.total_pages
|
|
21
|
+
elsif collection.current_page <= middle
|
|
22
|
+
starts_at = 1
|
|
23
|
+
ends_at = links
|
|
24
|
+
else
|
|
25
|
+
starts_at = (collection.current_page - middle)
|
|
26
|
+
ends_at = (collection.current_page + middle)
|
|
27
|
+
end
|
|
28
|
+
else
|
|
29
|
+
starts_at = 1
|
|
30
|
+
ends_at = collection.total_pages
|
|
31
|
+
end
|
|
32
|
+
pages = Range.new(starts_at, ends_at)
|
|
33
|
+
less_pages = (starts_at > 1)
|
|
34
|
+
more_pages = (ends_at < collection.total_pages)
|
|
35
|
+
render(
|
|
36
|
+
'pagers/main',
|
|
37
|
+
collection: collection,
|
|
38
|
+
pages: pages,
|
|
39
|
+
less_pages: less_pages,
|
|
40
|
+
more_pages: more_pages,
|
|
41
|
+
options: options
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Pagers
|
|
2
|
+
module Extensions
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module Base
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
module ClassMethods
|
|
8
|
+
|
|
9
|
+
def inherited(subclass)
|
|
10
|
+
subclass.class_eval do
|
|
11
|
+
if superclass == ::ActiveRecord::Base
|
|
12
|
+
scope :page, ->(number, options={}) {
|
|
13
|
+
padding = (options[:padding] || Pagers.configuration.padding)
|
|
14
|
+
length = (options[:length] || Pagers.configuration.length)
|
|
15
|
+
current_page = [number.to_i, 1].max
|
|
16
|
+
limit = length
|
|
17
|
+
offset = ((length * (current_page - 1)) + padding)
|
|
18
|
+
values = Module.new do
|
|
19
|
+
define_method :padding do
|
|
20
|
+
padding
|
|
21
|
+
end
|
|
22
|
+
define_method :page_length do
|
|
23
|
+
length
|
|
24
|
+
end
|
|
25
|
+
define_method :current_page do
|
|
26
|
+
current_page
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
limit(limit).offset(offset).extending(
|
|
30
|
+
Pagers::Extensions::ActiveRecord::Relation,
|
|
31
|
+
values
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Pagers
|
|
2
|
+
module Extensions
|
|
3
|
+
module ActiveRecord
|
|
4
|
+
module Relation
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
def total_pages
|
|
8
|
+
@total_pages ||= [(total_count.to_f / page_length).ceil, 1].max
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def previous_page
|
|
12
|
+
@previous_page ||= (current_page > 1 ? (current_page - 1) : nil)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def next_page
|
|
16
|
+
@next_page ||= (current_page < total_pages ? (current_page + 1) : nil)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def first_page
|
|
20
|
+
1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def last_page
|
|
24
|
+
total_pages
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def out_of_bounds?
|
|
28
|
+
@out_of_bounds ||= (current_page > total_pages || current_page < first_page)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def total_count
|
|
32
|
+
@total_count ||= begin
|
|
33
|
+
r = except(:limit, :offset, :order)
|
|
34
|
+
r = r.except(:includes) unless references_eager_loaded_tables?
|
|
35
|
+
r = r.count
|
|
36
|
+
(r.respond_to?(:count) ? r.count : r) - padding
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/pagers/railtie.rb
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
module Pagers
|
|
2
2
|
class Railtie < Rails::Railtie
|
|
3
3
|
|
|
4
|
-
initializer 'pagers' do
|
|
5
|
-
::ActiveRecord::Base.
|
|
6
|
-
|
|
4
|
+
initializer 'pagers.extensions' do
|
|
5
|
+
::ActiveRecord::Base.include(
|
|
6
|
+
Pagers::Extensions::ActiveRecord::Base
|
|
7
|
+
)
|
|
8
|
+
::ActionView::Base.include(
|
|
9
|
+
Pagers::Extensions::ActionView::Base
|
|
10
|
+
)
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
end
|
data/lib/pagers/version.rb
CHANGED
data/test/dummy/Rakefile
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// listed below.
|
|
3
3
|
//
|
|
4
4
|
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
-
// or vendor/assets/javascripts
|
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
6
|
//
|
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
8
|
// compiled file.
|
|
9
9
|
//
|
|
10
|
-
// Read Sprockets README (https://github.com/
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
11
|
// about supported directives.
|
|
12
12
|
//
|
|
13
13
|
//= require_tree .
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* listed below.
|
|
4
4
|
*
|
|
5
5
|
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
-
* or vendor/assets/stylesheets
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
7
|
*
|
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the
|
|
9
|
-
* compiled file
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
10
12
|
*
|
|
11
|
-
*= require_self
|
|
12
13
|
*= require_tree .
|
|
14
|
+
*= require_self
|
|
13
15
|
*/
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html>
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
</body>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Dummy</title>
|
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<%= yield %>
|
|
11
|
+
</body>
|
|
14
12
|
</html>
|