Sha256: a141f03eb22b358fc6cd05089276a5e9bbd8e584a345c20654b8c067e3596843

Contents?: true

Size: 1.77 KB

Versions: 6

Compression:

Stored size: 1.77 KB

Contents

module Locomotive
  module Liquid
    module Drops
      class Contents < ::Liquid::Drop

        def before_method(meth)
          type = @context.registers[:site].content_types.where(:slug => meth.to_s).first
          ProxyCollection.new(type)
        end

      end

      class ProxyCollection < ::Liquid::Drop

        def initialize(content_type)
          @content_type = content_type
          @collection = nil
        end

        def first
          content = @content_type.ordered_contents(@context['with_scope']).first
        end

        def last
          content = @content_type.ordered_contents(@context['with_scope']).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
          }
        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
      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/contents.rb
locomotive_cms-0.0.4.beta4 lib/locomotive/liquid/drops/contents.rb
locomotive_cms-0.0.4.beta3 lib/locomotive/liquid/drops/contents.rb
locomotive_cms-0.0.4.beta2 lib/locomotive/liquid/drops/contents.rb
locomotive_cms-0.0.4.beta1 lib/locomotive/liquid/drops/contents.rb
locomotive_cms-0.0.4 lib/locomotive/liquid/drops/contents.rb