********************/
/* Template Class */
/* Author: */
/* Date: 6-09 */
/*********************************************************/
//Template Method Define
function Template_Parse(name)
{
if(this[name]==null)
return "";
var reg = new RegExp("{(\\w*)}","ig");
var str = new String(this[name]);
var arr = str.match(reg);
var i;
if(arr != null)
for(i=0;i<arr.length;i++)
{
key = arr.slice(1,-1);
reg = new RegExp(arr,"ig");
if(this[key]!=null)
str = str.replace(reg,this[key]);
}
return str;
}
function Template_Split(name)
{
var len = 0;
var arr;
if(this[name]==null)
return;
var Template_Exp = new RegExp("<!--#TPLDEF +(\\w*) *-->((.|\\n)*)<!--#TPLEND +\\1 *-->","i");
while(this[name].search(Template_Exp)!=-1)
{
arr = this[name].match(Template_Exp);
this[arr[1} = arr;
this[name] = this[name].replace(Template_Exp,"{"+arr+"}");
this.Split(arr);
}
}
function Template_Load(name,filename)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.BuildPath(this.TplPath, filename);
if(fso.FileExists(file))
{
var f = fso.OpenTextFile(file, 1);
this[name] = f.ReadAll();
}
}
//Template Constructor
function Template(path)
{
//Property
this.TplPath = path;
//Method
this.Parse = Template_Parse;
this.Split = Template_Split;
this.Load = Template_Load;
}
%>