Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Evaluate attribute value if function

  • Loading branch information...
commit e36cf6d14c8c43c51fee5567831f168aff713e04 1 parent 95b152d
@oozcitak authored
Showing with 5 additions and 1 deletion.
  1. +3 −0  src/XMLAttribute.coffee
  2. +2 −1  test/createxml.coffee
View
3  src/XMLAttribute.coffee
@@ -15,6 +15,9 @@ module.exports = class XMLAttribute
if not name?
throw new Error "Missing attribute name"
+ # evaluate if function
+ value = value.apply() if _.isFunction value
+
@name = @stringify.attName name
@value = @stringify.attValue value
View
3  test/createxml.coffee
@@ -65,6 +65,7 @@ vows
.ele('atttest', { 'att': 'val' }, 'text')
.up()
.ele('atttest', 'text')
+ .att('att', () -> 'val')
'resulting XML': (topic) ->
xml = '<?xml version="1.0"?>' +
@@ -77,7 +78,7 @@ vows
'<cdata><![CDATA[<test att="val">this is a test</test>\nSecond line]]></cdata>' +
'<raw>&<>&</raw>' +
'<atttest att="val">text</atttest>' +
- '<atttest>text</atttest>' +
+ '<atttest att="val">text</atttest>' +
'</root>'
assert.strictEqual topic.end(), xml
Please sign in to comment.
Something went wrong with that request. Please try again.