siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
104 lines (76 loc) • 3.18 kB
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js">/*
Siesta 5.6.1
Copyright(c) 2009-2022 Bryntum AB
https://bryntum.com/contact
https://bryntum.com/products/siesta/license
*/
Class('Siesta.Util.XMLNode', {
has : {
children : Joose.I.Array,
tag : { required : true },
attributes : Joose.I.Object,
textContent : null,
escapeTable : {
init : {
'&' : '&amp;',
'<' : '&lt;',
'>' : '&gt;',
'"' : '&quot;'
}
}
},
methods : {
escapeXml : function (s) {
var me = this
return typeof s != 'string' ? s : s.replace(/[&<>"]/g, function (match) {
return me.escapeTable[ match ]
})
},
toString : function () {
var me = this
var childrenContent = []
Joose.A.each(this.children, function (child) {
childrenContent.push(child.toString())
})
var attributesContent = []
Joose.O.each(this.attributes, function (value, name) {
attributesContent.push(name + '="' + me.escapeXml(value) + '"')
})
// to have predictable order of attributes in tests
attributesContent.sort()
attributesContent.unshift(this.tag)
return '<' + attributesContent.join(' ') + '>' + (this.textContent != null ? this.escapeXml(this.textContent) : '') + childrenContent.join('') + '</' + this.tag + '>'
},
appendChild : function (child) {
if (child instanceof Siesta.Util.XMLNode)
child.parent = this
else
child = new Siesta.Util.XMLNode(Joose.O.extend(child, { parent : this }))
this.children.push(child)
return child
},
setAttribute : function (name, value) {
this.attributes[ name ] = value
}
}
})
</pre>
</body>
</html>