Sha256: 4e19de6b953cf58ae301652a8dbbe6960c1096d2faeea1124e394e9e2cf24ea0

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

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

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

      end

      class ContentTypeProxyCollection < ProxyCollection

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

        def public_submission_url
          @context.registers[:controller].main_app.locomotive_entry_submissions_url(@content_type.slug)
        end

        def api
          Locomotive.log :warn, "[Liquid template] the api for content_types has been deprecated and replaced by public_submission_url instead."
          { 'create' => public_submission_url }
        end

        def before_method(meth)
          klass = @content_type.entries.klass # delegate to the proxy class

          if (meth.to_s =~ /^group_by_(.+)$/) == 0
            klass.send(:group_by_select_option, $1, @content_type.order_by_definition)
          elsif (meth.to_s =~ /^(.+)_options$/) == 0
            klass.send(:"#{$1}_options").map { |option| option['name'] }
          else
            Locomotive.log :warn, "[Liquid template] trying to call #{meth} on a content_type object"
          end
        end

        protected

        def collection
          @collection ||= @content_type.ordered_entries(@context['with_scope'])
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
locomotive_cms-2.0.3 lib/locomotive/liquid/drops/content_types.rb
locomotive_cms-2.0.2 lib/locomotive/liquid/drops/content_types.rb
locomotive_cms-2.0.1 lib/locomotive/liquid/drops/content_types.rb
locomotive_cms-2.0.0 lib/locomotive/liquid/drops/content_types.rb
tribeca_cms-0.1.1 lib/locomotive/liquid/drops/content_types.rb
tribeca_cms-2.0.0.rc12 lib/locomotive/liquid/drops/content_types.rb
locomotive_cms-2.0.0.rc12 lib/locomotive/liquid/drops/content_types.rb
locomotive_cms-2.0.0.rc11 lib/locomotive/liquid/drops/content_types.rb
locomotive_cms-2.0.0.rc10 lib/locomotive/liquid/drops/content_types.rb