2012-01-09 14:49:59 +00:00
|
|
|
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
|
2012-02-16 23:51:33 +00:00
|
|
|
ContentTypeProxyCollection.new(type)
|
2012-01-09 14:49:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-02-16 23:51:33 +00:00
|
|
|
class ContentTypeProxyCollection < ProxyCollection
|
2012-01-09 14:49:59 +00:00
|
|
|
|
|
|
|
def initialize(content_type)
|
|
|
|
@content_type = content_type
|
2012-02-16 23:51:33 +00:00
|
|
|
@collection = nil
|
2012-01-09 14:49:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def public_submission_url
|
|
|
|
@context.registers[:controller].main_app.locomotive_entry_submissions_url(@content_type.slug)
|
|
|
|
end
|
|
|
|
|
2012-02-20 00:15:43 +00:00
|
|
|
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
|
|
|
|
|
2012-01-09 14:49:59 +00:00
|
|
|
def before_method(meth)
|
|
|
|
klass = @content_type.entries.klass # delegate to the proxy class
|
|
|
|
|
2012-02-20 00:15:43 +00:00
|
|
|
if (meth.to_s =~ /^group_by_(.+)$/) == 0
|
|
|
|
klass.send(:group_by_select_option, $1, @content_type.order_by_definition)
|
2012-01-09 14:49:59 +00:00
|
|
|
else
|
2012-02-20 00:15:43 +00:00
|
|
|
Locomotive.log :warn, "[Liquid template] trying to call #{meth} on a content_type object"
|
2012-01-09 14:49:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def collection
|
|
|
|
@collection ||= @content_type.ordered_entries(@context['with_scope'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|