rughetto-merb_paginate 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/merb_paginate/view_helpers.rb +8 -19
  2. metadata +1 -1
@@ -59,7 +59,6 @@ module MerbPaginate
59
59
  # * <tt>:outer_window</tt> -- how many links are around the first and the last page (default: 1)
60
60
  # * <tt>:separator</tt> -- string separator for page HTML elements (default: single space)
61
61
  # * <tt>:param_name</tt> -- parameter name for page number in URLs (default: <tt>:page</tt>)
62
- # * <tt>:named_route</tt> -- optional named route used to generate the pagination url
63
62
  # * <tt>:params</tt> -- additional parameters when generating pagination links
64
63
  # (eg. <tt>:controller => "foo", :action => nil</tt>)
65
64
  # * <tt>:renderer</tt> -- class name of the link renderer (default: WillPaginate::LinkRenderer)
@@ -226,29 +225,19 @@ module MerbPaginate
226
225
  def page_link_or_span(page, span_class = 'current', text = nil)
227
226
  text ||= page.to_s
228
227
  if page and page != current_page
229
- "<a href=\"#{url_options_string(page)}\">#{text}</a>"
228
+ "<a href=\"#{url_for_page(page)}\">#{text}</a>"
230
229
  else
231
230
  "<span class=\"#{span_class}\">#{text}</span>"
232
231
  end
233
232
  end
234
233
 
235
- # TODO: I am not sure if I like the way this is working. It will always do /posts/index?page=1 for page one when it could do /
236
- # Would be nice if it was smarter
237
- def url_options(page)
238
- options = { param_name => page }
239
-
240
- # page links should preserve GET parameters
241
- options = @template.request.params.merge(options).except('action', 'controller', 'format', *Array(@options[:except])) if @template.request.method == :get
242
- options.rec_merge!(@options[:params]) if @options[:params]
243
- return options
244
- end
245
-
246
- def url_options_string(page)
247
- if @options[:named_route]
248
- @template.url(@options[:named_route], url_options(page))
249
- else
250
- @template.url(url_options(page))
251
- end
234
+ def url_for_page(page)
235
+ # Include all query params when constructing new paging URL
236
+ params = @template.params.to_a.reject{|i| ['namespace', 'controller', 'action', 'format'].include?(i[0]) }
237
+ params << [param_name, page]
238
+ params = params.map{|i| i.join('=')}.join('&')
239
+
240
+ @template.request.path + "?" + params
252
241
  end
253
242
 
254
243
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rughetto-merb_paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Herald