mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Moved handling of String includes into the core tag
This commit is contained in:
parent
7dc0bf3eeb
commit
9e4a638c51
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
1
test/autotests/render/include-safeHTML/expected.html
Normal file
1
test/autotests/render/include-safeHTML/expected.html
Normal file
@ -0,0 +1 @@
|
||||
<strong>Hello!</strong>
|
||||
2
test/autotests/render/include-safeHTML/template.marko
Normal file
2
test/autotests/render/include-safeHTML/template.marko
Normal file
@ -0,0 +1,2 @@
|
||||
var html = { safeHTML: '<strong>Hello!</strong>' };
|
||||
<include(html)/>
|
||||
1
test/autotests/render/include-safeHTML/test.js
Normal file
1
test/autotests/render/include-safeHTML/test.js
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
1
test/autotests/render/include-string/expected.html
Normal file
1
test/autotests/render/include-string/expected.html
Normal file
@ -0,0 +1 @@
|
||||
<script>Hello</script>
|
||||
2
test/autotests/render/include-string/template.marko
Normal file
2
test/autotests/render/include-string/template.marko
Normal file
@ -0,0 +1,2 @@
|
||||
var text = '<script>Hello</script>';
|
||||
<include(text)/>
|
||||
1
test/autotests/render/include-string/test.js
Normal file
1
test/autotests/render/include-string/test.js
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
@ -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 */);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user