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}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Base

Returns a new instance of Base.



11
12
13
# File 'lib/locomotive/liquid/drops/base.rb', line 11

def initialize(source)
  @_source = source
end

Instance Attribute Details

#_sourceObject (readonly)

Returns the value of attribute _source.



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

def _source
  @_source
end

Class Method Details

.liquify(*records, &block) ⇒ Object

converts an array of records to an array of liquid drops



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

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



15
16
17
# File 'lib/locomotive/liquid/drops/base.rb', line 15

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