From 786d2d969312757d37e4f826c095aa3deab7bb21 Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Mon, 24 Oct 2011 23:44:35 +0800 Subject: [PATCH] Added will paginate to liquid. --- config/initializers/will_paginate.rb | 1 + .../liquid/drops/will_paginate_extension.rb | 13 +++++++++++++ lib/locomotive/liquid/tags/paginate.rb | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/locomotive/liquid/drops/will_paginate_extension.rb diff --git a/config/initializers/will_paginate.rb b/config/initializers/will_paginate.rb index dfed3fe9..e808301f 100644 --- a/config/initializers/will_paginate.rb +++ b/config/initializers/will_paginate.rb @@ -1 +1,2 @@ require 'will_paginate/array' +require 'locomotive/liquid/drops/will_paginate_extension' diff --git a/lib/locomotive/liquid/drops/will_paginate_extension.rb b/lib/locomotive/liquid/drops/will_paginate_extension.rb new file mode 100644 index 00000000..a1d0910e --- /dev/null +++ b/lib/locomotive/liquid/drops/will_paginate_extension.rb @@ -0,0 +1,13 @@ +class WillPaginate::Collection + def to_liquid + { + :collection => self.to_a, + :current_page => current_page, + :previous_page => previous_page, + :next_page => next_page, + :total_entries => total_entries, + :total_pages => total_pages, + :per_page => per_page + } + end +end diff --git a/lib/locomotive/liquid/tags/paginate.rb b/lib/locomotive/liquid/tags/paginate.rb index 7bac6fcb..4844ef93 100644 --- a/lib/locomotive/liquid/tags/paginate.rb +++ b/lib/locomotive/liquid/tags/paginate.rb @@ -38,7 +38,7 @@ module Locomotive pagination = collection.send(:paginate, { :page => context['current_page'], - :per_page => @per_page }).stringify_keys + :per_page => @per_page }).to_liquid.stringify_keys page_count, current_page = pagination['total_pages'], pagination['current_page']