Skip to content

Commit 963a8f9

Browse files
committed
Custom stingify functions affect current instance only
1 parent a7d814a commit 963a8f9

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

1.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
x = require './src/index.coffee'
2+
3+
xml = x.create('hello')
4+
.ele('element')
5+
.ins('xml-stylesheet', 'type="text/xsl" href="style.xsl"')
6+
console.log xml.end({pretty:true})

src/XMLStringifier.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class XMLStringifier
99
constructor: (options) ->
1010
@allowSurrogateChars = options?.allowSurrogateChars
1111
for own key, value of options?.stringify or {}
12-
XMLStringifier::[key] = value
12+
@[key] = value
1313

1414
# Defaults
1515
eleName: (val) ->

test/stringify.coffee

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
vows = require 'vows'
2+
assert = require 'assert'
3+
4+
xmlbuilder = require '../src/index.coffee'
5+
6+
vows
7+
.describe('Stringify')
8+
.addBatch
9+
'Custom function':
10+
topic: () ->
11+
addns = (val) ->
12+
'my:' + val
13+
14+
xmlbuilder.create('test7', { headless: true, stringify: { eleName: addns } })
15+
.ele('nodes')
16+
.ele('node', '1').up()
17+
.ele('node', '2').up()
18+
.ele('node', '3')
19+
20+
'resulting XML': (topic) ->
21+
xml = '<my:test7><my:nodes><my:node>1</my:node><my:node>2</my:node><my:node>3</my:node></my:nodes></my:test7>'
22+
assert.strictEqual topic.end(), xml
23+
24+
.export(module)
25+

0 commit comments

Comments
 (0)