summaryrefslogtreecommitdiff
path: root/vendor/plugins/will_paginate/lib/will_paginate.rb
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/plugins/will_paginate/lib/will_paginate.rb')
-rw-r--r--vendor/plugins/will_paginate/lib/will_paginate.rb78
1 files changed, 0 insertions, 78 deletions
diff --git a/vendor/plugins/will_paginate/lib/will_paginate.rb b/vendor/plugins/will_paginate/lib/will_paginate.rb
deleted file mode 100644
index e072412..0000000
--- a/vendor/plugins/will_paginate/lib/will_paginate.rb
+++ /dev/null
@@ -1,78 +0,0 @@
1require 'active_support'
2
3# = You *will* paginate!
4#
5# First read about WillPaginate::Finder::ClassMethods, then see
6# WillPaginate::ViewHelpers. The magical array you're handling in-between is
7# WillPaginate::Collection.
8#
9# Happy paginating!
10module WillPaginate
11 class << self
12 # shortcut for <tt>enable_actionpack</tt> and <tt>enable_activerecord</tt> combined
13 def enable
14 enable_actionpack
15 enable_activerecord
16 end
17
18 # hooks WillPaginate::ViewHelpers into ActionView::Base
19 def enable_actionpack
20 return if ActionView::Base.instance_methods.include? 'will_paginate'
21 require 'will_paginate/view_helpers'
22 ActionView::Base.send :include, ViewHelpers
23
24 if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
25 ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
26 end
27 end
28
29 # hooks WillPaginate::Finder into ActiveRecord::Base and classes that deal
30 # with associations
31 def enable_activerecord
32 return if ActiveRecord::Base.respond_to? :paginate
33 require 'will_paginate/finder'
34 ActiveRecord::Base.send :include, Finder
35
36 # support pagination on associations
37 a = ActiveRecord::Associations
38 returning([ a::AssociationCollection ]) { |classes|
39 # detect http://dev.rubyonrails.org/changeset/9230
40 unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
41 classes << a::HasManyThroughAssociation
42 end
43 }.each do |klass|
44 klass.send :include, Finder::ClassMethods
45 klass.class_eval { alias_method_chain :method_missing, :paginate }
46 end
47 end
48
49 # Enable named_scope, a feature of Rails 2.1, even if you have older Rails
50 # (tested on Rails 2.0.2 and 1.2.6).
51 #
52 # You can pass +false+ for +patch+ parameter to skip monkeypatching
53 # *associations*. Use this if you feel that <tt>named_scope</tt> broke
54 # has_many, has_many :through or has_and_belongs_to_many associations in
55 # your app. By passing +false+, you can still use <tt>named_scope</tt> in
56 # your models, but not through associations.
57 def enable_named_scope(patch = true)
58 return if defined? ActiveRecord::NamedScope
59 require 'will_paginate/named_scope'
60 require 'will_paginate/named_scope_patch' if patch
61
62 ActiveRecord::Base.send :include, WillPaginate::NamedScope
63 end
64 end
65
66 module Deprecation # :nodoc:
67 extend ActiveSupport::Deprecation
68
69 def self.warn(message, callstack = caller)
70 message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
71 ActiveSupport::Deprecation.warn(message, callstack)
72 end
73 end
74end
75
76if defined?(Rails) and defined?(ActiveRecord) and defined?(ActionController)
77 WillPaginate.enable
78end