前几天 写的博客 多项目 函数库、类库 统一为一个版本的方法中提到 使用 one.php 将整个项目打包成 一个 php 文件,有网友 让我 整个asp版本的,今天下午抽空写了个 one.asp,使用方式基本一致,这次 增加了路径计算的功能,可以引用不同路径。
举个简单的应用场景,开发一个小的API系统,支持 XML、JSON输出。区别是 基础版(dev/dev.asp)只支持 Access,VIP版本(dev/vip.asp)支持 Access + SQL Server。这样VIP版本就需要在现在的基础上 增加 sqlserver的支持,增加额外的 配置项。开发过程只需要 按正常开发即可。
开发完毕后,通过 one.asp 打包成 index.asp 和 vip.asp 两个版本,整套程序都是一个独立的文件。
下图演示了 解析过程:
完整的测试代码 可以 访问:oneasp.rar 下载
核心代码 如下:
' ====================================================
' 类名:One
' 作者:mqycn
' 博客:http://www.miaoqiyuan.cn
' 源码:http://www.miaoqiyuan.cn/p/one-php
' 说明:多项目 函数库、类库 统一为一个版本的方法
' ====================================================
Class OneAsp
Private FSO
Private Root
Private Sub Class_Initialize()
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
End Sub
Private Sub Class_Terminate()
Set FSO = Nothing
End Sub
Public Function Run(ByVal sourceFile, ByVal saveFile)
Run = "<hr><b>Input:</b>" & sourceFile & "<br><b>Result:</b>" & Save(saveFile, Include(sourceFile))
End Function
Public Function Include(ByVal path)
Dim tmpPath, tmpItem, arrPath, index
tmpPath = ""
arrPath = Split(path, "/")
For index = 0 To UBound(arrPath) - 1
tmpItem = arrPath(index)
tmpPath = tmpPath & tmpItem & "/"
Next
Include = Parse(tmpPath, arrPath(UBound(arrPath)))
End Function
Private Function Parse(ByVal root, ByVal fileName)
Call SetRoot(root)
Dim html
html = OpenRead(fileName)
Dim preg, pregResult
Set preg = New Regexp
preg.pattern = "<!--#include file=""([^""]*)""-->"
preg.global = True
preg.ignorecase = True
Dim htmlInclude
Set pregResult = preg.execute(html)
For Each htmlInclude In pregResult
html = Replace(html, htmlInclude, Include(root & htmlInclude.submatches(0)))
Next
Parse = "<% '" & root & fileName & " Start %" & ">" & vbCrLf & html & vbCrLf & "<% '" & root & fileName & " End %" & ">" & vbCrLf
End Function
Private Function SetRoot(ByVal rootPath)
If Right(rootPath, 1) <> "/" Then rootPath = rootPath & "/"
Root = rootPath
End Function
Private Function RealPath(ByVal path)
RealPath = Server.Mappath(Root & path)
End Function
Private Function OpenRead(ByVal path)
Dim txtFile
Set txtFile = FSO.OpenTextFile(RealPath(path))
OpenRead = txtFile.ReadAll()
txtFile.close
On Error GoTo 0
End Function
Public Function Save(ByVal path, ByVal body)
Dim txtFile
Set txtFile = FSO.CreateTextFile(Server.Mappath(path))
txtFile.write body
txtFile.close
Set txtFile = Nothing
Save = path
End Function
End Class
使用也非常简单,使用 Call new OneAsp.run(开发版, 打包版),可以 dev.asp 中的所有包含的代码 打包到 index.asp,如果只想获取解析的内容,可以使用 Response.Write Server.Htmlencode(Call new OneAsp.include(开发版))
多项目,函数库,类库
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。


