will_paginate 2.3.17 → 3.0.pre
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.
Potentially problematic release.
This version of will_paginate might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +24 -80
- data/LICENSE +1 -1
- data/README.rdoc +125 -0
- data/Rakefile +26 -22
- data/lib/will_paginate.rb +10 -84
- data/lib/will_paginate/array.rb +25 -8
- data/lib/will_paginate/collection.rb +15 -28
- data/lib/will_paginate/core_ext.rb +26 -0
- data/lib/will_paginate/deprecation.rb +50 -0
- data/lib/will_paginate/finders.rb +9 -0
- data/lib/will_paginate/finders/active_record.rb +158 -0
- data/lib/will_paginate/finders/active_resource.rb +51 -0
- data/lib/will_paginate/finders/base.rb +112 -0
- data/lib/will_paginate/finders/data_mapper.rb +30 -0
- data/lib/will_paginate/finders/sequel.rb +23 -0
- data/lib/will_paginate/railtie.rb +26 -0
- data/lib/will_paginate/version.rb +5 -5
- data/lib/will_paginate/view_helpers.rb +25 -436
- data/lib/will_paginate/view_helpers/action_view.rb +142 -0
- data/lib/will_paginate/view_helpers/base.rb +126 -0
- data/lib/will_paginate/view_helpers/link_renderer.rb +130 -0
- data/lib/will_paginate/view_helpers/link_renderer_base.rb +83 -0
- data/lib/will_paginate/view_helpers/merb.rb +13 -0
- data/spec/collection_spec.rb +147 -0
- data/spec/console +8 -0
- data/spec/console_fixtures.rb +8 -0
- data/spec/database.yml +22 -0
- data/spec/finders/active_record_spec.rb +377 -0
- data/spec/finders/active_resource_spec.rb +52 -0
- data/spec/finders/activerecord_test_connector.rb +114 -0
- data/spec/finders/data_mapper_spec.rb +62 -0
- data/spec/finders/data_mapper_test_connector.rb +20 -0
- data/spec/finders/sequel_spec.rb +53 -0
- data/spec/finders/sequel_test_connector.rb +9 -0
- data/spec/finders_spec.rb +76 -0
- data/{test → spec}/fixtures/admin.rb +0 -0
- data/{test → spec}/fixtures/developer.rb +2 -3
- data/{test → spec}/fixtures/developers_projects.yml +0 -0
- data/{test → spec}/fixtures/project.rb +2 -6
- data/{test → spec}/fixtures/projects.yml +1 -1
- data/{test → spec}/fixtures/replies.yml +0 -0
- data/{test → spec}/fixtures/reply.rb +1 -1
- data/{test → spec}/fixtures/schema.rb +0 -0
- data/spec/fixtures/topic.rb +7 -0
- data/{test → spec}/fixtures/topics.yml +0 -0
- data/{test → spec}/fixtures/user.rb +0 -0
- data/{test → spec}/fixtures/users.yml +0 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/tasks.rake +60 -0
- data/spec/view_helpers/action_view_spec.rb +345 -0
- data/spec/view_helpers/base_spec.rb +64 -0
- data/spec/view_helpers/link_renderer_base_spec.rb +84 -0
- data/spec/view_helpers/view_example_group.rb +103 -0
- metadata +60 -65
- data/README.md +0 -53
- data/lib/will_paginate/finder.rb +0 -269
- data/lib/will_paginate/i18n.rb +0 -29
- data/lib/will_paginate/locale/en.yml +0 -33
- data/lib/will_paginate/named_scope.rb +0 -170
- data/lib/will_paginate/named_scope_patch.rb +0 -37
- data/lib/will_paginate/per_page.rb +0 -27
- data/test/ci.rb +0 -60
- data/test/collection_test.rb +0 -160
- data/test/console +0 -8
- data/test/database.yml +0 -16
- data/test/finder_test.rb +0 -527
- data/test/fixtures/topic.rb +0 -12
- data/test/gemfiles/Gemfile.1.2 +0 -13
- data/test/gemfiles/Gemfile.1.2.lock +0 -39
- data/test/gemfiles/Gemfile.2.0 +0 -16
- data/test/gemfiles/Gemfile.2.0.lock +0 -28
- data/test/gemfiles/Gemfile.2.1 +0 -16
- data/test/gemfiles/Gemfile.2.1.lock +0 -28
- data/test/gemfiles/Gemfile.2.2 +0 -16
- data/test/gemfiles/Gemfile.2.2.lock +0 -28
- data/test/helper.rb +0 -34
- data/test/lib/activerecord_test_case.rb +0 -38
- data/test/lib/activerecord_test_connector.rb +0 -86
- data/test/lib/load_fixtures.rb +0 -12
- data/test/lib/view_test_process.rb +0 -186
- data/test/view_test.rb +0 -380
data/CHANGELOG.rdoc
CHANGED
@@ -1,81 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
* added
|
4
|
-
* added
|
5
|
-
*
|
6
|
-
*
|
7
|
-
|
8
|
-
|
9
|
-
*
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
*
|
22
|
-
|
23
|
-
= 2.3.12, released 2009-12-01
|
24
|
-
|
25
|
-
* make view helpers "HTML safe" for Rails 2.3.5 with rails_xss plugin
|
26
|
-
|
27
|
-
= 2.3.11, released 2009-06-02
|
28
|
-
|
29
|
-
* fix `enable_actionpack`
|
30
|
-
|
31
|
-
= 2.3.10, released 2009-05-21
|
32
|
-
|
33
|
-
* count_by_sql: don't use table alias with any adapters starting with "oracle"
|
34
|
-
* Add back "AS count_table" alias to `paginate_by_sql` counter SQL
|
35
|
-
|
36
|
-
= 2.3.9, released 2009-05-29
|
37
|
-
|
38
|
-
* remove "AS count_table" alias from `paginate_by_sql` counter SQL
|
39
|
-
* Rails 2.3.2 compat: monkeypatch Rails issue #2189 (count breaks has_many :through)
|
40
|
-
* fix generation of page URLs that contain the "@" character
|
41
|
-
* check for method existance in a ruby 1.8- and 1.9-compatible way
|
42
|
-
* load will_paginate view helpers even if ActiveRecord is not loaded
|
43
|
-
|
44
|
-
== 2.3.8, released 2009-03-09
|
45
|
-
|
46
|
-
* Rails 2.3 compat: query parameter parsing with Rack
|
47
|
-
|
48
|
-
== 2.3.7, released 2009-02-09
|
49
|
-
|
50
|
-
* Removed all unnecessary &block variables since they cause serious memory damage and lots of subsequent gc runs.
|
51
|
-
|
52
|
-
== 2.3.6, released 2008-10-26
|
53
|
-
|
54
|
-
* Rails 2.2 fix: stop using `extract_attribute_names_from_match` inernal AR method, it no longer exists
|
55
|
-
|
56
|
-
== 2.3.5, released 2008-10-07
|
57
|
-
|
58
|
-
* update the backported named_scope implementation for Rails versions older than 2.1
|
59
|
-
* break out of scope of paginated_each() yielded block when used on named scopes
|
60
|
-
* fix paginate(:from)
|
61
|
-
|
62
|
-
== 2.3.4, released 2008-09-16
|
63
|
-
|
64
|
-
* Removed gem dependency to Active Support (causes trouble with vendored rails).
|
65
|
-
* Rails 2.1: fix a failing test and a deprecation warning.
|
66
|
-
* Cope with scoped :select when counting.
|
67
|
-
|
68
|
-
== 2.3.3, released 2008-08-29
|
69
|
-
|
70
|
-
* Ensure that paginate_by_sql doesn't change the original SQL query.
|
71
|
-
* RDoc love (now live at http://gitrdoc.com/mislav/will_paginate/tree/master)
|
72
|
-
* Rename :prev_label to :previous_label for consistency. old name still functions but is deprecated
|
73
|
-
* ActiveRecord 2.1: Remove :include option from count_all query when it's possible.
|
74
|
-
|
75
|
-
== 2.3.2, released 2008-05-16
|
76
|
-
|
77
|
-
* Fixed LinkRenderer#stringified_merge by removing "return" from iterator block
|
78
|
-
* Ensure that 'href' values in pagination links are escaped URLs
|
1
|
+
== "agnostic" branch
|
2
|
+
|
3
|
+
* added Sequel support
|
4
|
+
* added an initialization hook for Merb
|
5
|
+
* refactored URL generation
|
6
|
+
* BACKWARDS INCOMPATIBLE: refactored LinkRenderer; also markup changes
|
7
|
+
<span class="current">1</span> is now <em>1</em>
|
8
|
+
a.prev_page -> a.previous_page (for consistency)
|
9
|
+
* "prev_label" -> "previous_label"
|
10
|
+
* ported view tests to specs
|
11
|
+
* setup Autotest
|
12
|
+
* added per_page=(limit) attribute writer to set default per_page
|
13
|
+
* Remove :include option from count_all query when possible (Rails 2.1)
|
14
|
+
* added WP::ViewHelpers::ActionView and LinkRenderer
|
15
|
+
* specs for ViewHelpers::Base and LinkRendererBase
|
16
|
+
* created LinkRendererBase that implements windowed visible page numbers logic
|
17
|
+
* created WP::ViewHelpers::Base abstract module that implements generic view helpers
|
18
|
+
* ported finder tests to specs
|
19
|
+
* added WP::Finders::DataMapper
|
20
|
+
* added WP::Finders::ActiveRecord mixin for ActiveRecord::Base
|
21
|
+
* created WP::Finders::Base abstract module that implements generic pagination logic
|
22
|
+
* removed dependency to ActiveSupport
|
79
23
|
|
80
24
|
== 2.3.1, released 2008-05-04
|
81
25
|
|
@@ -106,14 +50,14 @@
|
|
106
50
|
gem install mislav-will_paginate
|
107
51
|
|
108
52
|
* extract reusable pagination testing stuff into WillPaginate::View
|
109
|
-
* rethink the page URL construction
|
53
|
+
* rethink the page URL construction mechanism to be more bulletproof when
|
110
54
|
combined with custom routing for page parameter
|
111
55
|
* test that anchor parameter can be used in pagination links
|
112
56
|
|
113
57
|
== 2.2.2, released 2008-04-21
|
114
58
|
|
115
59
|
* Add support for page parameter in custom routes like "/foo/page/2"
|
116
|
-
* Change output of "page_entries_info" on single-page collection and
|
60
|
+
* Change output of "page_entries_info" on single-page collection and erroneous
|
117
61
|
output with empty collection as reported by Tim Chater
|
118
62
|
|
119
63
|
== 2.2.1, released 2008-04-08
|
data/LICENSE
CHANGED
data/README.rdoc
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
= The will_paginate Ruby library
|
2
|
+
|
3
|
+
Pagination is just limiting the number of records loaded and displayed. Why should you let it get in
|
4
|
+
your way while developing?
|
5
|
+
|
6
|
+
This is how you paginate on an ActiveRecord model:
|
7
|
+
|
8
|
+
Post.paginate :page => 1, :order => 'created_at DESC'
|
9
|
+
|
10
|
+
Most of the time it's as simple as replacing "find" with "paginate" and specifying the page you want.
|
11
|
+
|
12
|
+
Some resources to get you started:
|
13
|
+
|
14
|
+
* The {will_paginate project page}[http://mislav.github.com/will_paginate/];
|
15
|
+
* Your mind reels with questions? Join our {Google group}[http://groups.google.com/group/will_paginate];
|
16
|
+
* {How to report bugs}[http://github.com/mislav/will_paginate/wikis/report-bugs];
|
17
|
+
* {Watch the will_paginate screencast}[http://railscasts.com/episodes/51] by Ryan Bates.
|
18
|
+
|
19
|
+
== I'm not using Rails; can I still use will_paginate?
|
20
|
+
|
21
|
+
Absolutely -- although will_paginate started off as a Rails plugin, now it is a <em>completely
|
22
|
+
framework-agnostic</em> library with support for Rails and Merb built-in. The core library doesn't
|
23
|
+
have any dependences and you can safely use it in any Ruby code.
|
24
|
+
|
25
|
+
When will_paginate is loaded in an environment where ActiveRecord and ActionView are present, it
|
26
|
+
automatically hooks into these frameworks to provide easy pagination on your models and in your
|
27
|
+
views. The same mechanism works for Merb applications, too. But, if no known framework is present
|
28
|
+
then you have absolute control over what parts of will_paginate do you want to load and where you want
|
29
|
+
them mixed in.
|
30
|
+
|
31
|
+
|
32
|
+
== Installation
|
33
|
+
|
34
|
+
The recommended way is that you get the gem hosted on {gems.github.com}[http://gems.github.com/]:
|
35
|
+
|
36
|
+
gem install mislav-will_paginate
|
37
|
+
|
38
|
+
In <b>Rails 2.1</b>, add a gem dependency:
|
39
|
+
|
40
|
+
# for Rails 2.1 and newer
|
41
|
+
config.gem 'mislav-will_paginate', :lib => 'will_paginate', :version => '~> 3.0'
|
42
|
+
|
43
|
+
If you're using Rails 2.0 or older, or any other Ruby framework, just add a simple require to a file
|
44
|
+
that initializes your application. For example, in Rails you would put this at the end of
|
45
|
+
"config/environment.rb".
|
46
|
+
|
47
|
+
gem 'mislav-will_paginate', '~> 3.0'
|
48
|
+
require 'will_paginate'
|
49
|
+
|
50
|
+
That's it. Remember to install the gem on <strong>all</strong> machines that you are deploying to.
|
51
|
+
|
52
|
+
<i>There are extensive {installation
|
53
|
+
instructions}[http://github.com/mislav/will_paginate/wikis/installation] on {the
|
54
|
+
wiki}[http://github.com/mislav/will_paginate/wikis].</i>
|
55
|
+
|
56
|
+
|
57
|
+
== Example usage
|
58
|
+
|
59
|
+
Typical usage involves a paginating find in the controller:
|
60
|
+
|
61
|
+
@posts = Post.paginate :page => params[:page], :order => 'updated_at DESC'
|
62
|
+
|
63
|
+
It's true: +paginate+ works just like +find+ -- it just doesn't fetch all the records. Don't forget
|
64
|
+
to tell it which page you want, or it will complain! Read more in WillPaginate::Finders.
|
65
|
+
|
66
|
+
Render the posts in your view like you would normally do, and when you need to render pagination,
|
67
|
+
just stick this in:
|
68
|
+
|
69
|
+
<%= will_paginate @posts %>
|
70
|
+
|
71
|
+
You're done. Read more in WillPaginate::ViewHelpers::Base.
|
72
|
+
|
73
|
+
How does it know how much items to fetch per page? It asks your model by calling its
|
74
|
+
+per_page+ class method. You can define it like this:
|
75
|
+
|
76
|
+
class Post < ActiveRecord::Base
|
77
|
+
self.per_page = 50
|
78
|
+
end
|
79
|
+
|
80
|
+
... or don't worry about it at all. WillPaginate defines it to be <strong>30</strong> by default. You can
|
81
|
+
always specify the count explicitly when calling +paginate+:
|
82
|
+
|
83
|
+
Post.paginate :page => params[:page], :per_page => 50
|
84
|
+
|
85
|
+
The +paginate+ finder wraps the original finder and returns your result set that now has some new
|
86
|
+
properties. You can use the collection as you would use any other array. WillPaginate view helpers
|
87
|
+
also need that collection object to be able to render pagination:
|
88
|
+
|
89
|
+
<ol>
|
90
|
+
<% for post in @posts -%>
|
91
|
+
<li>Render `post` in some nice way.</li>
|
92
|
+
<% end -%>
|
93
|
+
</ol>
|
94
|
+
|
95
|
+
<p>Now let's render us some pagination!</p>
|
96
|
+
<%= will_paginate @posts %>
|
97
|
+
|
98
|
+
|
99
|
+
== Authors and credits
|
100
|
+
|
101
|
+
The original author of will_paginate was PJ Hyett, who later handed over development to Mislav
|
102
|
+
Marohnić. (The library was completely rewritten since then.)
|
103
|
+
|
104
|
+
All these people helped making will_paginate what it is now with their code contributions or just
|
105
|
+
simply awesome ideas:
|
106
|
+
|
107
|
+
Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence Golda, Matt Aimonetti,
|
108
|
+
Charles Brian Quinn, Desi McAdam, James Coglan, Matijs van Zuijlen, Maria, Brendan Ribera, Todd
|
109
|
+
Willey, Bryan Helmkamp, Jan Berkel, Lourens Naudé, Rick Olson, Russell Norris, Piotr Usewicz, Chris
|
110
|
+
Eppstein, Brandon Arbini, Denis Barushev, Paul Barry, Ben Pickles, Ken Collins, Lida Tang and Pieter
|
111
|
+
Noordhuis.
|
112
|
+
|
113
|
+
|
114
|
+
== Usable pagination in the UI
|
115
|
+
|
116
|
+
There are example CSS styles to get you started on the will_paginate project page.
|
117
|
+
|
118
|
+
More reading about pagination as design pattern:
|
119
|
+
|
120
|
+
* {Pagination 101}[http://kurafire.net/log/archive/2007/06/22/pagination-101];
|
121
|
+
* {Pagination gallery}[http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/] featured on Smashing Magazine;
|
122
|
+
* {Pagination design pattern}[http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination] on Yahoo Design Pattern Library.
|
123
|
+
|
124
|
+
Want to discuss, request features, ask questions? Join the {Google
|
125
|
+
group}[http://groups.google.com/group/will_paginate].
|
data/Rakefile
CHANGED
@@ -1,28 +1,32 @@
|
|
1
|
-
require 'rake/
|
1
|
+
require 'rake/rdoctask'
|
2
2
|
|
3
|
-
|
4
|
-
task :default => :test
|
3
|
+
load 'spec/tasks.rake'
|
5
4
|
|
6
|
-
desc '
|
7
|
-
|
8
|
-
if ENV['DB'] and ENV['DB'] != 'sqlite3'
|
9
|
-
t.pattern = %w[test/finder_test.rb]
|
10
|
-
else
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
end
|
13
|
-
t.libs << 'test'
|
14
|
-
end
|
5
|
+
desc 'Default: run specs.'
|
6
|
+
task :default => :spec
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
8
|
+
desc 'Generate RDoc documentation for the will_paginate plugin.'
|
9
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
|
11
|
+
include('lib/**/*.rb').
|
12
|
+
exclude('lib/will_paginate/finders/active_record/named_scope*').
|
13
|
+
exclude('lib/will_paginate/finders/sequel.rb').
|
14
|
+
exclude('lib/will_paginate/view_helpers/merb.rb').
|
15
|
+
exclude('lib/will_paginate/deprecation.rb').
|
16
|
+
exclude('lib/will_paginate/core_ext.rb').
|
17
|
+
exclude('lib/will_paginate/version.rb')
|
18
|
+
|
19
|
+
rdoc.main = "README.rdoc" # page to start on
|
20
|
+
rdoc.title = "will_paginate documentation"
|
21
|
+
|
22
|
+
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
23
|
+
rdoc.options << '--inline-source' << '--charset=UTF-8'
|
24
|
+
rdoc.options << '--webcvs=http://github.com/mislav/will_paginate/tree/master/'
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
task :website do
|
28
|
+
Dir.chdir('website') do
|
29
|
+
%x(haml index.haml index.html)
|
30
|
+
%x(sass pagination.sass pagination.css)
|
27
31
|
end
|
28
32
|
end
|
data/lib/will_paginate.rb
CHANGED
@@ -1,97 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
require 'will_paginate/core_ext'
|
1
|
+
require 'will_paginate/deprecation'
|
3
2
|
|
4
3
|
# = You *will* paginate!
|
5
4
|
#
|
6
|
-
# First read about WillPaginate::
|
5
|
+
# First read about WillPaginate::Finders::Base, then see
|
7
6
|
# WillPaginate::ViewHelpers. The magical array you're handling in-between is
|
8
7
|
# WillPaginate::Collection.
|
9
8
|
#
|
10
9
|
# Happy paginating!
|
11
10
|
module WillPaginate
|
12
|
-
class << self
|
13
|
-
# shortcut for <tt>enable_actionpack</tt> and <tt>enable_activerecord</tt> combined
|
14
|
-
def enable
|
15
|
-
enable_actionpack
|
16
|
-
enable_activerecord
|
17
|
-
end
|
18
|
-
|
19
|
-
# hooks WillPaginate::ViewHelpers into ActionView::Base
|
20
|
-
def enable_actionpack
|
21
|
-
return if ActionView::Base.instance_methods.include_method? :will_paginate
|
22
|
-
require 'will_paginate/view_helpers'
|
23
|
-
ActionView::Base.send :include, ViewHelpers
|
24
|
-
|
25
|
-
if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
|
26
|
-
ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# hooks WillPaginate::Finder into ActiveRecord::Base and classes that deal
|
31
|
-
# with associations
|
32
|
-
def enable_activerecord
|
33
|
-
return if ActiveRecord::Base.respond_to? :paginate
|
34
|
-
require 'will_paginate/finder'
|
35
|
-
ActiveRecord::Base.send :include, Finder
|
36
|
-
|
37
|
-
# support pagination on associations
|
38
|
-
a = ActiveRecord::Associations
|
39
|
-
klasses = [ a::AssociationCollection ]
|
40
|
-
# detect http://dev.rubyonrails.org/changeset/9230
|
41
|
-
unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
|
42
|
-
klasses << a::HasManyThroughAssociation
|
43
|
-
end
|
44
|
-
|
45
|
-
klasses.each do |klass|
|
46
|
-
klass.send :include, Finder::ClassMethods
|
47
|
-
klass.class_eval { alias_method_chain :method_missing, :paginate }
|
48
|
-
end
|
49
|
-
|
50
|
-
# monkeypatch Rails ticket #2189: "count breaks has_many :through"
|
51
|
-
ActiveRecord::Base.class_eval do
|
52
|
-
protected
|
53
|
-
def self.construct_count_options_from_args(*args)
|
54
|
-
result = super
|
55
|
-
result[0] = '*' if result[0].is_a?(String) and result[0] =~ /\.\*$/
|
56
|
-
result
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Enable named_scope, a feature of Rails 2.1, even if you have older Rails
|
62
|
-
# (tested on Rails 2.0.2 and 1.2.6).
|
63
|
-
#
|
64
|
-
# You can pass +false+ for +patch+ parameter to skip monkeypatching
|
65
|
-
# *associations*. Use this if you feel that <tt>named_scope</tt> broke
|
66
|
-
# has_many, has_many :through or has_and_belongs_to_many associations in
|
67
|
-
# your app. By passing +false+, you can still use <tt>named_scope</tt> in
|
68
|
-
# your models, but not through associations.
|
69
|
-
def enable_named_scope(patch = true)
|
70
|
-
return if defined? ActiveRecord::NamedScope
|
71
|
-
require 'will_paginate/named_scope'
|
72
|
-
require 'will_paginate/named_scope_patch' if patch
|
73
|
-
|
74
|
-
ActiveRecord::Base.send :include, WillPaginate::NamedScope
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
module Deprecation # :nodoc:
|
79
|
-
extend ActiveSupport::Deprecation
|
80
|
-
|
81
|
-
def self.warn(message, callstack = caller)
|
82
|
-
message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
|
83
|
-
ActiveSupport::Deprecation.warn(message, callstack)
|
84
|
-
end
|
85
|
-
end
|
86
11
|
end
|
87
12
|
|
88
|
-
if defined?
|
89
|
-
|
90
|
-
WillPaginate.enable_actionpack if defined? ActionController
|
13
|
+
if defined?(::Rails::Railtie)
|
14
|
+
require 'will_paginate/railtie'
|
91
15
|
end
|
92
16
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
17
|
+
if defined?(::Merb::Plugins)
|
18
|
+
require 'will_paginate/view_helpers/merb'
|
19
|
+
# auto-load the right ORM adapter
|
20
|
+
if adapter = { :datamapper => 'data_mapper', :activerecord => 'active_record', :sequel => 'sequel' }[Merb.orm]
|
21
|
+
require "will_paginate/finders/#{adapter}"
|
22
|
+
end
|
97
23
|
end
|
data/lib/will_paginate/array.rb
CHANGED
@@ -1,15 +1,32 @@
|
|
1
1
|
require 'will_paginate/collection'
|
2
|
-
require 'will_paginate/per_page'
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
class Array
|
4
|
+
# Paginates a static array (extracting a subset of it). The result is a
|
5
|
+
# WillPaginate::Collection instance, which is an array with a few more
|
6
|
+
# properties about its paginated state.
|
7
|
+
#
|
8
|
+
# Parameters:
|
9
|
+
# * <tt>:page</tt> - current page, defaults to 1
|
10
|
+
# * <tt>:per_page</tt> - limit of items per page, defaults to 30
|
11
|
+
# * <tt>:total_entries</tt> - total number of items in the array, defaults to
|
12
|
+
# <tt>array.length</tt> (obviously)
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
# arr = ['a', 'b', 'c', 'd', 'e']
|
16
|
+
# paged = arr.paginate(:per_page => 2) #-> ['a', 'b']
|
17
|
+
# paged.total_entries #-> 5
|
18
|
+
# arr.paginate(:page => 2, :per_page => 2) #-> ['c', 'd']
|
19
|
+
# arr.paginate(:page => 3, :per_page => 2) #-> ['e']
|
20
|
+
#
|
21
|
+
# This method was originally {suggested by Desi
|
22
|
+
# McAdam}[http://www.desimcadam.com/archives/8] and later proved to be the
|
23
|
+
# most useful method of will_paginate library.
|
6
24
|
def paginate(options = {})
|
7
25
|
raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
WillPaginate::Collection.create(page, per_page, total) do |pager|
|
26
|
+
|
27
|
+
WillPaginate::Collection.create options[:page] || 1,
|
28
|
+
options[:per_page] || 30,
|
29
|
+
options[:total_entries] || self.length do |pager|
|
13
30
|
pager.replace self[pager.offset, pager.per_page].to_a
|
14
31
|
end
|
15
32
|
end
|