agnostic-will_paginate 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.autotest +54 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.manifest +61 -0
  5. data/CHANGELOG.rdoc +105 -0
  6. data/LICENSE +18 -0
  7. data/README.rdoc +125 -0
  8. data/Rakefile +58 -0
  9. data/init.rb +1 -0
  10. data/lib/will_paginate.rb +45 -0
  11. data/lib/will_paginate/array.rb +33 -0
  12. data/lib/will_paginate/collection.rb +145 -0
  13. data/lib/will_paginate/core_ext.rb +69 -0
  14. data/lib/will_paginate/deprecation.rb +50 -0
  15. data/lib/will_paginate/finders.rb +9 -0
  16. data/lib/will_paginate/finders/active_record.rb +192 -0
  17. data/lib/will_paginate/finders/active_record/named_scope.rb +170 -0
  18. data/lib/will_paginate/finders/active_record/named_scope_patch.rb +39 -0
  19. data/lib/will_paginate/finders/active_resource.rb +51 -0
  20. data/lib/will_paginate/finders/base.rb +112 -0
  21. data/lib/will_paginate/finders/data_mapper.rb +30 -0
  22. data/lib/will_paginate/finders/sequel.rb +22 -0
  23. data/lib/will_paginate/version.rb +9 -0
  24. data/lib/will_paginate/view_helpers.rb +42 -0
  25. data/lib/will_paginate/view_helpers/action_view.rb +158 -0
  26. data/lib/will_paginate/view_helpers/base.rb +126 -0
  27. data/lib/will_paginate/view_helpers/link_renderer.rb +130 -0
  28. data/lib/will_paginate/view_helpers/link_renderer_base.rb +83 -0
  29. data/lib/will_paginate/view_helpers/merb.rb +13 -0
  30. data/spec/collection_spec.rb +147 -0
  31. data/spec/console +8 -0
  32. data/spec/console_fixtures.rb +8 -0
  33. data/spec/database.yml +22 -0
  34. data/spec/finders/active_record_spec.rb +461 -0
  35. data/spec/finders/active_resource_spec.rb +52 -0
  36. data/spec/finders/activerecord_test_connector.rb +108 -0
  37. data/spec/finders/data_mapper_spec.rb +62 -0
  38. data/spec/finders/data_mapper_test_connector.rb +20 -0
  39. data/spec/finders/sequel_spec.rb +53 -0
  40. data/spec/finders/sequel_test_connector.rb +9 -0
  41. data/spec/finders_spec.rb +76 -0
  42. data/spec/fixtures/admin.rb +3 -0
  43. data/spec/fixtures/developer.rb +13 -0
  44. data/spec/fixtures/developers_projects.yml +13 -0
  45. data/spec/fixtures/project.rb +15 -0
  46. data/spec/fixtures/projects.yml +6 -0
  47. data/spec/fixtures/replies.yml +29 -0
  48. data/spec/fixtures/reply.rb +7 -0
  49. data/spec/fixtures/schema.rb +38 -0
  50. data/spec/fixtures/topic.rb +6 -0
  51. data/spec/fixtures/topics.yml +30 -0
  52. data/spec/fixtures/user.rb +2 -0
  53. data/spec/fixtures/users.yml +35 -0
  54. data/spec/rcov.opts +2 -0
  55. data/spec/spec.opts +2 -0
  56. data/spec/spec_helper.rb +75 -0
  57. data/spec/tasks.rake +60 -0
  58. data/spec/view_helpers/action_view_spec.rb +344 -0
  59. data/spec/view_helpers/base_spec.rb +64 -0
  60. data/spec/view_helpers/link_renderer_base_spec.rb +84 -0
  61. data/spec/view_helpers/view_example_group.rb +111 -0
  62. metadata +152 -0
