Sha256: 4819721dde009138fc1a0fbc0e4fbbb3fb0cd43337f4838f2062f72c35bd4d1e

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

module Locomotive
  module Liquid
    module Drops
      class ContentEntry < Base

        delegate :_slug, :_permalink, :_translated, :seo_title, :meta_keywords, :meta_description, to: :@_source

        def _id
          @_source._id.to_s
        end

        def _label
          @_label ||= @_source._label
        end

        # 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 %}
        #
        def next
          @next ||= @_source.next.to_liquid
        end

        # 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 %}
        #
        def previous
          @previous ||= @_source.previous.to_liquid
        end

        def errors
          @_source.errors.messages.to_hash.stringify_keys
        end

        def before_method(meth)
          return '' if @_source.nil?

          if not @@forbidden_attributes.include?(meth.to_s)
            value = @_source.send(meth)

            if value.respond_to?(:all) # check for an association
              filter_and_order_list(value)
            else
              value
            end
          else
            nil
          end
        end

        protected

        def filter_and_order_list(list)
          conditions, order_by = HashWithIndifferentAccess.new(_visible: true), nil

          if @context['with_scope']
            conditions.merge!(@context['with_scope'])
            order_by = conditions.delete(:order_by).try(:split)
          end

          list.filtered(conditions, order_by)
        end

      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
locomotive_cms-2.5.7 lib/locomotive/liquid/drops/content_entry.rb
locomotivecms-3.0.0.pre.alpha.2 lib/locomotive/previous_liquid/drops/content_entry.rb
locomotivecms-3.0.0.pre.alpha lib/locomotive/previous_liquid/drops/content_entry.rb
locomotive_cms-2.5.6 lib/locomotive/liquid/drops/content_entry.rb
locomotive_cms-2.5.6.rc2 lib/locomotive/liquid/drops/content_entry.rb
locomotive_cms-2.5.6.rc1 lib/locomotive/liquid/drops/content_entry.rb