Permalink
Browse files

The page_entries_info helper can now be called without any arguments …

…just as the will_paginate helper
  • Loading branch information...
1 parent 6be4a96 commit eacd19ac867be7741c7eaddccbf3e81bcc8e8a59 @pietern pietern committed with mislav Oct 9, 2008
Showing with 20 additions and 8 deletions.
  1. +18 −6 lib/will_paginate/view_helpers/action_view.rb
  2. +2 −2 lib/will_paginate/view_helpers/base.rb
@@ -11,16 +11,18 @@ module ActionView
def will_paginate(collection = nil, options = {})
options, collection = collection, nil if collection.is_a? Hash
- unless collection or !controller
- collection_name = "@#{controller.controller_name}"
- collection = instance_variable_get(collection_name)
- raise ArgumentError, "The #{collection_name} variable appears to be empty. Did you " +
- "forget to pass the collection object for will_paginate?" unless collection
- end
+ collection ||= infer_collection_from_controller
super(collection, options.symbolize_keys)
end
+ def page_entries_info(collection = nil, options = {})
+ options, collection = collection, nil if collection.is_a? Hash
+ collection ||= infer_collection_from_controller
+
+ super(collection, options.symbolize_keys)
+ end
+
# Wrapper for rendering pagination links at both top and bottom of a block
# of content.
#
@@ -48,6 +50,16 @@ def paginated_section(*args, &block)
content = pagination + capture(&block) + pagination
concat content, block.binding
end
+
+ protected
+
+ def infer_collection_from_controller
+ collection_name = "@#{controller.controller_name}"
+ collection = instance_variable_get(collection_name)
+ raise ArgumentError, "The #{collection_name} variable appears to be empty. Did you " +
+ "forget to pass the collection object for will_paginate?" if collection.nil?
+ collection
+ end
end
end
end
@@ -95,8 +95,8 @@ def will_paginate(collection, options = {})
# By default, this method produces HTML output. You can trigger plain
# text output by passing <tt>:html => false</tt> in options.
def page_entries_info(collection, options = {})
- entry_name = options[:entry_name] || (collection.empty?? 'entry' :
- collection.first.class.name.underscore.gsub('_', ' '))
+ entry_name = options[:entry_name] || (collection.empty?? 'entry' :
+ collection.first.class.name.underscore.gsub('_', ' '))
plural_name = if options[:plural_name]
options[:plural_name]

0 comments on commit eacd19a

Please sign in to comment.