From 25441ff60ace2ec3068a4a657303ea355ba0877e Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Mon, 24 Oct 2011 22:35:21 +0800 Subject: [PATCH] Arrays now paginate correctly. --- lib/locomotive/liquid/drops/array_extension.rb | 5 +++++ lib/locomotive/liquid/drops/base.rb | 17 +++++++++++++++++ lib/locomotive/liquid/drops/contents.rb | 13 ------------- lib/locomotive/liquid/tags/paginate.rb | 1 + lib/locomotive/render.rb | 1 + 5 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 lib/locomotive/liquid/drops/array_extension.rb diff --git a/lib/locomotive/liquid/drops/array_extension.rb b/lib/locomotive/liquid/drops/array_extension.rb new file mode 100644 index 00000000..0584ff8f --- /dev/null +++ b/lib/locomotive/liquid/drops/array_extension.rb @@ -0,0 +1,5 @@ +class Array + def to_liquid + Locomotive::Liquid::Drops::Base.new(self) + end +end diff --git a/lib/locomotive/liquid/drops/base.rb b/lib/locomotive/liquid/drops/base.rb index f5717f5f..7abd618d 100644 --- a/lib/locomotive/liquid/drops/base.rb +++ b/lib/locomotive/liquid/drops/base.rb @@ -30,6 +30,23 @@ module Locomotive records end + def paginate(options = {}) + @collection = self.collection.paginate(options) + { + :collection => @collection, + :current_page => @collection.current_page, + :previous_page => @collection.previous_page, + :next_page => @collection.next_page, + :total_entries => @collection.total_entries, + :total_pages => @collection.total_pages, + :per_page => @collection.per_page + } + end + + def collection + @_source + end + protected def liquify(*records, &block) diff --git a/lib/locomotive/liquid/drops/contents.rb b/lib/locomotive/liquid/drops/contents.rb index 691e5c9f..c0aefc0d 100644 --- a/lib/locomotive/liquid/drops/contents.rb +++ b/lib/locomotive/liquid/drops/contents.rb @@ -63,19 +63,6 @@ module Locomotive protected - def paginate(options = {}) - @collection = self.collection.paginate(options) - { - :collection => @collection, - :current_page => @collection.current_page, - :previous_page => @collection.previous_page, - :next_page => @collection.next_page, - :total_entries => @collection.total_entries, - :total_pages => @collection.total_pages, - :per_page => @collection.per_page - } - end - def collection @collection ||= @content_type.ordered_contents(@context['with_scope']) end diff --git a/lib/locomotive/liquid/tags/paginate.rb b/lib/locomotive/liquid/tags/paginate.rb index eb41575a..31560382 100644 --- a/lib/locomotive/liquid/tags/paginate.rb +++ b/lib/locomotive/liquid/tags/paginate.rb @@ -43,6 +43,7 @@ module Locomotive page_count, current_page = pagination['total_pages'], pagination['current_page'] path = context.registers[:page].fullpath + path = context['path'] 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'] diff --git a/lib/locomotive/render.rb b/lib/locomotive/render.rb index d17d2d20..ea52a817 100644 --- a/lib/locomotive/render.rb +++ b/lib/locomotive/render.rb @@ -65,6 +65,7 @@ module Locomotive 'contents' => Locomotive::Liquid::Drops::Contents.new, 'current_page' => self.params[:page], 'params' => self.params, + 'path' => request.path, 'url' => request.url, 'now' => Time.now.utc, 'today' => Date.today