3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/**
\r
9 * @class Ext.Template
\r
11 Ext.apply(Ext.Template.prototype, {
\r
12 <div id="method-Ext.Template-applyTemplate"></div>/**
\r
13 * Returns an HTML fragment of this template with the specified values applied.
\r
14 * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
\r
15 * @return {String} The HTML fragment
\r
18 applyTemplate : function(values){
\r
20 useF = me.disableFormats !== true,
\r
21 fm = Ext.util.Format,
\r
25 return me.compiled(values);
\r
27 function fn(m, name, format, args){
\r
28 if (format && useF) {
\r
29 if (format.substr(0, 5) == "this.") {
\r
30 return tpl.call(format.substr(5), values[name], values);
\r
33 // quoted values are required for strings in compiled templates,
\r
34 // but for non compiled we need to strip them
\r
35 // quoted reversed for jsmin
\r
36 var re = /^\s*['"](.*)["']\s*$/;
\r
37 args = args.split(',');
\r
38 for(var i = 0, len = args.length; i < len; i++){
\r
39 args[i] = args[i].replace(re, "$1");
\r
41 args = [values[name]].concat(args);
\r
43 args = [values[name]];
\r
45 return fm[format].apply(fm, args);
\r
48 return values[name] !== undefined ? values[name] : "";
\r
51 return me.html.replace(me.re, fn);
\r
54 <div id="prop-Ext.Template-disableFormats"></div>/**
\r
55 * <tt>true</tt> to disable format functions (defaults to <tt>false</tt>)
\r
59 disableFormats : false,
\r
61 <div id="prop-Ext.Template-re"></div>/**
\r
62 * The regular expression used to match template variables
\r
67 re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
\r
69 <div id="method-Ext.Template-compile"></div>/**
\r
70 * Compiles the template into an internal function, eliminating the RegEx overhead.
\r
71 * @return {Ext.Template} this
\r
74 compile : function(){
\r
76 fm = Ext.util.Format,
\r
77 useF = me.disableFormats !== true,
\r
78 sep = Ext.isGecko ? "+" : ",",
\r
81 function fn(m, name, format, args){
\r
83 args = args ? ',' + args : "";
\r
84 if(format.substr(0, 5) != "this."){
\r
85 format = "fm." + format + '(';
\r
87 format = 'this.call("'+ format.substr(5) + '", ';
\r
91 args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
\r
93 return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
\r
96 // branched to use + in gecko and [].join() in others
\r
98 body = "this.compiled = function(values){ return '" +
\r
99 me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
\r
102 body = ["this.compiled = function(values){ return ['"];
\r
103 body.push(me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
\r
104 body.push("'].join('');};");
\r
105 body = body.join('');
\r
111 // private function used to call members
\r
112 call : function(fnName, value, allValues){
\r
113 return this[fnName](value, allValues);
\r
116 Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate; </pre>
\r