public
Fork of mislav/will_paginate
Description: Most awesome pagination solution for Rails
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/technoweenie/will_paginate.git
Search Repo:
Add page_entries_info view helper
mislav (author)
Thu Feb 28 07:36:42 -0800 2008
commit  be779fb538a841fd0a95dbe99cb650e38815a29a
tree    d1a9413fbd7e60c656f1c0672fbf1bef58ae6885
parent  6b77787c18d6e7947adbe2e55491459d64bc0564
...
96
97
98
 
 
 
 
 
 
 
 
 
 
 
 
 
99
100
101
102
103
 
104
105
106
...
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
 
115
116
117
118
0
@@ -96,11 +96,23 @@
0
       # render HTML for pagination
0
       renderer.to_html
0
     end
0
+
0
+ # Renders a helpful message with numbers of displayed vs. total entries.
0
+ # You can use this as a blueprint for your own, similar helpers.
0
+ #
0
+ # <%= page_entries_info @posts %>
0
+ # #-> Displaying entries 6 - 10 of 26 in total
0
+ def page_entries_info(collection)
0
+ %{Displaying entries <b>%d&nbsp;-&nbsp;%d</b> of <b>%d</b> in total} % [
0
+ collection.offset + 1,
0
+ collection.offset + collection.length,
0
+ collection.total_entries
0
+ ]
0
+ end
0
   end
0
 
0
   # This class does the heavy lifting of actually building the pagination
0
- # links. It is used by +will_paginate+ helper internally, but avoid using it
0
- # directly (for now) because its API is not set in stone yet.
0
+ # links. It is used by +will_paginate+ helper internally.
0
   class LinkRenderer
0
 
0
     def initialize(collection, options, template)
...
240
241
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
0
@@ -240,4 +240,19 @@
0
     end
0
   end
0
 end
0
+
0
+class ViewHelpersTest < Test::Unit::TestCase
0
+ include WillPaginate::ViewHelpers
0
+
0
+ def test_page_entries_info
0
+ arr = ('a'..'z').to_a
0
+ collection = arr.paginate :page => 2, :per_page => 5
0
+ assert_equal %{Displaying entries <b>6&nbsp;-&nbsp;10</b> of <b>26</b> in total},
0
+ page_entries_info(collection)
0
+
0
+ collection = arr.paginate :page => 7, :per_page => 4
0
+ assert_equal %{Displaying entries <b>25&nbsp;-&nbsp;26</b> of <b>26</b> in total},
0
+ page_entries_info(collection)
0
+ end
0
+end

Comments

    No one has commented yet.