Skip to content
This repository
Browse code

XML import generator fixes

  • Loading branch information...
commit 4cabc2a257e7494897284c00dc2ef138c0a1e2c7 1 parent 821d5ad
Oliver Newland authored March 29, 2012

Showing 1 changed file with 6 additions and 8 deletions. Show diff stats Hide diff stats

  1. 14  lib/bb/var.rb
14  lib/bb/var.rb
@@ -178,7 +178,7 @@ def gen_xml_importer(target, xml)
178 178
           xml_find = "#{xml_name} = $(xml).attr('#{xml_name}')"
179 179
           n = xml_name
180 180
           if default
181  
-            "(#{xml_name}.length() == 0 ? #{default} : #{xml_name})"
  181
+            "(#{xml_name}.length == 0 ? #{default} : #{xml_name}) if #{xml_name}?"
182 182
           else
183 183
             "#{xml}.#{n}"
184 184
           end
@@ -200,15 +200,13 @@ def gen_xml_importer(target, xml)
200 200
       rhs =
201 201
       case type
202 202
       when "String"
203  
-        xml_read # no conversion needed
  203
+        xml_name
204 204
       
205 205
       when "int", "uint", "Number"
206  
-        "#{type}(#{xml_name})"
  206
+        "Number(#{xml_name})"
207 207
       
208 208
       when "Boolean"
209  
-        "(#{xml_name}.toString().toLowerCase() == 'true')"
210  
-        # toString is because Boolean defaults are literal true or false,
211  
-        # but attr values are always strings.
  209
+        "(#{xml_name}.toString().toLowerCase() == 'true') if #{xml_name}?"
212 210
       
213 211
       when "Object"
214 212
         unless xml_storage_class == XML_STORAGE_PARAMETERS
@@ -245,14 +243,14 @@ def gen_xml_importer(target, xml)
245 243
         end
246 244
         
247 245
         if collection
248  
-          "_.map(#{xml_name}, (#{xml_name}_i) -> $a.#{type}.from_xml2(#{xml_name}_i, deferred, object_with_id))"
  246
+          "_.map($(#{xml_name}), (#{xml_name}_i) -> $a.#{type}.from_xml2($(#{xml_name}_i), deferred, object_with_id))"
249 247
         else
250 248
           "$a.#{type}.from_xml2(#{xml_name}, deferred, object_with_id)"
251 249
         end
252 250
       end
253 251
       
254 252
       assign = [xml_find, 
255  
-                "#{target}.set '#{name}', #{rhs}"]
  253
+                "#{target}.set('#{name}', #{rhs})"]
256 254
       
257 255
       if defer
258 256
         "deferred.push(-> #{assign})"

0 notes on commit 4cabc2a

Please sign in to comment.
Something went wrong with that request. Please try again.