Better handling of null/undefined expressions.

This commit is contained in:
Patrick Steele-Idem 2014-08-13 09:49:07 -06:00
parent a49554b4cb
commit 8d564e4954
11 changed files with 36 additions and 6 deletions

View File

@ -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');
}

View File

@ -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);
}

View File

@ -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');
// });

View File

@ -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);
});

View File

@ -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;

View File

@ -0,0 +1 @@
Hello ${data.name}! Hello $!{data.name}! Hello $!{data.missing}!

View File

@ -0,0 +1 @@
Hello John! Hello John! Hello !

View 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) +
'!');
};
}

View File

@ -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,

View File

@ -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,

View File

@ -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) {