public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
Break LinkRenderer#windowed_paginator into 2 methods: `windowed_links` and 
`visible_page_numbers`.  References #186  [Bryan Helmkamp]


git-svn-id: svn://errtheblog.com/svn/plugins/will_paginate@448 
1eaa51fe-a21a-0410-9c2e-ae7a00a434c4
mislav (author)
Sat Feb 23 12:39:03 -0800 2008
commit  b21179cc9e28a4fa39500ca936e18d6ccd99247c
tree    783fa70bc5bf444be2ff59330818debbac379888
parent  6a3be1e668b5326c4131ad0fbe0258755f12b6d7
0
...
125
126
127
128
 
129
130
131
...
125
126
127
 
128
129
130
131
0
@@ -125,7 +125,7 @@ contributions or simply awesome ideas:
0
 
0
 Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
0
 Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
0
-van Zuijlen, Maria, Brendan Ribera, Todd Willey.
0
+van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp.
0
 
0
 == Usable pagination in the UI
0
 
...
110
111
112
113
 
114
115
116
...
133
134
135
136
 
 
 
 
 
 
 
 
 
 
 
 
 
137
138
139
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
166
167
 
168
169
170
...
110
111
112
 
113
114
115
116
...
133
134
135
 
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
...
164
165
166
 
 
167
 
 
 
 
 
 
 
 
168
169
 
170
171
172
173
0
@@ -110,7 +110,7 @@ module WillPaginate
0
     end
0
 
0
     def to_html
0
- links = @options[:page_links] ? windowed_paginator : []
0
+ links = @options[:page_links] ? windowed_links : []
0
       # previous/next buttons
0
       links.unshift page_link_or_span(@collection.previous_page, 'disabled', @options[:prev_label])
0
       links.push page_link_or_span(@collection.next_page, 'disabled', @options[:next_label])
0
@@ -133,7 +133,19 @@ module WillPaginate
0
 
0
     def gap_marker; '...'; end
0
     
0
- def windowed_paginator
0
+ def windowed_links
0
+ prev = nil
0
+
0
+ visible_page_numbers.inject [] do |links, n|
0
+ # detect gaps:
0
+ links << gap_marker if prev and n > prev + 1
0
+ links << page_link_or_span(n)
0
+ prev = n
0
+ links
0
+ end
0
+ end
0
+
0
+ def visible_page_numbers
0
       inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i
0
       window_from = current_page - inner_window
0
       window_to = current_page + inner_window
0
@@ -152,19 +164,10 @@ module WillPaginate
0
       right_gap = (window_to + 1)...(total_pages - outer_window)
0
       visible -= left_gap.to_a if left_gap.last - left_gap.first > 1
0
       visible -= right_gap.to_a if right_gap.last - right_gap.first > 1
0
-
0
- links, prev = [], nil
0
 
0
- visible.each do |n|
0
- # detect gaps:
0
- links << gap_marker if prev and n > prev + 1
0
- links << page_link_or_span(n)
0
- prev = n
0
- end
0
-
0
- links
0
+ visible
0
     end
0
-
0
+
0
     def page_link_or_span(page, span_class = 'current', text = nil)
0
       text ||= page.to_s
0
       if page and page != current_page

Comments

    No one has commented yet.