Skip to content

Commit 121e571

Browse files
committed
Single tag-wrapping method
1 parent 630890b commit 121e571

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

model-bind.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
return e === element.ownerDocument;
2525
}
2626

27-
function openTag(tagName, attrs) {
27+
function htmlTag(tagName, attrs) {
28+
var content = Array.prototype.slice.call(arguments, 2);
29+
if (typeof attrs !== 'object') {
30+
content.unshift(attrs);
31+
attrs = null;
32+
}
33+
2834
var html = '<' + tagName;
2935
for (var key in attrs) {
3036
var value = attrs[key];
@@ -36,13 +42,10 @@
3642
html += " " + key.escapeHtml() + '="' + value.toString().escapeHtml() + '"';
3743
}
3844
}
39-
html += '>';
40-
return html;
41-
}
42-
function closeTag(tagName) {
43-
return '</' + tagName + '>';
45+
return html += '>' + content.join('') + '</' + tagName + '>';
4446
}
45-
47+
api.util.tag = htmlTag;
48+
4649
var specialAttributes = {
4750
'class': function (element, value) {
4851
if (value === null) {
@@ -676,7 +679,7 @@
676679
var context = thisContext._subContext(model, binding, uiPath);
677680
context._renderInnerHtml(model, binding, tag, attrs, function (error, html) {
678681
if (typeof html === 'string') {
679-
html = openTag(tag, attrs) + html + closeTag(tag);
682+
html = htmlTag(tag, attrs, html)
680683
}
681684
callback(error, html);
682685
});
@@ -703,7 +706,7 @@
703706
if (!rootModel) {
704707
var error = new Error('Missing from data store: ' + data.key);
705708
var errorHtml = thisContext.errorHtml(error, data.tag, data.attrs)
706-
return callback(error, openTag(data.tag, data.attrs) + errorHtml + closeTag(data.tag, data.attrs));
709+
return callback(error, htmlTag(data.tag, data.attrs, errorHtml));
707710
}
708711
var model = rootModel.modelForPath(data.path);
709712
if (thisContext.includeDataProperties) {
@@ -742,7 +745,7 @@
742745
data.attrs[dataPropertyStoreKey] = data.key;
743746
data.attrs[dataPropertyPath] = data.path;
744747
data.attrs[dataPropertyUiPath] = data.ui;
745-
return openTag(data.tag, data.attrs) + closeTag(data.tag);
748+
return htmlTag(data.tag, data.attrs);
746749
});
747750
// DEBUG
748751
if (tag !== 'html' && tag !== 'body') {

0 commit comments

Comments
 (0)