fix bug with pagination + add _permalink property for content instances

This commit is contained in:
dinedine 2010-10-26 15:06:57 +02:00
parent b4d3aae46f
commit 7cb26a74d4
4 changed files with 29 additions and 20 deletions

View File

@ -28,6 +28,7 @@ class ContentInstance
## methods ##
alias :visible? :_visible?
alias :_permalink :_slug
def site_id # needed by the uploader of custom fields
self.content_type.site_id

View File

@ -16,6 +16,9 @@ BOARD:
- increase the input field for domain names
- drag&drop for assets ('last' class issue)
- api
- handle html request (for now, it's just json)
- refactor slugify method (use parameterize + create a module)
- [content types] the "display column" selector should not include file types

View File

@ -18,29 +18,15 @@ module Locomotive
end
def first
content = @content_type.ordered_contents(@context['with_scope']).first
self.collection.first
end
def last
content = @content_type.ordered_contents(@context['with_scope']).last
self.collection.last
end
def each(&block)
@collection ||= @content_type.ordered_contents(@context['with_scope'])
@collection.each(&block)
end
def paginate(options = {})
@collection ||= @content_type.ordered_contents(@context['with_scope']).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
}
self.collection.each(&block)
end
def api
@ -55,6 +41,25 @@ module Locomotive
klass.send(meth)
end
end
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']) # remove per_page, page keys
end
end
end
end

View File

@ -36,13 +36,13 @@ module Locomotive
raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
pagination = collection.paginate({
pagination = collection.send(:paginate, {
:page => context['current_page'],
:per_page => @per_page }).stringify_keys!
:per_page => @per_page }).stringify_keys
page_count, current_page = pagination['total_pages'], pagination['current_page']
path = context['page'].path rescue '/'
path = context.registers[:page].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']