ASP

推荐列表 站点导航

当前位置:首页 > 脚本编程 > ASP >

one.asp多项目、函数库、类库 统一为一个版本的方法

来源:网络整理  作者:wy  发布时间:2020-12-23 11:29
前几天 写的博客 多项目 函数库、类库 统一为一个版本的方法中提到 使用 one.php 将整个项目打包成 一个 php 文件,有...

前几天 写的博客 多项目 函数库、类库 统一为一个版本的方法中提到 使用 one.php 将整个项目打包成 一个 php 文件,有网友 让我 整个asp版本的,今天下午抽空写了个 one.asp,使用方式基本一致,这次 增加了路径计算的功能,可以引用不同路径。

举个简单的应用场景,开发一个小的API系统,支持 XML、JSON输出。区别是 基础版(dev/dev.asp)只支持 Access,VIP版本(dev/vip.asp)支持 Access + SQL Server。这样VIP版本就需要在现在的基础上 增加 sqlserver的支持,增加额外的 配置项。开发过程只需要 按正常开发即可。

one.asp多项目、函数库、类库 统一为一个版本的方法


开发完毕后,通过 one.asp 打包成 index.asp 和 vip.asp 两个版本,整套程序都是一个独立的文件。

one.asp多项目、函数库、类库 统一为一个版本的方法


下图演示了 解析过程:

one.asp多项目、函数库、类库 统一为一个版本的方法


完整的测试代码 可以 访问:oneasp.rar 下载

核心代码 如下:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

 

' ====================================================

' 类名:One

' 作者:mqycn

' 博客:

' 源码:

' 说明:多项目 函数库、类库 统一为一个版本的方法

' ====================================================

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(开发版))

相关热词: 方法

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://www.juheyunku.com/jiaob/asp/8152.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

one.asp多项目、函数库、类库 统一为一个版本的方法

2020-12-23 编辑:wy

前几天 写的博客 多项目 函数库、类库 统一为一个版本的方法中提到 使用 one.php 将整个项目打包成 一个 php 文件,有网友 让我 整个asp版本的,今天下午抽空写了个 one.asp,使用方式基本一致,这次 增加了路径计算的功能,可以引用不同路径。

举个简单的应用场景,开发一个小的API系统,支持 XML、JSON输出。区别是 基础版(dev/dev.asp)只支持 Access,VIP版本(dev/vip.asp)支持 Access + SQL Server。这样VIP版本就需要在现在的基础上 增加 sqlserver的支持,增加额外的 配置项。开发过程只需要 按正常开发即可。

one.asp多项目、函数库、类库 统一为一个版本的方法


开发完毕后,通过 one.asp 打包成 index.asp 和 vip.asp 两个版本,整套程序都是一个独立的文件。

one.asp多项目、函数库、类库 统一为一个版本的方法


下图演示了 解析过程:

one.asp多项目、函数库、类库 统一为一个版本的方法


完整的测试代码 可以 访问:oneasp.rar 下载

核心代码 如下:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

 

' ====================================================

' 类名:One

' 作者:mqycn

' 博客:

' 源码:

' 说明:多项目 函数库、类库 统一为一个版本的方法

' ====================================================

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(开发版))

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://www.juheyunku.com/jiaob/asp/8152.shtml

相关文章

风云图片

推荐阅读

返回ASP频道首页