Permalink
Browse files

first version that works with Merb -> add a Merb inclusion hook

  • Loading branch information...
1 parent 2039231 commit ba7096b68e320729338376954d30e9072b91a3e8 @mislav mislav committed Oct 12, 2008
@@ -33,3 +33,11 @@ def self.enable_named_scope(patch = true)
require 'will_paginate/view_helpers/action_view' if defined?(ActionController)
require 'will_paginate/finders/active_record' if defined?(ActiveRecord)
end
+
+if defined?(Merb::Plugins)
+ require 'will_paginate/collection'
+ require 'will_paginate/view_helpers/base'
+ require 'will_paginate/view_helpers/link_renderer'
+ # this only includes will_paginate view stuff in Merb (not finder adapters)
+ Merb::AbstractController.send(:include, WillPaginate::ViewHelpers::Base)
+end
@@ -68,3 +68,15 @@ def infer_collection_from_controller
if defined?(ActionController::Base) and ActionController::Base.respond_to? :rescue_responses
ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
end
+
+WillPaginate::ViewHelpers::LinkRenderer.class_eval do
+ protected
+
+ def default_url_params
+ { :escape => false }
+ end
+
+ def generate_url(params)
+ @template.url_for(params)
+ end
+end
@@ -82,29 +82,35 @@ def html_container(html)
# and <tt>:params</tt> option into account.
def url(page)
@base_url_params ||= begin
- url_params = default_url_params
+ url_params = base_url_params
merge_optional_params(url_params)
url_params
end
url_params = @base_url_params.dup
add_current_page_param(url_params, page)
- @template.url_for(url_params)
+ generate_url(url_params)
end
def default_url_params
- url_params = { :escape => false }
- if @template.request.get?
- # page links should preserve GET parameters
- symbolized_update(url_params, @template.params)
- end
+ { }
+ end
+
+ def base_url_params
+ url_params = default_url_params
+ # page links should preserve GET parameters
+ symbolized_update(url_params, @template.params) if get_request?
url_params
end
+ def merge_optional_params(url_params)
+ symbolized_update(url_params, @options[:params]) if @options[:params]
+ end
+
def add_current_page_param(url_params, page)
unless param_name.index(/[^\w-]/)
- url_params[param_name] = page
+ url_params[param_name.to_sym] = page
else
page_param = (defined?(CGIMethods) ? CGIMethods : ActionController::AbstractRequest).
parse_query_parameters(param_name + '=' + page.to_s)
@@ -113,8 +119,12 @@ def add_current_page_param(url_params, page)
end
end
- def merge_optional_params(url_params)
- symbolized_update(url_params, @options[:params]) if @options[:params]
+ def get_request?
+ @template.request.get?
+ end
+
+ def generate_url(params)
+ @template.url(params)
end
private

0 comments on commit ba7096b

Please sign in to comment.