lib/locomotive/liquid/drops/contents.rb in locomotive_cms-0.0.4.beta12 vs lib/locomotive/liquid/drops/contents.rb in locomotive_cms-0.0.4

- old
+ new

@@ -16,38 +16,24 @@ @content_type = content_type @collection = nil end def first - self.collection.first + content = @content_type.ordered_contents(@context['with_scope']).first end def last - self.collection.last + content = @content_type.ordered_contents(@context['with_scope']).last end def each(&block) - self.collection.each(&block) + @collection ||= @content_type.ordered_contents(@context['with_scope']) + @collection.each(&block) end - def api - { 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) } - end - - def before_method(meth) - klass = @content_type.contents.klass # delegate to the proxy class - if (meth.to_s =~ /^group_by_.+$/) == 0 - klass.send(meth, :ordered_contents) - else - klass.send(meth) - end - end - - protected - def paginate(options = {}) - @collection = self.collection.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, @@ -55,11 +41,20 @@ :total_pages => @collection.total_pages, :per_page => @collection.per_page } end - def collection - @collection ||= @content_type.ordered_contents(@context['with_scope']) + def api + { 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) } + end + + def before_method(meth) + klass = @content_type.contents.klass # delegate to the proxy class + if (meth.to_s =~ /^group_by_.+$/) == 0 + klass.send(meth, :ordered_contents) + else + klass.send(meth) + end end end end end end