Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 69 lines (59 sloc) 2.149 kB
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
1 require 'will_paginate'
dc588e6 @mislav fix handling WillPaginate::InvalidPage exceptions in Rails
authored
2 require 'will_paginate/page_number'
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
3 require 'will_paginate/collection'
9d200f9 @mislav extract translate helpers into WillPaginate::I18n module
authored
4 require 'will_paginate/i18n'
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
5
6 module WillPaginate
7 class Railtie < Rails::Railtie
87d0dba @mislav simplify railtie; remove unnecessary requires
authored
8 initializer "will_paginate" do |app|
35216e2 @matthuhiggins Use autoloading in Railtie so that framework loading isn't triggered …
matthuhiggins authored
9 ActiveSupport.on_load :active_record do
4d260bc @mislav mix in Active Record/Action View directly on `require`
authored
10 require 'will_paginate/active_record'
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
11 end
87d0dba @mislav simplify railtie; remove unnecessary requires
authored
12
35216e2 @matthuhiggins Use autoloading in Railtie so that framework loading isn't triggered …
matthuhiggins authored
13 ActiveSupport.on_load :action_controller do
005b871 @mislav enable will_paginate to load as a plugin
authored
14 WillPaginate::Railtie.setup_actioncontroller
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
15 end
87d0dba @mislav simplify railtie; remove unnecessary requires
authored
16
35216e2 @matthuhiggins Use autoloading in Railtie so that framework loading isn't triggered …
matthuhiggins authored
17 ActiveSupport.on_load :action_view do
4d260bc @mislav mix in Active Record/Action View directly on `require`
authored
18 require 'will_paginate/view_helpers/action_view'
35216e2 @matthuhiggins Use autoloading in Railtie so that framework loading isn't triggered …
matthuhiggins authored
19 end
f1fba71 @mislav have no fear, i18n is here!
authored
20
005b871 @mislav enable will_paginate to load as a plugin
authored
21 self.class.add_locale_path config
be12b56 @mislav enable access to ViewHelpers.pagination_options for Rails initializers
authored
22
23 # early access to ViewHelpers.pagination_options
24 require 'will_paginate/view_helpers'
005b871 @mislav enable will_paginate to load as a plugin
authored
25 end
26
27 def self.setup_actioncontroller
6f4390b @mislav fix handling InvalidPage exceptions in Rails 3.2
authored
28 ( defined?(ActionDispatch::ExceptionWrapper) ?
29 ActionDispatch::ExceptionWrapper : ActionDispatch::ShowExceptions
30 ).send :include, ShowExceptionsPatch
dc588e6 @mislav fix handling WillPaginate::InvalidPage exceptions in Rails
authored
31 ActionController::Base.extend ControllerRescuePatch
005b871 @mislav enable will_paginate to load as a plugin
authored
32 end
33
34 def self.add_locale_path(config)
9d200f9 @mislav extract translate helpers into WillPaginate::I18n module
authored
35 config.i18n.railties_load_path.unshift(*WillPaginate::I18n.load_path)
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
36 end
dc588e6 @mislav fix handling WillPaginate::InvalidPage exceptions in Rails
authored
37
38 # Extending the exception handler middleware so it properly detects
39 # WillPaginate::InvalidPage regardless of it being a tag module.
40 module ShowExceptionsPatch
41 extend ActiveSupport::Concern
42 included { alias_method_chain :status_code, :paginate }
e5e6c47 @mislav fix the ExceptionWrapper patch
authored
43 def status_code_with_paginate(exception = @exception)
dc588e6 @mislav fix handling WillPaginate::InvalidPage exceptions in Rails
authored
44 if exception.is_a?(WillPaginate::InvalidPage) or
45 (exception.respond_to?(:original_exception) &&
46 exception.original_exception.is_a?(WillPaginate::InvalidPage))
47 Rack::Utils.status_code(:not_found)
48 else
e5e6c47 @mislav fix the ExceptionWrapper patch
authored
49 original_method = method(:status_code_without_paginate)
50 if original_method.arity != 0
51 original_method.call(exception)
52 else
53 original_method.call()
54 end
dc588e6 @mislav fix handling WillPaginate::InvalidPage exceptions in Rails
authored
55 end
56 end
57 end
58
59 module ControllerRescuePatch
60 def rescue_from(*args, &block)
61 if idx = args.index(WillPaginate::InvalidPage)
62 args[idx] = args[idx].name
63 end
64 super(*args, &block)
65 end
66 end
0c35f28 @mislav cleanup Rails bootstrapping and move it to a Railtie
authored
67 end
68 end
Something went wrong with that request. Please try again.