Sha256: b3e9eff7fd01710dbf1e04157ed9face2f80c30f8f765011a34c3e6238d251e1

Contents?: true

Size: 1.35 KB

Versions: 30

Compression:

Stored size: 1.35 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Drops
        class Base < ::Liquid::Drop

          @@forbidden_attributes = %w{_id _version _index}

          def initialize(source)
            @_source = source
          end

          def id
            (@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
          end

          def as_json(options = nil)
            @_source.as_json(options)
          end

          protected

          # converts an array of records to an array of liquid drops
          def liquify(*records, &block)
            i = -1
            records =
              records.inject [] do |all, r|
                i += 1
                attrs = (block && block.arity == 1) ? [r] : [r, i]
                all << (block ? block.call(*attrs) : r.to_liquid).tap do |_r|
                  # For unknown reasons, Liquid doesn't always set the context
                  #
                  # Example:
                  #   {{ site.index.children | map: 'title' | join: " - " }}
                  #   was not working before
                  #
                  _r.context = @context if _r.respond_to?(:context=)
                end
                all
              end
            records.compact!
            records
          end

          def _source
            @_source
          end

        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/liquid/drops/base.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/liquid/drops/base.rb