2010-07-23 20:09:54 +00:00
|
|
|
module Locomotive
|
|
|
|
module Liquid
|
|
|
|
module Drops
|
2012-01-04 01:07:53 +00:00
|
|
|
class ContentEntry < Base
|
2011-07-04 17:40:14 +00:00
|
|
|
|
2012-01-04 01:07:53 +00:00
|
|
|
delegate :_slug, :_permalink, :seo_title, :meta_keywords, :meta_description, :to => '_source'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-03 00:25:19 +00:00
|
|
|
def _id
|
2011-06-21 00:39:59 +00:00
|
|
|
self._source._id.to_s
|
2011-06-03 00:25:19 +00:00
|
|
|
end
|
2012-01-04 01:07:53 +00:00
|
|
|
|
2012-02-16 23:51:33 +00:00
|
|
|
def _label
|
|
|
|
@_label ||= self._source._label
|
|
|
|
end
|
|
|
|
|
2011-09-16 03:37:48 +00:00
|
|
|
# Returns the next content for the parent content type.
|
|
|
|
# If no content is found, nil is returned.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# {% if article.next %}
|
|
|
|
# <a href="/articles/{{ article.next._permalink }}">Read next article</a>
|
|
|
|
# {% endif %}
|
|
|
|
#
|
2011-09-16 03:35:40 +00:00
|
|
|
def next
|
|
|
|
self._source.next.to_liquid
|
|
|
|
end
|
2012-01-04 01:07:53 +00:00
|
|
|
|
2011-09-16 03:37:48 +00:00
|
|
|
# Returns the previous content for the parent content type.
|
|
|
|
# If no content is found, nil is returned.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# {% if article.previous %}
|
|
|
|
# <a href="/articles/{{ article.previous._permalink }}">Read previous article</a>
|
|
|
|
# {% endif %}
|
|
|
|
#
|
2011-09-16 03:35:40 +00:00
|
|
|
def previous
|
|
|
|
self._source.previous.to_liquid
|
|
|
|
end
|
2011-06-03 00:25:19 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def before_method(meth)
|
2011-06-21 00:39:59 +00:00
|
|
|
return '' if self._source.nil?
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
if not @@forbidden_attributes.include?(meth.to_s)
|
2011-06-21 00:39:59 +00:00
|
|
|
value = self._source.send(meth)
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-03-28 15:33:20 +00:00
|
|
|
if value.respond_to?(:all) # check for an association
|
2012-03-12 02:09:20 +00:00
|
|
|
filter_and_order_list(value)
|
2012-02-16 23:51:33 +00:00
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2010-07-16 20:36:07 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2012-03-12 02:09:20 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def filter_and_order_list(list)
|
|
|
|
# filter ?
|
|
|
|
if @context['with_scope']
|
|
|
|
conditions = HashWithIndifferentAccess.new(@context['with_scope'])
|
|
|
|
order_by = conditions.delete(:order_by).try(:split)
|
|
|
|
|
|
|
|
if order_by.nil?
|
|
|
|
list.where(conditions).ordered
|
|
|
|
else
|
|
|
|
list.where(conditions).order_by(order_by)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
list.ordered
|
2012-03-28 15:33:20 +00:00
|
|
|
end
|
2012-03-12 02:09:20 +00:00
|
|
|
end
|
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|
|
|
|
end
|