Sha256: e6f40a69c19b722ce7a82cae2fd30c63e5e67cc5afadcaa02ba7efbdf22baf16

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

module Locomotive
  module Liquid
    module Drops

      class AssetCollections < ::Liquid::Drop

        def before_method(meth)
          collection = @context.registers[:site].asset_collections.where(:slug => meth.to_s).first
          AssetCollectionProxy.new(collection)
        end

      end

      class AssetCollectionProxy < ::Liquid::Drop

        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
          }
        end

        def before_method(meth)
          return '' if @collection.nil?
          @collection.send(meth)
        end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotive_cms-0.0.4.beta5 lib/locomotive/liquid/drops/asset_collections.rb
locomotive_cms-0.0.4.beta4 lib/locomotive/liquid/drops/asset_collections.rb
locomotive_cms-0.0.4.beta3 lib/locomotive/liquid/drops/asset_collections.rb
locomotive_cms-0.0.4.beta2 lib/locomotive/liquid/drops/asset_collections.rb
locomotive_cms-0.0.4.beta1 lib/locomotive/liquid/drops/asset_collections.rb
locomotive_cms-0.0.4 lib/locomotive/liquid/drops/asset_collections.rb