one.asp多项目、函数库、类库 统一为一个版本的方法
前几天写的博客多项目函数库、类库统一为一个版本的方法中提到使用one.php将整个项目打包成一个php文件,有网友让我整个asp版本的,今天下午抽空写了个one.asp,使用方式基本一致,这次增加了路径计算的功能,可以引用不同路径。
举个简单的应用场景,开发一个小的API系统,支持XML、JSON输出。区别是基础版(dev/dev.asp)只支持Access,VIP版本(dev/vip.asp)支持Access+SQLServer。这样VIP版本就需要在现在的基础上增加sqlserver的支持,增加额外的配置项。开发过程只需要按正常开发即可。
开发完毕后,通过one.asp打包成index.asp和vip.asp两个版本,整套程序都是一个独立的文件。
下图演示了解析过程:
完整的测试代码可以访问:oneasp.rar下载
核心代码如下:
'==================================================== '类名:One '作者:mqycn '博客:http://www.miaoqiyuan.cn '源码:http://www.miaoqiyuan.cn/p/one-php '说明:多项目函数库、类库统一为一个版本的方法 '==================================================== ClassOneAsp PrivateFSO PrivateRoot PrivateSubClass_Initialize() SetFSO=Server.CreateObject("Scripting.FileSystemObject") EndSub PrivateSubClass_Terminate() SetFSO=Nothing EndSub PublicFunctionRun(ByValsourceFile,ByValsaveFile) Run="
Input:"&sourceFile&"
Result:"&Save(saveFile,Include(sourceFile)) EndFunction PublicFunctionInclude(ByValpath) DimtmpPath,tmpItem,arrPath,index tmpPath="" arrPath=Split(path,"/") Forindex=0ToUBound(arrPath)-1 tmpItem=arrPath(index) tmpPath=tmpPath&tmpItem&"/" Next Include=Parse(tmpPath,arrPath(UBound(arrPath))) EndFunction PrivateFunctionParse(ByValroot,ByValfileName) CallSetRoot(root) Dimhtml html=OpenRead(fileName) Dimpreg,pregResult Setpreg=NewRegexp preg.pattern="" preg.global=True preg.ignorecase=True DimhtmlInclude SetpregResult=preg.execute(html) ForEachhtmlIncludeInpregResult html=Replace(html,htmlInclude,Include(root&htmlInclude.submatches(0))) Next Parse="<%'"&root&fileName&"Start%"&">"&vbCrLf&html&vbCrLf&"<%'"&root&fileName&"End%"&">"&vbCrLf EndFunction PrivateFunctionSetRoot(ByValrootPath) IfRight(rootPath,1)<>"/"ThenrootPath=rootPath&"/" Root=rootPath EndFunction PrivateFunctionRealPath(ByValpath) RealPath=Server.Mappath(Root&path) EndFunction PrivateFunctionOpenRead(ByValpath) DimtxtFile SettxtFile=FSO.OpenTextFile(RealPath(path)) OpenRead=txtFile.ReadAll() txtFile.close OnErrorGoTo0 EndFunction PublicFunctionSave(ByValpath,ByValbody) DimtxtFile SettxtFile=FSO.CreateTextFile(Server.Mappath(path)) txtFile.writebody txtFile.close SettxtFile=Nothing Save=path EndFunction EndClass
使用也非常简单,使用CallnewOneAsp.run(开发版,打包版),可以dev.asp中的所有包含的代码打包到index.asp,如果只想获取解析的内容,可以使用Response.WriteServer.Htmlencode(CallnewOneAsp.include(开发版))
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。