@@ -0,0 +1,54 @@
1
+ Autotest.add_hook :initialize do |at|
2
+
3
+ at.libs = 'lib:spec'
4
+
5
+ at.clear_mappings
6
+
7
+ at.add_mapping(%r{^lib/will_paginate/(.+)\.rb$}) { |_, match|
8
+ "spec/#{match[1]}_spec.rb"
9
+ }
10
+ at.add_mapping(%r{^spec/.+_spec\.rb$}) { |f, _| f }
11
+ at.add_mapping(%r{^spec/(finders/activerecord_test_connector.rb|database.yml|fixtures/.+)$}) {
12
+ 'spec/finders/active_record_spec.rb'
13
+ }
14
+ at.add_mapping(%r{^spec/((spec_helper|shared/.+)\.rb|spec.opts)$}) {
15
+ # simply re-run all specs
16
+ at.files_matching %r{^spec/.+_spec\.rb$}
17
+ }
18
+
19
+ # add these to ignore list
20
+ %w{ .git test/ rails/ Rakefile README.rdoc init.rb .autotest
21
+ doc/ coverage/ LICENSE CHANGELOG .manifest will_paginate.gemspec examples/
22
+ spec/tasks.rake spec/console spec/rcov.opts
23
+ }.each { |path| at.add_exception path }
24
+
25
+ end
26
+
27
+ Autotest::Rspec.class_eval do
28
+ # RSpec guys forgot about `libs` in make_test_cmd
29
+ def make_test_cmd_with_libs(files_to_test)
30
+ make_test_cmd_without_libs(files_to_test).sub(' -S ', " -S -I#{libs} ")
31
+ end
32
+
33
+ alias :make_test_cmd_without_libs :make_test_cmd
34
+ alias :make_test_cmd :make_test_cmd_with_libs
35
+
36
+ # ugh, we have to monkeypatch Autotest ...
37
+ # the regexp it generates for the exception list just matches too much
38
+ #
39
+ # SOLUTION: wrap it up in another regexp that anchors the whole expression to
40
+ # the beginning of the path
41
+ def exceptions
42
+ unless defined? @exceptions then
43
+ if @exception_list.empty? then
44
+ @exceptions = nil
45
+ else
46
+ # old (BAD):
47
+ # @exceptions = Regexp.union(*@exception_list)
48
+ @exceptions = /^\.\/#{Regexp.union(*@exception_list)}/
49
+ end
50
+ end
51
+
52
+ @exceptions
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ /doc
2
+ /rails
3
+ *.gem
4
+ /coverage
@@ -0,0 +1,3 @@
1
+ [submodule "website"]
2
+ path = website
3
+ url = git@github.com:mislav/will_paginate.git
@@ -0,0 +1,61 @@
1
+ .autotest
2
+ .gitignore
3
+ .gitmodules
4
+ .manifest
5
+ CHANGELOG.rdoc
6
+ LICENSE
7
+ README.rdoc
8
+ Rakefile
9
+ init.rb
10
+ lib/will_paginate.rb
11
+ lib/will_paginate/array.rb
12
+ lib/will_paginate/collection.rb
13
+ lib/will_paginate/core_ext.rb
14
+ lib/will_paginate/deprecation.rb
15
+ lib/will_paginate/finders.rb
16
+ lib/will_paginate/finders/active_record.rb
17
+ lib/will_paginate/finders/active_record/named_scope.rb
18
+ lib/will_paginate/finders/active_record/named_scope_patch.rb
19
+ lib/will_paginate/finders/active_resource.rb
20
+ lib/will_paginate/finders/base.rb
21
+ lib/will_paginate/finders/data_mapper.rb
22
+ lib/will_paginate/finders/sequel.rb
23
+ lib/will_paginate/version.rb
24
+ lib/will_paginate/view_helpers.rb
25
+ lib/will_paginate/view_helpers/action_view.rb
26
+ lib/will_paginate/view_helpers/base.rb
27
+ lib/will_paginate/view_helpers/link_renderer.rb
28
+ lib/will_paginate/view_helpers/link_renderer_base.rb
29
+ lib/will_paginate/view_helpers/merb.rb
30
+ spec/collection_spec.rb
31
+ spec/console
32
+ spec/console_fixtures.rb
33
+ spec/database.yml
34
+ spec/finders/active_record_spec.rb
35
+ spec/finders/active_resource_spec.rb
36
+ spec/finders/activerecord_test_connector.rb
37
+ spec/finders/data_mapper_spec.rb
38
+ spec/finders/data_mapper_test_connector.rb
39
+ spec/finders/sequel_spec.rb
40
+ spec/finders/sequel_test_connector.rb
41
+ spec/finders_spec.rb
42
+ spec/fixtures/admin.rb
43
+ spec/fixtures/developer.rb
44
+ spec/fixtures/developers_projects.yml
45
+ spec/fixtures/project.rb
46
+ spec/fixtures/projects.yml
47
+ spec/fixtures/replies.yml
48
+ spec/fixtures/reply.rb
49
+ spec/fixtures/schema.rb
50
+ spec/fixtures/topic.rb
51
+ spec/fixtures/topics.yml
52
+ spec/fixtures/user.rb
53
+ spec/fixtures/users.yml
54
+ spec/rcov.opts
55
+ spec/spec.opts
56
+ spec/spec_helper.rb
57
+ spec/tasks.rake
58
+ spec/view_helpers/action_view_spec.rb
59
+ spec/view_helpers/base_spec.rb
60
+ spec/view_helpers/link_renderer_base_spec.rb
61
+ spec/view_helpers/view_example_group.rb
@@ -0,0 +1,105 @@
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
23
+
24
+ == 2.3.1, released 2008-05-04
25
+
26
+ * Fixed page numbers not showing with custom routes and implicit first page
27
+ * Try to use Hanna for documentation (falls back to default RDoc template if not)
28
+
29
+ == 2.3.0, released 2008-04-29
30
+
31
+ * Changed LinkRenderer to receive collection, options and reference to view template NOT in
32
+ constructor, but with the #prepare method. This is a step towards supporting passing of
33
+ LinkRenderer (or subclass) instances that may be preconfigured in some way
34
+ * LinkRenderer now has #page_link and #page_span methods for easier customization of output in
35
+ subclasses
36
+ * Changed page_entries_info() method to adjust its output according to humanized class name of
37
+ collection items. Override this with :entry_name parameter (singular).
38
+
39
+ page_entries_info(@posts)
40
+ #-> "Displaying all 12 posts"
41
+ page_entries_info(@posts, :entry_name => 'item')
42
+ #-> "Displaying all 12 items"
43
+
44
+ == 2.2.3, released 2008-04-26
45
+
46
+ * will_paginate gem is no longer published on RubyForge, but on
47
+ gems.github.com:
48
+
49
+ gem sources -a http://gems.github.com/ (you only need to do this once)
50
+ gem install mislav-will_paginate
51
+
52
+ * extract reusable pagination testing stuff into WillPaginate::View
53
+ * rethink the page URL construction mechanism to be more bulletproof when
54
+ combined with custom routing for page parameter
55
+ * test that anchor parameter can be used in pagination links
56
+
57
+ == 2.2.2, released 2008-04-21
58
+
59
+ * Add support for page parameter in custom routes like "/foo/page/2"
60
+ * Change output of "page_entries_info" on single-page collection and erroneous
61
+ output with empty collection as reported by Tim Chater
62
+
63
+ == 2.2.1, released 2008-04-08
64
+
65
+ * take less risky path when monkeypatching named_scope; fix that it no longer
66
+ requires ActiveRecord::VERSION
67
+ * use strings in "respond_to?" calls to work around a bug in acts_as_ferret
68
+ stable (ugh)
69
+ * add rake release task
70
+
71
+
72
+ == 2.2.0, released 2008-04-07
73
+
74
+ === API changes
75
+ * Rename WillPaginate::Collection#page_count to "total_pages" for consistency.
76
+ If you implemented this interface, change your implementation accordingly.
77
+ * Remove old, deprecated style of calling Array#paginate as "paginate(page,
78
+ per_page)". If you want to specify :page, :per_page or :total_entries, use a
79
+ parameter hash.
80
+ * Rename LinkRenderer#url_options to "url_for" and drastically optimize it
81
+
82
+ === View changes
83
+ * Added "prev_page" and "next_page" CSS classes on previous/next page buttons
84
+ * Add examples of pagination links styling in "examples/index.html"
85
+ * Change gap in pagination links from "..." to
86
+ "<span class="gap">&hellip;</span>".
87
+ * Add "paginated_section", a block helper that renders pagination both above and
88
+ below content in the block
89
+ * Add rel="prev|next|start" to page links
90
+
91
+ === Other
92
+
93
+ * Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
94
+ WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
95
+ * Support complex page parameters like "developers[page]"
96
+ * Move Array#paginate definition to will_paginate/array.rb. You can now easily
97
+ use pagination on arrays outside of Rails:
98
+
99
+ gem 'will_paginate'
100
+ require 'will_paginate/array'
101
+
102
+ * Add "paginated_each" method for iterating through every record by loading only
103
+ one page of records at the time
104
+ * Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
105
+ default
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2009 Mislav Marohnić
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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].
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ begin
3
+ hanna_dir = '/Users/mislav/Projects/Hanna/lib'
4
+ $:.unshift hanna_dir if File.exists? hanna_dir
5
+ require 'hanna/rdoctask'
6
+ rescue LoadError
7
+ require 'rake'
8
+ require 'rake/rdoctask'
9
+ end
10
+ load 'spec/tasks.rake'
11
+
12
+ desc 'Default: run specs.'
13
+ task :default => :spec
14
+
15
+ desc 'Generate RDoc documentation for the will_paginate plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'CHANGELOG.rdoc').
18
+ include('lib/**/*.rb').
19
+ exclude('lib/will_paginate/finders/active_record/named_scope*').
20
+ exclude('lib/will_paginate/finders/sequel.rb').
21
+ exclude('lib/will_paginate/view_helpers/merb.rb').
22
+ exclude('lib/will_paginate/deprecation.rb').
23
+ exclude('lib/will_paginate/core_ext.rb').
24
+ exclude('lib/will_paginate/version.rb')
25
+
26
+ rdoc.main = "README.rdoc" # page to start on
27
+ rdoc.title = "will_paginate documentation"
28
+
29
+ rdoc.rdoc_dir = 'doc' # rdoc output folder
30
+ rdoc.options << '--inline-source' << '--charset=UTF-8'
31
+ rdoc.options << '--webcvs=http://github.com/mislav/will_paginate/tree/master/'
32
+ end
33
+
34
+ desc %{Update ".manifest" with the latest list of project filenames. Respect\
35
+ .gitignore by excluding everything that git ignores. Update `files` and\
36
+ `test_files` arrays in "*.gemspec" file if it's present.}
37
+ task :manifest do
38
+ list = `git ls-files --full-name -x *.gemspec -x website`.chomp.split("\n")
39
+
40
+ if spec_file = Dir['*.gemspec'].first
41
+ spec = File.read spec_file
42
+ spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
43
+ assignment = $1
44
+ bunch = $2 ? list.grep(/^(test|spec)\//) : list
45
+ '%s%%w(%s)' % [assignment, bunch.join(' ')]
46
+ end
47
+
48
+ File.open(spec_file, 'w') { |f| f << spec }
49
+ end
50
+ File.open('.manifest', 'w') { |f| f << list.join("\n") }
51
+ end
52
+
53
+ task :website do
54
+ Dir.chdir('website') do
55
+ %x(haml index.haml index.html)
56
+ %x(sass pagination.sass pagination.css)
57
+ end
58
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'will_paginate'
@@ -0,0 +1,45 @@
1
+ require 'will_paginate/deprecation'
2
+
3
+ # = You *will* paginate!
4
+ #
5
+ # First read about WillPaginate::Finders::Base, then see
6
+ # WillPaginate::ViewHelpers. The magical array you're handling in-between is
7
+ # WillPaginate::Collection.
8
+ #
9
+ # Happy paginating!
10
+ module WillPaginate
11
+ # This method used to hook in ActiveRecord and ActionView at load time,
12
+ # but now doesn't do anything anymore and will be removed in future releases.
13
+ def self.enable
14
+ Deprecation.warn "WillPaginate::enable() doesn't do anything anymore"
15
+ end
16
+
17
+ # Enable named_scope, a feature of Rails 2.1, even if you have older Rails
18
+ # (tested on Rails 2.0.2 and 1.2.6).
19
+ #
20
+ # You can pass +false+ for +patch+ parameter to skip monkeypatching
21
+ # *associations*. Use this if you feel that <tt>named_scope</tt> broke
22
+ # has_many, has_many :through or has_and_belongs_to_many associations in
23
+ # your app. By passing +false+, you can still use <tt>named_scope</tt> in
24
+ # your models, but not through associations.
25
+ def self.enable_named_scope(patch = true)
26
+ return if defined? ActiveRecord::NamedScope
27
+ require 'will_paginate/finders/active_record/named_scope'
28
+ require 'will_paginate/finders/active_record/named_scope_patch' if patch
29
+
30
+ ActiveRecord::Base.send :include, WillPaginate::NamedScope
31
+ end
32
+ end
33
+
34
+ if defined?(Rails)
35
+ require 'will_paginate/view_helpers/action_view' if defined?(ActionController)
36
+ require 'will_paginate/finders/active_record' if defined?(ActiveRecord)
37
+ end
38
+
39
+ if defined?(Merb::Plugins)
40
+ require 'will_paginate/view_helpers/merb'
41
+ # auto-load the right ORM adapter
42
+ if adapter = { :datamapper => 'data_mapper', :activerecord => 'active_record', :sequel => 'sequel' }[Merb.orm]
43
+ require "will_paginate/finders/#{adapter}"
44
+ end
45
+ end