diff --git a/javascript/lib/tenjin.js b/javascript/lib/tenjin.js index a175771..5a0e751 100644 --- a/javascript/lib/tenjin.js +++ b/javascript/lib/tenjin.js @@ -342,6 +342,9 @@ Tenjin.Template = function(filename, properties) { else if (! this.preamble) this.preamble = ''; if (this.postamble == true) delete(this.postamble); else if (! this.postamble) this.postamble = ''; + if (properties.tostrfunc) { + this.tostrfunc = properties.tostrfunc; + } if (properties.escapefunc) { var funcname = properties.escapefunc; if (funcname.charAt(0) == '.') { @@ -357,6 +360,7 @@ Tenjin.Template = function(filename, properties) { }; Tenjin.Template.__props__ = { + tostrfunc : "toStr", escapefunc : "escapeXml", preamble : "var _buf = ''; ", postamble : "_buf\n", @@ -560,7 +564,7 @@ Tenjin.Template.prototype = { hookExpression: function(expr, flag_escape) { if (this.emptystr) { //return flag_escape ? this.escapeExpression(expr) : "[" + expr + "].join()"; - return flag_escape ? this.escapeExpression(expr) : "toStr(" + expr + ")"; + return flag_escape ? this.escapeExpression(expr) : this.tostrfunc + "(" + expr + ")"; } else { return flag_escape ? this.escapeExpression(expr) : "(" + expr + ")"; diff --git a/javascript/test/template_test.js b/javascript/test/template_test.js index be0995e..3404d17 100644 --- a/javascript/test/template_test.js +++ b/javascript/test/template_test.js @@ -124,6 +124,19 @@ topic('Tenjin.Template', function(t) { ok (t2.render(context)).eq(output2); }); + spec("allows to change 'toStr()' by 'tostrfunc' option.", function() { + var input = "

Hello #{name}!

\n"; + var script_expected = ( + '' + + "var _buf = ''; _buf += '

Hello ' + String(name) + '!

\\n';\n" + + "_buf\n" + ); + var fname = 'input.jshtml'; + this.writeFile(fname, input); + var t1 = new Tenjin.Template({tostrfunc: 'String'}); + ok (t1.convert(input)).eq(script_expected); + }); + });