public
Rubygem
Description: Most awesome pagination solution for Rails
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Search Repo:
changed page_entries_info() method to adjust its output according to 
humanized class name of collection items.

  page_entries_info(@posts)  #->  "Displaying all 12 posts"

Override this with :entry_name parameter.
mislav (author)
Tue Apr 29 11:59:21 -0700 2008
commit  cc485b2cc28cfdb306d8f04879d760043f03833c
tree    2ffea50a03cc25eada975766977658dea3768a05
parent  eacdb75555d7839b3d7da952c2fc65cd7516a6a3
...
131
132
133
134
135
 
 
 
136
137
138
...
131
132
133
 
 
134
135
136
137
138
139
0
@@ -131,8 +131,9 @@
0
     #
0
     # <%= page_entries_info @posts %>
0
     # #-> Displaying entries 6 - 10 of 26 in total
0
- def page_entries_info(collection, opts = {})
0
- entry_name = opts[:entry_name] || 'entry'
0
+ def page_entries_info(collection, options = {})
0
+ entry_name = options[:entry_name] ||
0
+ (collection.empty?? 'entry' : collection.first.class.name.underscore.sub('_', ' '))
0
       
0
       if collection.total_pages < 2
0
         case collection.size
...
135
136
137
138
 
139
140
141
142
 
143
144
145
 
 
 
 
 
 
 
 
 
146
147
148
149
150
 
151
152
153
 
154
155
156
...
172
173
174
175
176
177
178
179
180
181
...
135
136
137
 
138
139
140
141
 
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
 
159
160
161
 
162
163
164
165
...
181
182
183
 
 
 
 
184
185
186
0
@@ -135,22 +135,31 @@
0
     array = ('a'..'z').to_a
0
     
0
     paginate array.paginate(:page => 2, :per_page => 5)
0
- assert_equal %{Displaying entries <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total},
0
+ assert_equal %{Displaying strings <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total},
0
       @html_result
0
     
0
     paginate array.paginate(:page => 7, :per_page => 4)
0
- assert_equal %{Displaying entries <b>25&nbsp;-&nbsp;26</b> of <b>26</b> in total},
0
+ assert_equal %{Displaying strings <b>25&nbsp;-&nbsp;26</b> of <b>26</b> in total},
0
       @html_result
0
   end
0
 
0
+ def test_page_entries_info_with_longer_class_name
0
+ @template = '<%= page_entries_info collection %>'
0
+ collection = ('a'..'z').to_a.paginate
0
+ collection.first.stubs(:class).returns(mock('class', :name => 'ProjectType'))
0
+
0
+ paginate collection
0
+ assert @html_result.index('project types'), "expected <#{@html_result.inspect}> to mention 'project types'"
0
+ end
0
+
0
   def test_page_entries_info_with_single_page_collection
0
     @template = '<%= page_entries_info collection %>'
0
     
0
     paginate(('a'..'d').to_a.paginate(:page => 1, :per_page => 5))
0
- assert_equal %{Displaying <b>all 4</b> entries}, @html_result
0
+ assert_equal %{Displaying <b>all 4</b> strings}, @html_result
0
     
0
     paginate(['a'].paginate(:page => 1, :per_page => 5))
0
- assert_equal %{Displaying <b>1</b> entry}, @html_result
0
+ assert_equal %{Displaying <b>1</b> string}, @html_result
0
     
0
     paginate([].paginate(:page => 1, :per_page => 5))
0
     assert_equal %{No entries found}, @html_result
0
@@ -172,10 +181,6 @@
0
     
0
     paginate([].paginate(:page => 1, :per_page => 5))
0
     assert_equal %{No authors found}, @html_result
0
-
0
- @template = '<%= page_entries_info collection %>'
0
- paginate([].paginate(:page => 1, :per_page => 5))
0
- assert_equal %{No entries found}, @html_result
0
   end
0
   
0
   ## parameter handling in page links ##

Comments

    No one has commented yet.