Moved handling of String includes into the core tag

This commit is contained in:
Patrick Steele-Idem 2017-01-18 07:12:45 -07:00
parent 7dc0bf3eeb
commit 9e4a638c51
8 changed files with 15 additions and 5 deletions

View File

@ -5,6 +5,8 @@ module.exports = function include(input, out) {
if (target) {
if (typeof target === 'function') {
target(out, arg);
} else if (typeof target === 'string') {
out.text(target);
} else if (typeof target === 'object') {
if (target.renderBody) {
target.renderBody(out, arg);
@ -12,9 +14,11 @@ module.exports = function include(input, out) {
target.renderer(arg, out);
} else if (target.render) {
target.render(arg, out);
} else if (target.safeHTML) {
out.write(target.safeHTML);
}
} else {
throw new Error('Invalid include target: ' + target);
}
}
};
};

View File

@ -0,0 +1 @@
<strong>Hello!</strong>

View File

@ -0,0 +1,2 @@
var html = { safeHTML: '<strong>Hello!</strong>' };
<include(html)/>

View File

@ -0,0 +1 @@
exports.templateData = {};

View File

@ -0,0 +1 @@
&lt;script>Hello&lt;/script>

View File

@ -0,0 +1,2 @@
var text = '<script>Hello</script>';
<include(text)/>

View File

@ -0,0 +1 @@
exports.templateData = {};

View File

@ -5,9 +5,7 @@ var getElementById = require('../util').$__getElementById;
module.exports = function include(input, out) {
var target = input._target;
if (typeof target === 'string') {
out.text(target);
} else if (target) {
if (target != null) {
normalInclude(input, out);
} else if (getElementById) {
var elId = input._elId;
@ -20,4 +18,4 @@ module.exports = function include(input, out) {
widgetsContext.$__preserveDOMNode(elId, true /* body only */);
}
}
};
};