From: Alan Knowles Date: Tue, 27 Jul 2010 02:54:18 +0000 (+0800) Subject: Roo/Template.js X-Git-Url: http://git.roojs.org/?p=roojs1;a=commitdiff_plain;h=bb534654580edf2a1cb7d8b0aa24c1cdde064779 Roo/Template.js --- diff --git a/Roo/Template.js b/Roo/Template.js index 281628c497..12252cd19b 100644 --- a/Roo/Template.js +++ b/Roo/Template.js @@ -43,36 +43,42 @@ Roo.Template.prototype = { * @return {String} The HTML fragment */ applyTemplate : function(values){ - if(this.compiled){ - return this.compiled(values); - } - var useF = this.disableFormats !== true; - var fm = Roo.util.Format, tpl = this; - var fn = function(m, name, format, args){ - if(format && useF){ - if(format.substr(0, 5) == "this."){ - return tpl.call(format.substr(5), values[name], values); - }else{ - if(args){ - // quoted values are required for strings in compiled templates, - // but for non compiled we need to strip them - // quoted reversed for jsmin - var re = /^\s*['"](.*)["']\s*$/; - args = args.split(','); - for(var i = 0, len = args.length; i < len; i++){ - args[i] = args[i].replace(re, "$1"); - } - args = [values[name]].concat(args); + try { + + if(this.compiled){ + return this.compiled(values); + } + var useF = this.disableFormats !== true; + var fm = Roo.util.Format, tpl = this; + var fn = function(m, name, format, args){ + if(format && useF){ + if(format.substr(0, 5) == "this."){ + return tpl.call(format.substr(5), values[name], values); }else{ - args = [values[name]]; + if(args){ + // quoted values are required for strings in compiled templates, + // but for non compiled we need to strip them + // quoted reversed for jsmin + var re = /^\s*['"](.*)["']\s*$/; + args = args.split(','); + for(var i = 0, len = args.length; i < len; i++){ + args[i] = args[i].replace(re, "$1"); + } + args = [values[name]].concat(args); + }else{ + args = [values[name]]; + } + return fm[format].apply(fm, args); } - return fm[format].apply(fm, args); + }else{ + return values[name] !== undefined ? values[name] : ""; } - }else{ - return values[name] !== undefined ? values[name] : ""; - } - }; - return this.html.replace(this.re, fn); + }; + return this.html.replace(this.re, fn); + } catch (e) { + console && console.log && console.log(e.toString()); + } + return ''; }, /**