Permalink
Browse files

XML import generator fixes

  • Loading branch information...
onewland committed Mar 29, 2012
1 parent 821d5ad commit 4cabc2a257e7494897284c00dc2ef138c0a1e2c7
Showing with 6 additions and 8 deletions.
  1. +6 −8 lib/bb/var.rb
View
@@ -178,7 +178,7 @@ def gen_xml_importer(target, xml)
xml_find = "#{xml_name} = $(xml).attr('#{xml_name}')"
n = xml_name
if default
- "(#{xml_name}.length() == 0 ? #{default} : #{xml_name})"
+ "(#{xml_name}.length == 0 ? #{default} : #{xml_name}) if #{xml_name}?"
else
"#{xml}.#{n}"
end
@@ -200,15 +200,13 @@ def gen_xml_importer(target, xml)
rhs =
case type
when "String"
- xml_read # no conversion needed
+ xml_name
when "int", "uint", "Number"
- "#{type}(#{xml_name})"
+ "Number(#{xml_name})"
when "Boolean"
- "(#{xml_name}.toString().toLowerCase() == 'true')"
- # toString is because Boolean defaults are literal true or false,
- # but attr values are always strings.
+ "(#{xml_name}.toString().toLowerCase() == 'true') if #{xml_name}?"
when "Object"
unless xml_storage_class == XML_STORAGE_PARAMETERS
@@ -245,14 +243,14 @@ def gen_xml_importer(target, xml)
end
if collection
- "_.map(#{xml_name}, (#{xml_name}_i) -> $a.#{type}.from_xml2(#{xml_name}_i, deferred, object_with_id))"
+ "_.map($(#{xml_name}), (#{xml_name}_i) -> $a.#{type}.from_xml2($(#{xml_name}_i), deferred, object_with_id))"
else
"$a.#{type}.from_xml2(#{xml_name}, deferred, object_with_id)"
end
end
assign = [xml_find,
- "#{target}.set '#{name}', #{rhs}"]
+ "#{target}.set('#{name}', #{rhs})"]
if defer
"deferred.push(-> #{assign})"

0 comments on commit 4cabc2a

Please sign in to comment.