mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Better handling of null/undefined expressions.
This commit is contained in:
parent
a49554b4cb
commit
8d564e4954
@ -251,7 +251,7 @@ function TemplateBuilder(compiler, path, rootNode) {
|
||||
this.vars = [];
|
||||
this.varsLookup = {};
|
||||
|
||||
this.getStaticHelperFunction('toString', 's');
|
||||
this.getStaticHelperFunction('str', 's');
|
||||
this.getStaticHelperFunction('empty', 'e');
|
||||
this.getStaticHelperFunction('notEmpty', 'ne');
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ ExpressionParserHelper.prototype = {
|
||||
// We don't need to surround with parentheses if
|
||||
// the expression will be escaped since the expression
|
||||
// is an argument to a function call
|
||||
expression = 'toString(' + expression + ')';
|
||||
expression = 'str(' + expression + ')';
|
||||
}
|
||||
expression = new Expression(expression);
|
||||
}
|
||||
|
||||
@ -57,6 +57,10 @@ describe('raptor-templates/compiler' , function() {
|
||||
testCompiler('test-project/custom-tag.rhtml');
|
||||
});
|
||||
|
||||
it('should compile a simple template with expressions', function() {
|
||||
testCompiler('test-project/hello-dynamic.rhtml');
|
||||
});
|
||||
|
||||
// it.only('should compile a template with <c:invoke>', function() {
|
||||
// testCompiler('test-project/tabs.rhtml');
|
||||
// });
|
||||
|
||||
@ -80,6 +80,10 @@ describe('raptor-templates/rhtml' , function() {
|
||||
testRender('test-project/simple.rhtml', {}, done);
|
||||
});
|
||||
|
||||
it('should render a simple template with expressions', function(done) {
|
||||
testRender('test-project/hello-dynamic.rhtml', {name: 'John'}, done);
|
||||
});
|
||||
|
||||
it('should render a template with a custom tag', function(done) {
|
||||
testRender('test-project/custom-tag.rhtml', {}, done);
|
||||
});
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
module.exports = function create(__helpers) {
|
||||
var empty = __helpers.e,
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne,
|
||||
hello_renderer = require("./hello-renderer"),
|
||||
_tag = __helpers.t;
|
||||
|
||||
1
test/test-project/hello-dynamic.rhtml
Normal file
1
test/test-project/hello-dynamic.rhtml
Normal file
@ -0,0 +1 @@
|
||||
Hello ${data.name}! Hello $!{data.name}! Hello $!{data.missing}!
|
||||
1
test/test-project/hello-dynamic.rhtml.expected.html
Normal file
1
test/test-project/hello-dynamic.rhtml.expected.html
Normal file
@ -0,0 +1 @@
|
||||
Hello John! Hello John! Hello !
|
||||
16
test/test-project/hello-dynamic.rhtml.expected.js
Normal file
16
test/test-project/hello-dynamic.rhtml.expected.js
Normal file
@ -0,0 +1,16 @@
|
||||
module.exports = function create(__helpers) {
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne,
|
||||
escapeXml = __helpers.x;
|
||||
|
||||
return function render(data, context) {
|
||||
context.w('Hello ' +
|
||||
escapeXml(data.name) +
|
||||
'! Hello ' +
|
||||
str(data.name) +
|
||||
'! Hello ' +
|
||||
str(data.missing) +
|
||||
'!');
|
||||
};
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
module.exports = function create(__helpers) {
|
||||
var empty = __helpers.e,
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne,
|
||||
escapeXmlAttr = __helpers.xa,
|
||||
escapeXml = __helpers.x,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
module.exports = function create(__helpers) {
|
||||
var empty = __helpers.e,
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne,
|
||||
hello_renderer = require("../hello-renderer"),
|
||||
_tag = __helpers.t,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
module.exports = function create(__helpers) {
|
||||
var empty = __helpers.e,
|
||||
var str = __helpers.s,
|
||||
empty = __helpers.e,
|
||||
notEmpty = __helpers.ne;
|
||||
|
||||
return function render(data, context) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user