15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/modular/creation.rb', line 15
def from_json(obj)
obj = ActiveSupport::JSON.decode obj if obj.is_a? String
obj = obj.with_indifferent_access
raise "Type expected in json string" unless obj['type']
component = create(obj['type'], obj.except('type').except("children"))
if obj.has_key?('children') && component.is_a?(Modular::Components::Container)
obj['children'].each do |child|
if child.is_a? Hash
child_component = from_json(child)
component.add(child_component)
end
end
end
component
end
|