File tree 2 files changed +77
-2
lines changed
2 files changed +77
-2
lines changed Original file line number Diff line number Diff line change @@ -40,9 +40,9 @@ module.exports = class XMLNode
40
40
else if _ .isFunction name
41
41
lastChild = @ element name .apply ()
42
42
43
- # expand if object but skip null values
43
+ # expand if object
44
44
else if _ .isObject name
45
- for own key, val of name when val ?
45
+ for own key, val of name
46
46
# evaluate if function
47
47
val = val .apply () if _ .isFunction val
48
48
Original file line number Diff line number Diff line change
1
+ vows = require ' vows'
2
+ assert = require ' assert'
3
+
4
+ xmlbuilder = require ' ../src/index.coffee'
5
+
6
+ vows
7
+ .describe (' Creating XML' )
8
+ .addBatch
9
+ ' Object builder consistency' :
10
+ topic : () ->
11
+ obj =
12
+ ele : " simple element"
13
+ person :
14
+ name : " John"
15
+ ' @age' : 35
16
+ ' ?pi' : ' mypi'
17
+ ' #comment' : ' Good guy'
18
+ ' #cdata' : ' well formed!'
19
+ unescaped :
20
+ ' #raw' : ' &<>&'
21
+ address :
22
+ city : " Istanbul"
23
+ street : " End of long and winding road"
24
+ contact : [
25
+ { phone : " 555-1234" }
26
+ { phone : " 555-1235" }
27
+ ]
28
+ id : () -> return 42
29
+ details :
30
+ ' #text' : ' classified'
31
+ nullval : null
32
+
33
+ t1 = xmlbuilder .create (' root' , { headless : true })
34
+ .ele (obj)
35
+
36
+ t2 = xmlbuilder .create (' root' , { headless : true })
37
+ .ele (' ele' , ' simple element' )
38
+ .up ()
39
+ .ele (' person' )
40
+ .ele (' name' , ' John' )
41
+ .up ()
42
+ .att (' age' , 35 )
43
+ .ins (' pi' , ' mypi' )
44
+ .com (' Good guy' )
45
+ .dat (' well formed!' )
46
+ .ele (' unescaped' )
47
+ .raw (' &<>&' )
48
+ .up ()
49
+ .ele (' address' )
50
+ .ele (' city' , ' Istanbul' )
51
+ .up ()
52
+ .ele (' street' , ' End of long and winding road' )
53
+ .up ()
54
+ .up ()
55
+ .ele (' contact' )
56
+ .ele (' phone' , ' 555-1234' )
57
+ .up ()
58
+ .ele (' phone' , ' 555-1235' )
59
+ .up ()
60
+ .up ()
61
+ .ele (' id' , 42 )
62
+ .up ()
63
+ .ele (' details' )
64
+ .text (' classified' )
65
+ .up ()
66
+ .ele (' nullval' , null )
67
+
68
+ return [t1, t2]
69
+
70
+ ' resulting XML ' : (topic ) ->
71
+ assert .strictEqual topic[0 ].end (), topic[1 ].end ()
72
+
73
+
74
+ .export (module )
75
+
You can’t perform that action at this time.
0 commit comments