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 (target) {
if (typeof target === 'function') { if (typeof target === 'function') {
target(out, arg); target(out, arg);
} else if (typeof target === 'string') {
out.text(target);
} else if (typeof target === 'object') { } else if (typeof target === 'object') {
if (target.renderBody) { if (target.renderBody) {
target.renderBody(out, arg); target.renderBody(out, arg);
@ -12,9 +14,11 @@ module.exports = function include(input, out) {
target.renderer(arg, out); target.renderer(arg, out);
} else if (target.render) { } else if (target.render) {
target.render(arg, out); target.render(arg, out);
} else if (target.safeHTML) {
out.write(target.safeHTML);
} }
} else { } else {
throw new Error('Invalid include target: ' + target); 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) { module.exports = function include(input, out) {
var target = input._target; var target = input._target;
if (typeof target === 'string') { if (target != null) {
out.text(target);
} else if (target) {
normalInclude(input, out); normalInclude(input, out);
} else if (getElementById) { } else if (getElementById) {
var elId = input._elId; var elId = input._elId;
@ -20,4 +18,4 @@ module.exports = function include(input, out) {
widgetsContext.$__preserveDOMNode(elId, true /* body only */); widgetsContext.$__preserveDOMNode(elId, true /* body only */);
} }
} }
}; };