diff --git a/app/models/content_instance.rb b/app/models/content_instance.rb index 37148bae..f2ed4aaa 100644 --- a/app/models/content_instance.rb +++ b/app/models/content_instance.rb @@ -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 diff --git a/doc/TODO b/doc/TODO index 75e07ef5..58c19657 100644 --- a/doc/TODO +++ b/doc/TODO @@ -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 diff --git a/lib/locomotive/liquid/drops/contents.rb b/lib/locomotive/liquid/drops/contents.rb index fc0e77c7..46710f55 100644 --- a/lib/locomotive/liquid/drops/contents.rb +++ b/lib/locomotive/liquid/drops/contents.rb @@ -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 diff --git a/lib/locomotive/liquid/tags/paginate.rb b/lib/locomotive/liquid/tags/paginate.rb index f21ce22d..eb41575a 100644 --- a/lib/locomotive/liquid/tags/paginate.rb +++ b/lib/locomotive/liquid/tags/paginate.rb @@ -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']