Class: Locomotive::Liquid::Drops::Base

Inherits:
Liquid::Drop
  • Object
show all
Defined in:
lib/locomotive/liquid/drops/base.rb

Direct Known Subclasses

ContentEntry, CurrentUser, Page, Site, Uploader

Constant Summary collapse

@@forbidden_attributes =
%w{_id _version _index}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/locomotive/liquid/drops/base.rb', line 9

def initialize(source)
  @_source = source
end

Class Method Details

.liquify(*records, &block) ⇒ Object

converts an array of records to an array of liquid drops



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/locomotive/liquid/drops/base.rb', line 18

def self.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)
      all
    end
  records.compact!
  records
end

Instance Method Details

#idObject



13
14
15
# File 'lib/locomotive/liquid/drops/base.rb', line 13

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