2010-07-23 20:09:54 +00:00
|
|
|
module Locomotive
|
|
|
|
module Liquid
|
2010-05-30 23:57:33 +00:00
|
|
|
module Drops
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
class AssetCollections < ::Liquid::Drop
|
|
|
|
|
2010-09-28 22:08:11 +00:00
|
|
|
def before_method(meth)
|
2010-10-10 23:16:43 +00:00
|
|
|
collection = @context.registers[:site].asset_collections.where(:slug => meth.to_s).first
|
|
|
|
AssetCollectionProxy.new(collection)
|
2010-09-28 22:08:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-10-10 23:16:43 +00:00
|
|
|
class AssetCollectionProxy < ::Liquid::Drop
|
2010-09-28 22:08:11 +00:00
|
|
|
|
|
|
|
def initialize(collection)
|
|
|
|
@collection = collection
|
|
|
|
end
|
|
|
|
|
|
|
|
def first
|
|
|
|
@collection.assets.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def last
|
|
|
|
@collection.assets.last
|
|
|
|
end
|
|
|
|
|
|
|
|
def each(&block)
|
|
|
|
@collection.assets.each(&block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def paginate(options = {})
|
|
|
|
paginated_collection = @collection.assets.paginate(options)
|
|
|
|
{
|
|
|
|
:collection => paginated_collection,
|
|
|
|
:current_page => paginated_collection.current_page,
|
|
|
|
:previous_page => paginated_collection.previous_page,
|
|
|
|
:next_page => paginated_collection.next_page,
|
|
|
|
:total_entries => paginated_collection.total_entries,
|
|
|
|
:total_pages => paginated_collection.total_pages,
|
|
|
|
:per_page => paginated_collection.per_page
|
|
|
|
}
|
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 before_method(meth)
|
2010-09-28 22:08:11 +00:00
|
|
|
return '' if @collection.nil?
|
|
|
|
@collection.send(meth)
|
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
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|