Permalink
Browse files

nicer memoized #html_attributes accessor

  • Loading branch information...
1 parent aacfbca commit 5a0a11cf3487124e6eb7299cf416a8a0642d4d45 @mislav mislav committed Oct 12, 2008
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/will_paginate/view_helpers/link_renderer.rb
@@ -14,6 +14,7 @@ class LinkRenderer < LinkRendererBase
def prepare(collection, options, template)
super(collection, options)
@template = template
+ @html_attributes = nil
end
# Process it! This method returns the complete HTML string which contains
@@ -31,13 +32,14 @@ def to_html
# Returns the subset of +options+ this instance was initialized with that
# represent HTML attributes for the container element of pagination links.
def html_attributes
- return @html_attributes if @html_attributes
- @html_attributes = @options.except *(WillPaginate::ViewHelpers.pagination_options.keys - [:class])
- # pagination of Post models will have the ID of "posts_pagination"
- if @options[:container] and @options[:id] === true
- @html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
+ @html_attributes ||= begin
+ attributes = @options.except *(WillPaginate::ViewHelpers.pagination_options.keys - [:class])
+ # pagination of Post models will have the ID of "posts_pagination"
+ if @options[:container] and @options[:id] === true
+ attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
+ end
+ attributes
end
- @html_attributes
end
protected

0 comments on commit 5a0a11c

Please sign in to comment.