tracks/vendor/plugins/will_paginate/lib/will_paginate.rb
Luke Melia 901a58f8a3 Upgraded to Rails 2.1. This can have wide ranging consequences, so please help track down any issues introduced by the upgrade. Requires environment.rb modifications.
Changes you will need to make:

 * In your environment.rb, you will need to update references to a few files per environment.rb.tmpl
 * In your environment.rb, you will need to specify the local time zone of the computer that is running your Tracks install.

Other notes on my changes:

 * Modified our code to take advantage of Rails 2.1's slick time zone support.
 * Upgraded will_paginate for compatibility
 * Hacked the Selenium on Rails plugin, which has not been updated in some time and does not support Rails 2.1
 * Verified that all tests pass on my machine, including Selenium tests -- I'd like confirmation from others, too.
2008-06-17 01:13:25 -04:00

86 lines
2.8 KiB
Ruby

require 'active_support'
# = You *will* paginate!
#
# First read about WillPaginate::Finder::ClassMethods, then see
# WillPaginate::ViewHelpers. The magical array you're handling in-between is
# WillPaginate::Collection.
#
# Happy paginating!
module WillPaginate
class << self
# shortcut for <tt>enable_actionpack; enable_activerecord</tt>
def enable
enable_actionpack
enable_activerecord
end
# mixes in WillPaginate::ViewHelpers in ActionView::Base
def enable_actionpack
return if ActionView::Base.instance_methods.include? 'will_paginate'
require 'will_paginate/view_helpers'
ActionView::Base.class_eval { include ViewHelpers }
if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
end
end
# mixes in WillPaginate::Finder in ActiveRecord::Base and classes that deal
# with associations
def enable_activerecord
return if ActiveRecord::Base.respond_to? :paginate
require 'will_paginate/finder'
ActiveRecord::Base.class_eval { include Finder }
# support pagination on associations
a = ActiveRecord::Associations
returning([ a::AssociationCollection ]) { |classes|
# detect http://dev.rubyonrails.org/changeset/9230
unless a::HasManyThroughAssociation.superclass == a::HasManyAssociation
classes << a::HasManyThroughAssociation
end
}.each do |klass|
klass.class_eval do
include Finder::ClassMethods
alias_method_chain :method_missing, :paginate
end
end
end
# Enable named_scope, a feature of Rails 2.1, even if you have older Rails
# (tested on Rails 2.0.2 and 1.2.6).
#
# You can pass +false+ for +patch+ parameter to skip monkeypatching
# *associations*. Use this if you feel that <tt>named_scope</tt> broke
# has_many, has_many :through or has_and_belongs_to_many associations in
# your app. By passing +false+, you can still use <tt>named_scope</tt> in
# your models, but not through associations.
def enable_named_scope(patch = true)
return if defined? ActiveRecord::NamedScope
require 'will_paginate/named_scope'
require 'will_paginate/named_scope_patch' if patch
ActiveRecord::Base.class_eval do
include WillPaginate::NamedScope
end
end
end
module Deprecation #:nodoc:
extend ActiveSupport::Deprecation
def self.warn(message, callstack = caller)
message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
behavior.call(message, callstack) if behavior && !silenced?
end
def self.silenced?
ActiveSupport::Deprecation.silenced?
end
end
end
if defined?(Rails) and defined?(ActiveRecord) and defined?(ActionController)
WillPaginate.enable
end