Skip to content

Instantly share code, notes, and snippets.

@keithpitt
Created May 23, 2011 09:20
Show Gist options
  • Save keithpitt/986456 to your computer and use it in GitHub Desktop.
Save keithpitt/986456 to your computer and use it in GitHub Desktop.
Locomotive params extra support
+++ b/lib/locomotive/liquid/tags/paginate.rb
@@ -42,7 +42,7 @@ module Locomotive
page_count, current_page = pagination['total_pages'], pagination['current_page']
- path = context.registers[:page].fullpath
+ path = context.registers[:controller].request.fullpath
pagination['previous'] = link(I18n.t('pagination.previous'), current_page - 1, path) if pagination['previous_page']
pagination['next'] = link(I18n.t('pagination.next'), current_page + 1, path) if pagination['next_page']
@@ -88,7 +88,15 @@ module Locomotive
end
def link(title, page, path)
- { 'title' => title, 'url' => path + "?page=#{page}", 'is_link' => true}
+ regex = /((\?|\&)page=\d+)/
+ if path.match(regex)
+ path = path.gsub(regex, "\\2page=#{page}")
+ elsif path.match(/\?/)
+ path = "#{path}&page=#{page}"
+ else
+ path = "#{path}?page=#{page}"
+ end
+ { 'title' => title, 'url' => path, 'is_link' => true}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment