ASP网页模板的应用: 让程序和界面分离,让ASP脚本(5)
/* Author: 沐枫 (lin.y@263.net) */
/* Date: 2000-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[i].slice(1,-1);
reg = new RegExp(arr[i],"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[2];
this[name] = this[name].replace(Template_Exp,"{"+arr[1]+"}");
this.Split(arr[1]);
}
}
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;
}
%>
内容版权声明:除非注明,否则皆为本站原创文章。