Arrays now paginate correctly.

This commit is contained in:
Mario Visic 2011-10-24 22:35:21 +08:00
parent 2c5407d588
commit 25441ff60a
5 changed files with 24 additions and 13 deletions

View File

@ -0,0 +1,5 @@
class Array
def to_liquid
Locomotive::Liquid::Drops::Base.new(self)
end
end

View File

@ -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)

View File

@ -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

View File

@ -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']

View File

@ -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