2010-05-30 23:57:33 +00:00
|
|
|
module Locomotive
|
|
|
|
module Liquid
|
|
|
|
module Drops
|
|
|
|
class Contents < ::Liquid::Drop
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def before_method(meth)
|
2010-09-28 22:08:11 +00:00
|
|
|
type = @context.registers[:site].content_types.where(:slug => meth.to_s).first
|
|
|
|
ProxyCollection.new(type)
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
class ProxyCollection < ::Liquid::Drop
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
def initialize(content_type)
|
2010-05-30 23:57:33 +00:00
|
|
|
@content_type = content_type
|
|
|
|
@collection = nil
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def first
|
2010-10-26 13:06:57 +00:00
|
|
|
self.collection.first
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def last
|
2010-10-26 13:06:57 +00:00
|
|
|
self.collection.last
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def each(&block)
|
2010-10-26 13:06:57 +00:00
|
|
|
self.collection.each(&block)
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2011-07-28 14:42:16 +00:00
|
|
|
|
2011-08-19 12:55:15 +00:00
|
|
|
def each_with_index(&block)
|
|
|
|
self.collection.each_with_index(&block)
|
|
|
|
end
|
|
|
|
|
2011-02-25 03:47:12 +00:00
|
|
|
def size
|
|
|
|
self.collection.size
|
|
|
|
end
|
2011-07-28 14:42:16 +00:00
|
|
|
|
2011-08-19 12:55:15 +00:00
|
|
|
alias :length :size
|
|
|
|
|
2011-02-25 03:47:12 +00:00
|
|
|
def empty?
|
|
|
|
self.collection.empty?
|
|
|
|
end
|
2011-07-28 14:42:16 +00:00
|
|
|
|
2011-02-25 03:47:12 +00:00
|
|
|
def any?
|
|
|
|
self.collection.any?
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-10-26 13:06:57 +00:00
|
|
|
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
|
2011-07-28 14:42:16 +00:00
|
|
|
|
2010-10-26 13:06:57 +00:00
|
|
|
if (meth.to_s =~ /^group_by_.+$/) == 0
|
|
|
|
klass.send(meth, :ordered_contents)
|
|
|
|
else
|
|
|
|
klass.send(meth)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2011-10-24 15:34:43 +00:00
|
|
|
def paginate(options = {})
|
2011-11-05 08:10:26 +00:00
|
|
|
@collection = Kaminari.paginate_array(self.collection).page(options[:page]).per(options[:per_page])
|
2011-10-24 15:34:43 +00:00
|
|
|
end
|
|
|
|
|
2010-10-26 13:06:57 +00:00
|
|
|
def collection
|
2010-10-28 23:36:45 +00:00
|
|
|
@collection ||= @content_type.ordered_contents(@context['with_scope'])
|
2010-06-10 13:30:22 +00:00
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2011-07-28 14:42:16 +00:00
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|