lib/rooftop/content/collection.rb in rooftop-0.0.6 vs lib/rooftop/content/collection.rb in rooftop-0.0.7.4
- old
+ new
@@ -1,12 +1,23 @@
module Rooftop
module Content
class Collection < ::Array
def initialize(content_fields)
- content_fields.each do |field|
- self << Rooftop::Content::Field.new(field)
+ content_fields.each do |field|
+ # if the field has a 'fields' key, it is a repeater field. Collect the sub-fields and
+ # set the field content to the collection of repeated fields
+ if field.has_key?('fields')
+ repeated_fields = field[:fields].collect do |repeated_fields|
+ repeated_fields.collect{|field| Rooftop::Content::Field.new(field)}
+ end
+
+ field.delete(:fields)
+ field[:value] = repeated_fields
end
+
+ self << Rooftop::Content::Field.new(field)
+ end
end
# Find content_fields by attribute. Assume there will only be one attribute in the search
def find_by(hash)
raise ArgumentError, "you can only find a field by one attribute at a time" unless hash.length == 1
@@ -40,6 +51,6 @@
end
end
end
end
-end
\ No newline at end of file
+end