最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

one.asp多項目、函數(shù)庫、類庫 統(tǒng)一為一個版本的方法

 更新時間:2020年08月24日 11:53:53   作者:苗啟源  
前幾天 寫的博客 多項目 函數(shù)庫、類庫 統(tǒng)一為一個版本的方法中提到 使用 one.php 將整個項目打包成 一個 php 文件,有網(wǎng)友 讓我 整個asp版本的,今天下午抽空寫了個 one.asp,使用方式基本一致,這次 增加了路徑計算的功能,可以引用不同路徑

前幾天 寫的博客 多項目 函數(shù)庫、類庫 統(tǒng)一為一個版本的方法中提到 使用 one.php 將整個項目打包成 一個 php 文件,有網(wǎng)友 讓我 整個asp版本的,今天下午抽空寫了個 one.asp,使用方式基本一致,這次 增加了路徑計算的功能,可以引用不同路徑。

舉個簡單的應(yīng)用場景,開發(fā)一個小的API系統(tǒng),支持 XML、JSON輸出。區(qū)別是 基礎(chǔ)版(dev/dev.asp)只支持 Access,VIP版本(dev/vip.asp)支持 Access + SQL Server。這樣VIP版本就需要在現(xiàn)在的基礎(chǔ)上 增加 sqlserver的支持,增加額外的 配置項。開發(fā)過程只需要 按正常開發(fā)即可。

開發(fā)完畢后,通過 one.asp 打包成 index.asp 和 vip.asp 兩個版本,整套程序都是一個獨立的文件。

下圖演示了 解析過程:

完整的測試代碼 可以 訪問:oneasp.rar 下載

核心代碼 如下:

' ====================================================
' 類名:One
' 作者:mqycn
' 博客:http://www.miaoqiyuan.cn
' 源碼:http://www.miaoqiyuan.cn/p/one-php
' 說明:多項目 函數(shù)庫、類庫 統(tǒng)一為一個版本的方法
' ====================================================
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(開發(fā)版, 打包版),可以 dev.asp 中的所有包含的代碼 打包到 index.asp,如果只想獲取解析的內(nèi)容,可以使用 Response.Write Server.Htmlencode(Call new OneAsp.include(開發(fā)版))

相關(guān)文章

最新評論

兴和县| 海门市| 托里县| 平潭县| 达拉特旗| 土默特右旗| 龙井市| 卓资县| 方城县| 英吉沙县| 无为县| 山东省| 平度市| 洞口县| 邵阳市| 射阳县| 黑龙江省| 阿尔山市| 通道| 松潘县| 太仓市| 景东| 西畴县| 正阳县| 扎兰屯市| 定日县| 靖西县| 石台县| 大姚县| 平泉县| 方城县| 石河子市| 五莲县| 克拉玛依市| 长春市| 江油市| 麦盖提县| 石楼县| 赣榆县| 屏南县| 蛟河市|