bootstrap_pager 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/pager.iml +50 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +307 -0
- data/Rakefile +42 -0
- data/app/assets/javascripts/infinitescroll.js +8 -0
- data/app/helpers/pager_helper.rb +5 -0
- data/app/views/pager/_first_page.html.erb +11 -0
- data/app/views/pager/_first_page.html.haml +9 -0
- data/app/views/pager/_first_page.html.slim +10 -0
- data/app/views/pager/_gap.html.erb +8 -0
- data/app/views/pager/_gap.html.haml +8 -0
- data/app/views/pager/_gap.html.slim +10 -0
- data/app/views/pager/_last_page.html.erb +11 -0
- data/app/views/pager/_last_page.html.haml +9 -0
- data/app/views/pager/_last_page.html.slim +10 -0
- data/app/views/pager/_next_page.html.erb +11 -0
- data/app/views/pager/_next_page.html.haml +9 -0
- data/app/views/pager/_next_page.html.slim +10 -0
- data/app/views/pager/_page.html.erb +14 -0
- data/app/views/pager/_page.html.haml +11 -0
- data/app/views/pager/_page.html.slim +13 -0
- data/app/views/pager/_paginator.html.erb +25 -0
- data/app/views/pager/_paginator.html.haml +19 -0
- data/app/views/pager/_paginator.html.slim +20 -0
- data/app/views/pager/_prev_page.html.erb +11 -0
- data/app/views/pager/_prev_page.html.haml +9 -0
- data/app/views/pager/_prev_page.html.slim +10 -0
- data/bootstrap_pager.gemspec +36 -0
- data/config/locales/pager.yml +19 -0
- data/gemfiles/active_record_30.gemfile +9 -0
- data/gemfiles/active_record_31.gemfile +7 -0
- data/gemfiles/active_record_32.gemfile +10 -0
- data/gemfiles/active_record_40.gemfile +8 -0
- data/gemfiles/active_record_edge.gemfile +11 -0
- data/gemfiles/data_mapper_12.gemfile +15 -0
- data/gemfiles/mongo_mapper.gemfile +10 -0
- data/gemfiles/mongoid_24.gemfile +7 -0
- data/gemfiles/mongoid_30.gemfile +12 -0
- data/gemfiles/sinatra_13.gemfile +13 -0
- data/gemfiles/sinatra_14.gemfile +13 -0
- data/lib/bootstrap_pager/config.rb +51 -0
- data/lib/bootstrap_pager/grape.rb +4 -0
- data/lib/bootstrap_pager/helpers/action_view_extension.rb +152 -0
- data/lib/bootstrap_pager/helpers/paginator.rb +186 -0
- data/lib/bootstrap_pager/helpers/sinatra_helpers.rb +144 -0
- data/lib/bootstrap_pager/helpers/tags.rb +96 -0
- data/lib/bootstrap_pager/hooks.rb +41 -0
- data/lib/bootstrap_pager/models/active_record_extension.rb +22 -0
- data/lib/bootstrap_pager/models/active_record_model_extension.rb +20 -0
- data/lib/bootstrap_pager/models/active_record_relation_methods.rb +29 -0
- data/lib/bootstrap_pager/models/array_extension.rb +58 -0
- data/lib/bootstrap_pager/models/configuration_methods.rb +48 -0
- data/lib/bootstrap_pager/models/data_mapper_collection_methods.rb +15 -0
- data/lib/bootstrap_pager/models/data_mapper_extension.rb +48 -0
- data/lib/bootstrap_pager/models/mongo_mapper_extension.rb +18 -0
- data/lib/bootstrap_pager/models/mongoid_criteria_methods.rb +23 -0
- data/lib/bootstrap_pager/models/mongoid_extension.rb +33 -0
- data/lib/bootstrap_pager/models/page_scope_methods.rb +70 -0
- data/lib/bootstrap_pager/models/plucky_criteria_methods.rb +18 -0
- data/lib/bootstrap_pager/railtie.rb +7 -0
- data/lib/bootstrap_pager/sinatra.rb +5 -0
- data/lib/bootstrap_pager/version.rb +3 -0
- data/lib/bootstrap_pager.rb +38 -0
- data/lib/generators/pager/config_generator.rb +16 -0
- data/lib/generators/pager/templates/pager_config.rb +10 -0
- data/lib/generators/pager/views_generator.rb +118 -0
- data/spec/config/config_spec.rb +91 -0
- data/spec/fake_app/active_record/config.rb +3 -0
- data/spec/fake_app/active_record/models.rb +57 -0
- data/spec/fake_app/data_mapper/config.rb +7 -0
- data/spec/fake_app/data_mapper/models.rb +27 -0
- data/spec/fake_app/log/development.log +832 -0
- data/spec/fake_app/mongo_mapper/config.rb +2 -0
- data/spec/fake_app/mongo_mapper/models.rb +9 -0
- data/spec/fake_app/mongoid/config.rb +16 -0
- data/spec/fake_app/mongoid/models.rb +22 -0
- data/spec/fake_app/rails_app.rb +67 -0
- data/spec/fake_app/sinatra_app.rb +22 -0
- data/spec/fake_gem.rb +4 -0
- data/spec/helpers/action_view_extension_spec.rb +292 -0
- data/spec/helpers/helpers_spec.rb +135 -0
- data/spec/helpers/sinatra_helpers_spec.rb +170 -0
- data/spec/helpers/tags_spec.rb +140 -0
- data/spec/models/active_record/active_record_relation_methods_spec.rb +47 -0
- data/spec/models/active_record/default_per_page_spec.rb +32 -0
- data/spec/models/active_record/max_pages_spec.rb +23 -0
- data/spec/models/active_record/max_per_page_spec.rb +32 -0
- data/spec/models/active_record/scopes_spec.rb +242 -0
- data/spec/models/array_spec.rb +150 -0
- data/spec/models/data_mapper/data_mapper_spec.rb +207 -0
- data/spec/models/mongo_mapper/mongo_mapper_spec.rb +84 -0
- data/spec/models/mongoid/mongoid_spec.rb +126 -0
- data/spec/requests/users_spec.rb +53 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/spec_helper_for_sinatra.rb +34 -0
- data/spec/support/database_cleaner.rb +16 -0
- data/spec/support/matchers.rb +52 -0
- data/vendor/assets/javascripts/jquery.infinitescroll.js +814 -0
- data/vendor/assets/javascripts/jquery.infinitescroll.min.js +1 -0
- metadata +311 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NGJkMThjNDdkNzM5MjdlYjU2OGI5NWEzNzFhOWM1YTBjYmVjM2NhZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzUyNDk1OTk0Zjk4ZGRkZTMzMzI2YjA5NTk5MGZiY2Y3ZWM5MzBjZg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWNlNDM0NTdkNjZkNzE4NmI5MzllYWE5M2UwYTU4YWY2NTRmMmQxNDk0Nzc4
|
10
|
+
YTVlYzJmYjE3NzI0MWJiNDM3ZDJiYzEwODJlY2M3ZTFkZWY5MDc0ZGZiNDRk
|
11
|
+
NzdlM2E2NDExNDc4ZjVmMDg4OGI1YzdlMTViZTBjY2UyYjVhZjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Y2FlYWYxOWQxOTM0YzFjZGU2ZTU5M2M0M2E1NTRjNDVmNzFjN2EyYmVlZDhj
|
14
|
+
OWZhZDI1MmFhNzA0ZWVhZDI3MTU0NjY3NTg4MTYzYjk5MGI3MmUzNzc4NDhk
|
15
|
+
NmNiMjkwMWUwYjUwZjBlMjdhZmE1NWUzYWQxOGYyYTZlNTNmOTQ=
|
data/.gitignore
ADDED
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
data/.idea/pager.iml
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager">
|
13
|
+
<content url="file://$MODULE_DIR$" />
|
14
|
+
<orderEntry type="inheritedJdk" />
|
15
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="actionpack (v3.2.14, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="activemodel (v3.2.14, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v3.2.14, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="builder (v3.0.4, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="capybara (v2.1.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="database_cleaner (v1.1.1, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.4, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="erubis (v2.7.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="hike (v1.2.3, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.5, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="journey (v1.0.4, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v1.8.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="mime-types (v1.25, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="mini_portile (v0.5.1, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_json (v1.7.9, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.6.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="rack (v1.4.5, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-cache (v1.2, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-test (v0.6.2, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.1.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rdoc (v4.0.1, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="rr (v1.1.2, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v2.14.1, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.14.5, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.14.2, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.14.3, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="sprockets (v2.2.2, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="sqlite3 (v1.3.8, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="tilt (v1.4.1, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.0.1, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="xpath (v2.0.0, RVM: ruby-1.9.3-p448) [gem]" level="application" />
|
48
|
+
</component>
|
49
|
+
</module>
|
50
|
+
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 nerakdon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Akira Matsuda
|
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.rdoc
ADDED
@@ -0,0 +1,307 @@
|
|
1
|
+
= Bootstrap Pager
|
2
|
+
|
3
|
+
Bootstrap Pager is an updated version of the Kaminari pagination gem, which is a Scope & Engine based, clean, powerful, customizable and sophisticated paginator for modern web app frameworks and ORMs
|
4
|
+
|
5
|
+
|
6
|
+
== New Features added in Bootstrap Pager
|
7
|
+
* Works with Bootstrap out of the box
|
8
|
+
* Now works with mountable rails engines using a namespaced route
|
9
|
+
* Semantic HTML5 markup goodness
|
10
|
+
* Added optional infinite scroll (off by default)
|
11
|
+
|
12
|
+
== Features
|
13
|
+
|
14
|
+
=== Clean
|
15
|
+
Does not globally pollute +Array+, +Hash+, +Object+ or <tt>AR::Base</tt>.
|
16
|
+
|
17
|
+
=== Easy to use
|
18
|
+
Just bundle the gem, then your models are ready to be paginated. No configuration required. Don't have to define anything in your models or helpers.
|
19
|
+
|
20
|
+
=== Simple scope-based API
|
21
|
+
Everything is method chainable with less "Hasheritis". You know, that's the Rails 3 way.
|
22
|
+
No special collection class or anything for the paginated values, instead using a general <tt>AR::Relation</tt> instance. So, of course you can chain any other conditions before or after the paginator scope.
|
23
|
+
|
24
|
+
=== Customizable engine-based I18n-aware helper
|
25
|
+
As the whole pagination helper is basically just a collection of links and non-links, Bootstrap Pager renders each of them through its own partial template inside the Engine. So, you can easily modify their behaviour, style or whatever by overriding partial templates.
|
26
|
+
|
27
|
+
=== ORM & template engine agnostic
|
28
|
+
Bootstrap Pager supports multiple ORMs (ActiveRecord, Mongoid, MongoMapper) multiple web frameworks (Rails, Sinatra), and multiple template engines (ERB, Haml).
|
29
|
+
|
30
|
+
=== Modern
|
31
|
+
The pagination helper outputs the HTML5 <nav> tag by default. Plus, the helper supports Rails 3 unobtrusive Ajax.
|
32
|
+
|
33
|
+
|
34
|
+
== Supported versions
|
35
|
+
|
36
|
+
* Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1 (trunk)
|
37
|
+
|
38
|
+
* Rails 3.0.x, 3.1, 3.2, 4.0, 4.1 (edge)
|
39
|
+
|
40
|
+
* Haml 3+
|
41
|
+
|
42
|
+
* Mongoid 2+
|
43
|
+
|
44
|
+
* MongoMapper 0.9+
|
45
|
+
|
46
|
+
* DataMapper 1.1.0+
|
47
|
+
|
48
|
+
== Install
|
49
|
+
|
50
|
+
Put this line in your Gemfile:
|
51
|
+
gem 'bootstrap_pager'
|
52
|
+
|
53
|
+
Then bundle install:
|
54
|
+
% bundle install
|
55
|
+
|
56
|
+
|
57
|
+
== Usage
|
58
|
+
|
59
|
+
=== Query Basics
|
60
|
+
|
61
|
+
* the +page+ scope
|
62
|
+
|
63
|
+
To fetch the 7th page of users (default +per_page+ is 25)
|
64
|
+
User.page(7)
|
65
|
+
|
66
|
+
* the +per+ scope
|
67
|
+
|
68
|
+
To show a lot more users per each page (change the +per_page+ value)
|
69
|
+
User.page(7).per(50)
|
70
|
+
Note that the +per+ scope is not directly defined on the models but is just a method defined on the page scope. This is absolutely reasonable because you will never actually use +per_page+ without specifying the +page+ number.
|
71
|
+
|
72
|
+
Keep in mind that +per+ utilizes internally +limit+ and so it will override any +limit+ that was set previously
|
73
|
+
User.count # => 1000
|
74
|
+
a = User.limit(5).count # => 5
|
75
|
+
b = a.page(1).per(20).size # => 20
|
76
|
+
|
77
|
+
* the +padding+ scope
|
78
|
+
|
79
|
+
Occasionally you need to pad a number of records that is not a multiple of the page size.
|
80
|
+
User.page(7).per(50).padding(3)
|
81
|
+
Note that the +padding+ scope also is not directly defined on the models.
|
82
|
+
|
83
|
+
=== General configuration options
|
84
|
+
|
85
|
+
You can configure the following default values by overriding these values using <tt>BootstrapPager.configure</tt> method.
|
86
|
+
default_per_page # 25 by default
|
87
|
+
max_per_page # nil by default
|
88
|
+
window # 4 by default
|
89
|
+
outer_window # 0 by default
|
90
|
+
left # 0 by default
|
91
|
+
right # 0 by default
|
92
|
+
page_method_name # :page by default
|
93
|
+
param_name # :page by default
|
94
|
+
|
95
|
+
There's a handy generator that generates the default configuration file into config/initializers directory.
|
96
|
+
Run the following generator command, then edit the generated file.
|
97
|
+
% rails g bootstrap_pager:config
|
98
|
+
|
99
|
+
* changing +page_method_name+
|
100
|
+
|
101
|
+
You can change the method name +page+ to +bonzo+ or +plant+ or whatever you like, in order to play nice with existing +page+ method or association or scope or any other plugin that defines +page+ method on your models.
|
102
|
+
|
103
|
+
|
104
|
+
=== Configuring default +per_page+ value for each model
|
105
|
+
|
106
|
+
* +paginates_per+
|
107
|
+
|
108
|
+
You can specify default +per_page+ value per each model using the following declarative DSL.
|
109
|
+
class User < ActiveRecord::Base
|
110
|
+
paginates_per 50
|
111
|
+
end
|
112
|
+
|
113
|
+
=== Configuring max +per_page+ value for each model
|
114
|
+
|
115
|
+
* +max_paginates_per+
|
116
|
+
|
117
|
+
You can specify max +per_page+ value per each model using the following declarative DSL.
|
118
|
+
If the variable that specified via +per+ scope is more than this variable, +max_paginates_per+ is used instead of it. Default value is nil, which means you are not imposing any max +per_page+ value.
|
119
|
+
class User < ActiveRecord::Base
|
120
|
+
max_paginates_per 100
|
121
|
+
end
|
122
|
+
|
123
|
+
=== Controllers
|
124
|
+
|
125
|
+
* the page parameter is in <tt>params[:page]</tt>
|
126
|
+
|
127
|
+
Typically, your controller code will look like this:
|
128
|
+
@users = User.order(:name).page params[:page]
|
129
|
+
|
130
|
+
=== Views
|
131
|
+
|
132
|
+
* the same old helper method
|
133
|
+
|
134
|
+
Just call the +paginate+ helper:
|
135
|
+
<%= paginate @users %>
|
136
|
+
|
137
|
+
This will render several <tt>?page=N</tt> pagination links surrounded by an HTML5 <+nav+> tag.
|
138
|
+
|
139
|
+
=== Helpers
|
140
|
+
|
141
|
+
* the +paginate+ helper method
|
142
|
+
|
143
|
+
<%= paginate @users %>
|
144
|
+
This would output several pagination links such as <tt>« First ‹ Prev ... 2 3 4 5 6 7 8 9 10 ... Next › Last »</tt>
|
145
|
+
|
146
|
+
* specifying the "inner window" size (4 by default)
|
147
|
+
|
148
|
+
<%= paginate @users, :window => 2 %>
|
149
|
+
This would output something like <tt>... 5 6 7 8 9 ...</tt> when 7 is the current page.
|
150
|
+
|
151
|
+
* specifying the "outer window" size (0 by default)
|
152
|
+
|
153
|
+
<%= paginate @users, :outer_window => 3 %>
|
154
|
+
This would output something like <tt>1 2 3 4 ...(snip)... 17 18 19 20</tt> while having 20 pages in total.
|
155
|
+
|
156
|
+
* outer window can be separately specified by +left+, +right+ (0 by default)
|
157
|
+
|
158
|
+
<%= paginate @users, :left => 1, :right => 3 %>
|
159
|
+
This would output something like <tt>1 ...(snip)... 18 19 20</tt> while having 20 pages in total.
|
160
|
+
|
161
|
+
* changing the parameter name (:+param_name+) for the links
|
162
|
+
|
163
|
+
<%= paginate @users, :param_name => :pagina %>
|
164
|
+
This would modify the query parameter name on each links.
|
165
|
+
|
166
|
+
* extra parameters (:+params+) for the links
|
167
|
+
|
168
|
+
<%= paginate @users, :params => {:controller => 'foo', :action => 'bar'} %>
|
169
|
+
This would modify each link's +url_option+. :+controller+ and :+action+ might be the keys in common.
|
170
|
+
|
171
|
+
* Ajax links (crazy simple, but works perfectly!)
|
172
|
+
|
173
|
+
<%= paginate @users, :remote => true %>
|
174
|
+
This would add <tt>data-remote="true"</tt> to all the links inside.
|
175
|
+
|
176
|
+
* the +link_to_next_page+ and +link_to_previous_page+ helper method
|
177
|
+
|
178
|
+
<%= link_to_next_page @items, 'Next Page' %>
|
179
|
+
This simply renders a link to the next page. This would be helpful for creating a Twitter-like pagination feature.
|
180
|
+
|
181
|
+
* the +page_entries_info+ helper method
|
182
|
+
|
183
|
+
<%= page_entries_info @users %>
|
184
|
+
This renders a helpful message with numbers of displayed vs. total entries.
|
185
|
+
|
186
|
+
=== I18n and labels
|
187
|
+
|
188
|
+
The default labels for 'first', 'last', 'previous', '...' and 'next' are stored in the I18n yaml inside the engine, and rendered through I18n API. You can switch the label value per I18n.locale for your internationalized application.
|
189
|
+
Keys and the default values are the following. You can override them by adding to a YAML file in your <tt>Rails.root/config/locales</tt> directory.
|
190
|
+
|
191
|
+
en:
|
192
|
+
views:
|
193
|
+
pagination:
|
194
|
+
first: "« First"
|
195
|
+
last: "Last »"
|
196
|
+
previous: "‹ Prev"
|
197
|
+
next: "Next ›"
|
198
|
+
truncate: "..."
|
199
|
+
|
200
|
+
=== Customizing the pagination helper
|
201
|
+
|
202
|
+
BootstrapPager includes a handy template generator.
|
203
|
+
|
204
|
+
* to edit your paginator
|
205
|
+
|
206
|
+
Run the generator first,
|
207
|
+
% rails g bootstrap_pager:views default
|
208
|
+
|
209
|
+
then edit the partials in your app's <tt>app/views/bootstrap_pager/</tt> directory.
|
210
|
+
|
211
|
+
* for Haml users
|
212
|
+
|
213
|
+
Haml templates generator is also available by adding the <tt>-e haml</tt> option (this is automatically invoked when the default template_engine is set to Haml).
|
214
|
+
|
215
|
+
% rails g bootstrap_pager:views default -e haml
|
216
|
+
|
217
|
+
* themes
|
218
|
+
|
219
|
+
The generator has the ability to fetch several sample template themes from
|
220
|
+
the external repository (https://github.com/amatsuda/bootstrap_pager_themes) in
|
221
|
+
addition to the bundled "default" one, which will help you creating a nice
|
222
|
+
looking paginator.
|
223
|
+
% rails g bootstrap_pager:views THEME
|
224
|
+
|
225
|
+
To see the full list of avaliable themes, take a look at the themes repository,
|
226
|
+
or just hit the generator without specifying +THEME+ argument.
|
227
|
+
% rails g bootstrap_pager:views
|
228
|
+
|
229
|
+
* multiple themes
|
230
|
+
|
231
|
+
To utilize multiple themes from within a single application, create a directory within the app/views/bootstrap_pager/ and move your custom template files into that directory.
|
232
|
+
% rails g bootstrap_pager:views default (skip if you have existing bootstrap_pager views)
|
233
|
+
% cd app/views/bootstrap_pager
|
234
|
+
% mkdir my_custom_theme
|
235
|
+
% cp _*.html.* my_custom_theme/
|
236
|
+
|
237
|
+
Next, reference that directory when calling the +paginate+ method:
|
238
|
+
|
239
|
+
<%= paginate @users, :theme => 'my_custom_theme' %>
|
240
|
+
|
241
|
+
Customize away!
|
242
|
+
|
243
|
+
Note: if the theme isn't present or none is specified, bootstrap_pager will default back to the views included within the gem.
|
244
|
+
|
245
|
+
=== Paginating a generic Array object
|
246
|
+
|
247
|
+
BootstrapPager provides an Array wrapper class that adapts a generic Array object to the <tt>paginate</tt> view helper.
|
248
|
+
However, the <tt>paginate</tt> helper doesn't automatically handle your Array object (this is intentional and by design).
|
249
|
+
<tt>BootstrapPager::paginate_array</tt> method converts your Array object into a paginatable Array that accepts <tt>page</tt> method.
|
250
|
+
BootstrapPager.paginate_array(my_array_object).page(params[:page]).per(10)
|
251
|
+
|
252
|
+
You can specify the +total_count+ value through options Hash. This would be helpful when handling an Array-ish object that has a different +count+ value from actual +count+ such as RSolr search result or when you need to generate a custom pagination. For example:
|
253
|
+
BootstrapPager.paginate_array([], total_count: 145).page(params[:page]).per(10)
|
254
|
+
|
255
|
+
== Creating friendly URLs and caching
|
256
|
+
|
257
|
+
Because of the +page+ parameter and Rails 3 routing, you can easily generate SEO and user-friendly URLs. For any resource you'd like to paginate, just add the following to your +routes.rb+:
|
258
|
+
|
259
|
+
resources :my_resources do
|
260
|
+
get 'page/:page', :action => :index, :on => :collection
|
261
|
+
end
|
262
|
+
|
263
|
+
This will create URLs like <tt>/my_resources/page/33</tt> instead of <tt>/my_resources?page=33</tt>. This is now a friendly URL, but it also has other added benefits...
|
264
|
+
|
265
|
+
Because the +page+ parameter is now a URL segment, we can leverage on Rails page caching[http://guides.rubyonrails.org/caching_with_rails.html#page-caching]!
|
266
|
+
|
267
|
+
NOTE: In this example, I've pointed the route to my <tt>:index</tt> action. You may have defined a custom pagination action in your controller - you should point <tt>:action => :your_custom_action</tt> instead.
|
268
|
+
|
269
|
+
|
270
|
+
== Sinatra/Padrino support
|
271
|
+
|
272
|
+
Since version 0.13.0, bootstrap_pager started to support Sinatra or Sinatra-based frameworks experimentally.
|
273
|
+
|
274
|
+
To use bootstrap_pager and its helpers with these frameworks,
|
275
|
+
|
276
|
+
require 'bootstrap_pager/sinatra'
|
277
|
+
|
278
|
+
or edit gemfile:
|
279
|
+
|
280
|
+
gem 'bootstrap_pager', :require => 'bootstrap_pager/sinatra'
|
281
|
+
|
282
|
+
More features are coming, and again, this is still experimental. Please let us know if you found anything wrong with the Sinatra support.
|
283
|
+
|
284
|
+
== Infinite Scroll with Jquery
|
285
|
+
|
286
|
+
For infinite scroll technology, add jquery.infinitescroll to your application.js file.
|
287
|
+
|
288
|
+
//= require jquery.infinitescroll
|
289
|
+
//= require infinitescroll
|
290
|
+
|
291
|
+
Then, add class="infinitescroll" to the div containing your pagination call, and add the class "infinitescroll-item" to the items within that div that represent individual objects.
|
292
|
+
|
293
|
+
<div id="posts" class="infinitescroll">
|
294
|
+
<div id="post_5" class="infinitescroll-item">
|
295
|
+
... Post content here ...
|
296
|
+
</div>
|
297
|
+
... Many more posts here ...
|
298
|
+
<%= pagination @posts %>
|
299
|
+
</div>
|
300
|
+
|
301
|
+
== Contributors
|
302
|
+
* Karen Lundgren - code updates
|
303
|
+
* Chad Lundgren - verbiage and usability advice
|
304
|
+
|
305
|
+
== Copyright
|
306
|
+
|
307
|
+
Copyright (c) 2013 Sour Cherry Web. See MIT-LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => "spec:all"
|
14
|
+
|
15
|
+
namespace :spec do
|
16
|
+
%w(active_record_edge active_record_40 active_record_32 active_record_31 active_record_30 data_mapper_12 mongoid_30 mongoid_24 mongo_mapper sinatra_13 sinatra_14).each do |gemfile|
|
17
|
+
desc "Run Tests against #{gemfile}"
|
18
|
+
task gemfile do
|
19
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
20
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run Tests against all ORMs"
|
25
|
+
task :all do
|
26
|
+
%w(active_record_edge active_record_40 active_record_32 active_record_31 active_record_30 data_mapper_12 mongoid_30 mongoid_24 mongo_mapper sinatra_13 sinatra_14).each do |gemfile|
|
27
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
28
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'rdoc/task'
|
34
|
+
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
require 'bootstrap_pager/version'
|
37
|
+
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = "bootstrap_pager #{BootstrapPager::VERSION}"
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "First" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the first page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<li class="first">
|
10
|
+
<%= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote %>
|
11
|
+
</li>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "First" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the first page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%li.first
|
9
|
+
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Link to the "First" page
|
2
|
+
- available local variables
|
3
|
+
url : url to the first page
|
4
|
+
current_page : a page object for the currently displayed page
|
5
|
+
total_pages : total number of pages
|
6
|
+
per_page : number of items to fetch per page
|
7
|
+
remote : data-remote
|
8
|
+
li.first
|
9
|
+
== link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, :remote => remote
|
10
|
+
'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%# Non-link tag that stands for skipped pages...
|
2
|
+
- available local variables
|
3
|
+
current_page: a page object for the currently displayed page
|
4
|
+
total_pages: total number of pages
|
5
|
+
per_page: number of items to fetch per page
|
6
|
+
remote: data-remote
|
7
|
+
-%>
|
8
|
+
<li class="page gap"><span><%= t('views.pagination.truncate').html_safe %></span></li>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
-# Non-link tag that stands for skipped pages...
|
2
|
+
-# available local variables
|
3
|
+
-# current_page: a page object for the currently displayed page
|
4
|
+
-# total_pages: total number of pages
|
5
|
+
-# per_page: number of items to fetch per page
|
6
|
+
-# remote: data-remote
|
7
|
+
%li.page.gap
|
8
|
+
%span= t('views.pagination.truncate').html_safe
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Non-link tag that stands for skipped pages...
|
2
|
+
- available local variables
|
3
|
+
current_page : a page object for the currently displayed page
|
4
|
+
total_pages : total number of pages
|
5
|
+
per_page : number of items to fetch per page
|
6
|
+
remote : data-remote
|
7
|
+
li.page.gap
|
8
|
+
span
|
9
|
+
== t('views.pagination.truncate').html_safe
|
10
|
+
'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "Last" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the last page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<li class="last">
|
10
|
+
<%= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote %>
|
11
|
+
</li>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "Last" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the last page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%li.last
|
9
|
+
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/ Link to the "Last" page
|
2
|
+
- available local variables
|
3
|
+
url : url to the last page
|
4
|
+
current_page : a page object for the currently displayed page
|
5
|
+
total_pages : total number of pages
|
6
|
+
per_page : number of items to fetch per page
|
7
|
+
remote : data-remote
|
8
|
+
li.last
|
9
|
+
== link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, :remote => remote
|
10
|
+
'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%# Link to the "Next" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the next page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
<li class="next">
|
10
|
+
<%= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, :rel => 'next', :remote => remote %>
|
11
|
+
</li>
|