lib/spontaneous/collections/field_set.rb in spontaneous-0.2.0.alpha7 vs lib/spontaneous/collections/field_set.rb in spontaneous-0.2.0.beta1

- old
+ new

@@ -30,12 +30,35 @@ # Lazily load fields by name def named(name) super || load_field(owner.field_prototypes[name.to_sym]) end + # A call to ${ fields } within a template will call + # this #render method. + # This should only be used during development + # + def render(format = :html, params = {}, *args) + map { |field| wrap_field_value(field, field.render(format, params, *args), format) }.join("\n") + end + + def render_using(renderer, format = :html, params = {}, *args) + map { |field| wrap_field_value(field, field.render_using(renderer, format, params, *args), format) }.join("\n") + end + protected + def wrap_field_value(field, value, format) + case format + when "html", :html + classes = [owner.class.to_s.dasherize.downcase, "field", field.name].join(" ") + id = "field-#{field.id.gsub(/\//, "-")}" + [ %(<div class="#{classes}" id="#{id}">), value, "</div>" ].join + else + value + end + end + def initialize_from_prototypes owner.field_prototypes.each do |field_prototype| add_field(field_prototype) end end @@ -44,10 +67,10 @@ @field_values ||= parse_field_data(@field_data) end def parse_field_data(initial_values) values = (initial_values || []).map do |value| - value = S::FieldTypes.deserialize_field(value) + value = S::Field.deserialize_field(value) [Spontaneous.schema.uids[value[:id]], value] end Hash[values] end