2011-07-04 17:40:14 +00:00
|
|
|
# Liquify taken from Mephisto sources (http://mephistoblog.com/)
|
2010-05-30 23:57:33 +00:00
|
|
|
module Locomotive
|
2010-07-23 20:09:54 +00:00
|
|
|
module Liquid
|
|
|
|
module Drops
|
2010-05-30 23:57:33 +00:00
|
|
|
class Base < ::Liquid::Drop
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-21 15:46:17 +00:00
|
|
|
@@forbidden_attributes = %w{_id _version _index}
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-06-21 00:39:59 +00:00
|
|
|
attr_reader :_source
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def initialize(source)
|
2011-07-04 17:40:14 +00:00
|
|
|
@_source = source
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
def id
|
2011-06-21 00:39:59 +00:00
|
|
|
(@_source.respond_to?(:id) ? @_source.id : nil) || 'new'
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-05-30 23:57:33 +00:00
|
|
|
# converts an array of records to an array of liquid drops
|
|
|
|
def self.liquify(*records, &block)
|
|
|
|
i = -1
|
2010-07-23 20:09:54 +00:00
|
|
|
records =
|
2010-05-30 23:57:33 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
protected
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-03 15:32:40 +00:00
|
|
|
def liquify(*records, &block)
|
|
|
|
self.class.liquify(*records, &block)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|