《拓文asp.net网站内容管理系统》官方演示站。
 设为首页  
 收藏本站
 作者:黄振安
 QQ:53854651
首 页 开源拓文.NET编程网站编程网页设计图形图像数据库软件工程留言本
    站内搜索:  
您现在的位置: 拓文网络 → 网站编程 → ASP → ASP模板类实现一维循环和二维循环,从文件、数据库、[正文]

热 门 文 章

相 关 文 章
  • ASP.NET性能优化
  • ASP脚本循环语句
  • 在.NET框架应用程序中发送电子邮件
  • .net打包自动安装数据库
  • asp.net开发wap必备:更好的匹配手机设备
  • 用ashx动态生成文件
  • windows 2003下asp.Net站点无法使用用户名+密码的方
  • ASP.NET中17种正则表达式
  • 提高ASP.Net应用程序性能的十大方法
  • 一个通过web.Mail发送邮件的类
  • ASP模板类实现一维循环和二维循环,从文件、数据库、
     
    [作者:不详    转贴自:不详    点击数:    更新时间:2006-3-14 9:12:36]

    <%
    '=========================================================
    ' File: class_template.asp
    ' Version:1.0
    ' Date: 2004-5-7
    ' Script Written by R.H
    ' Description: ASP Template Class
    '=========================================================
    ' Copyright (C) 2004 Interflower Studios. All rights reserved.
    ' Web: http://www.interflower.cn
    ' Need help? Contact: ranhuan@msn.com
    '=========================================================

    '=========================================================
    '模板中替换的部分用{{%}}表示
    '模板中的循环用<!-- BEGIN % -->开始 <!-- END % -->结束 支持一次嵌套


    Class Template
         Private tmp
         Private tpl_dir, tpl, tpl_blk
         Private var_list, blk_list, blk_var_list
         Private re, match, matchs
         Private Sub class_Initialize
               sql =
               tpl_dir = templates/
               tpl =
               blk=
               Set var_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_var_list = Server.CreateObject(Scripting.Dictionary)
               Set re = New RegExp  
         End Sub

    '取得主体模板      
    '========================

    '从变量取出
         Public Sub SetTpl(tplvar)
               tpl = tplvar
         End Sub
         
    ' 从DB中取出,自己修改sql语句
         Public Sub SetTplDb(tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT content FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               If rs.RecordCount <> 1 Then
                     Response.Write(数据库错误!<br>)
                     Response.End()
               End If
               tpl = rs(content)
               rs.Close
               Set rs = Nothing
         End Sub
         
    '从文件取出
         Public Sub SetTplFile(tplfile)
               Dim FSO, oFile
               Set FSO = Server.Createobject(Scripting.FileSystemObject)
               If FSO.FileExists(Server.Mappath(tpl_dir & tplfile)) then
                     Set oFile = FSO.OpenTextFile(Server.Mappath(tpl_dir & tplfile))
                     tpl = oFile.ReadAll
                     oFile.Close
                     Set oFile = Nothing
               Else
                     Response.Write 模板文件不存在!<br>
               End if
               Set FSO = nothing
         End Sub

    '取得区块模板      
    '========================

    '从变量取出
         Public sub SetBlk(blkname, tplvar)
               re.IgnoreCase = True
               re.Global = True
               re.Pattern = {{ & blkname & }}
               tpl = re.Replace(tpl, tplvar)
               rs.Close
         End Sub

    '从数据库取出
         Public sub SetBlkDb(blkname, tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT * FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               tmp = rs(content)
               rs.Close
               SetBlk blkname, tmp
               set rs = Nothing
         End Sub

    '从文件取出
         Public sub SetBlkFile(blkname, tplfile)
               Dim FSO, oFile
               Set FSO = createobject(Scripting.FileSystemObject)
               If FSO.FileExists(server.mappath(tpl_dir &tplfile)) Then
                     Set oFile = FSO.OpenTextFile(Server.MapPath(tpl_dir &tplfile))
                     tmp = oFile.ReadAl
                     SetBlock blkname, tmp
                     oFile.Close
                     set oFile = Nothing
               Else
                     Response.Write 区块模板文件不存在!<br>
               End If
               Set FSO = Nothing
         End Sub
         
    '设置变量替换值      
    '========================

    '简单替换
         Public Sub SetVar(sName, sValue)
               If var_list.Exists(sName) then
                     var_list.Remove sName
                     var_list.Add sName, sValue
               Else
                     var_list.Add sName, sValue
               End if
         End Sub
         
    '简单替换 追加数据
         Public Sub AppendVar(sName, sValue)
               If var_list.Exists(sName) then
                     tmp = var_list.Item(sName) & sValue
                     var_list.Remove sName
                     var_list.Add sName, tmp
               Else
                     var_list.Add sName, sValue
               End If
         End Sub

    '循环替换      
    '========================      
         
    '一维循环开始
         Public Sub UdBlk(BlkName)
               tpl_blk = BlkName
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = <!--\s+BEGIN\s+( & BlkName & )\s+-->([\s\S.]*)<!--\s+END\s+\1\s+-->
               Set Matches = re.Execute(tpl)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           var_list.Add BlkName,
                           tpl = re.Replace(tpl, {{&BlkName&}})
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub

    '一维循环结束      
         Public Sub PsBlk(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = var_list.Item(BlkName) & tmp
               var_list.Remove BlkName
               var_list.Add BlkName, tmp

               blk_var_list.RemoveAll
         End Sub
         
    '二维循环开始
         Public Sub UdBlk2(BlkName)
               tmp = blk_list.Item(tpl_blk)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = <!--\s+BEGIN\s+( & BlkName & )\s+-->([\s\S.]*)<!--\s+END\s+\1\s+-->
               Set Matches = re.Execute(tmp)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           'response.Write match.SubMatches(1)
                           blk_var_list.Add BlkName,
                           tmp = re.Replace(tmp, {{&BlkName&}})
                           blk_list.ReMove tpl_blk
                           blk_list.Add tpl_blk, tmp
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub      
         
    '二维循环结束      
         Public Sub PsBlk2(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = blk_var_list.Item(BlkName) & tmp
               blk_var_list.RemoveAll
               blk_var_list.Add BlkName, tmp
         End Sub

    '循环中的替换
         Public Sub SetBlkVar(s, v)
               If blk_var_list.Exists(s) then
                     blk_var_list.Remove s
                     blk_var_list.Add s, v
               Else
                     blk_var_list.Add s, v
               End if
         End Sub

    '解析模板和输出内容      
    '========================

    '执行解析
    '可以通过下面的过程取得网页内容,结合fso可以生成静态页面
         Public Property GetTpl
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & {{ & )([^}]+) & }}
               Set Matches = re.Execute(tpl)  
               for each match in Matches
                     if var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.Value
                           tpl = re.Replace(tpl, var_list.Item(match.SubMatches(1)))
                     end if
               next
               GetTpl = tpl
         End Property
         
    '输出内容
         Public Sub Parse
               Response.Write tpl
         End Sub
    End Class
    %><%
    '=========================================================
    ' File: class_template.asp
    ' Version:1.0
    ' Date: 2004-5-7
    ' Script Written by R.H
    ' Description: ASP Template Class
    '=========================================================
    ' Copyright (C) 2004 Interflower Studios. All rights reserved.
    ' Web: http://www.interflower.cn
    ' Need help? Contact: ranhuan@msn.com
    '=========================================================

    '=========================================================
    '模板中替换的部分用{{%}}表示
    '模板中的循环用<!-- BEGIN % -->开始 <!-- END % -->结束 支持一次嵌套


    Class Template
         Private tmp
         Private tpl_dir, tpl, tpl_blk
         Private var_list, blk_list, blk_var_list
         Private re, match, matchs
         Private Sub class_Initialize
               sql =
               tpl_dir = templates/
               tpl =
               blk=
               Set var_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_var_list = Server.CreateObject(Scripting.Dictionary)
               Set re = New RegExp  
         End Sub

    '取得主体模板      
    '========================

    '从变量取出
         Public Sub SetTpl(tplvar)
               tpl = tplvar
         End Sub
         
    ' 从DB中取出,自己修改sql语句
         Public Sub SetTplDb(tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT content FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               If rs.RecordCount <> 1 Then
                     Response.Write(数据库错误!<br>)
                     Response.End()
               End If
               tpl = rs(content)
               rs.Close
               Set rs = Nothing
         End Sub
         
    '从文件取出
         Public Sub SetTplFile(tplfile)
               Dim FSO, oFile
               Set FSO = Server.Createobject(Scripting.FileSystemObject)
               If FSO.FileExists(Server.Mappath(tpl_dir & tplfile)) then
                     Set oFile = FSO.OpenTextFile(Server.Mappath(tpl_dir & tplfile))
                     tpl = oFile.ReadAll
                     oFile.Close
                     Set oFile = Nothing
               Else
                     Response.Write 模板文件不存在!<br>
               End if
               Set FSO = nothing
         End Sub

    '取得区块模板      
    '========================

    '从变量取出
         Public sub SetBlk(blkname, tplvar)
               re.IgnoreCase = True
               re.Global = True
               re.Pattern = {{ & blkname & }}
               tpl = re.Replace(tpl, tplvar)
               rs.Close
         End Sub

    '从数据库取出
         Public sub SetBlkDb(blkname, tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT * FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               tmp = rs(content)
               rs.Close
               SetBlk blkname, tmp
               set rs = Nothing
         End Sub

    '从文件取出
         Public sub SetBlkFile(blkname, tplfile)
               Dim FSO, oFile
               Set FSO = createobject(Scripting.FileSystemObject)
               If FSO.FileExists(server.mappath(tpl_dir &tplfile)) Then
                     Set oFile = FSO.OpenTextFile(Server.MapPath(tpl_dir &tplfile))
                     tmp = oFile.ReadAl
                     SetBlock blkname, tmp
                     oFile.Close
                     set oFile = Nothing
               Else
                     Response.Write 区块模板文件不存在!<br>
               End If
               Set FSO = Nothing
         End Sub
         
    '设置变量替换值      
    '========================

    '简单替换
         Public Sub SetVar(sName, sValue)
               If var_list.Exists(sName) then
                     var_list.Remove sName
                     var_list.Add sName, sValue
               Else
                     var_list.Add sName, sValue
               End if
         End Sub
         
    '简单替换 追加数据
         Public Sub AppendVar(sName, sValue)
               If var_list.Exists(sName) then
                     tmp = var_list.Item(sName) & sValue
                     var_list.Remove sName
                     var_list.Add sName, tmp
               Else
                     var_list.Add sName, sValue
               End If
         End Sub

    '循环替换      
    '========================      
         
    '一维循环开始
         Public Sub UdBlk(BlkName)
               tpl_blk = BlkName
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = <!--\s+BEGIN\s+( & BlkName & )\s+-->([\s\S.]*)<!--\s+END\s+\1\s+-->
               Set Matches = re.Execute(tpl)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           var_list.Add BlkName,
                           tpl = re.Replace(tpl, {{&BlkName&}})
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub

    '一维循环结束      
         Public Sub PsBlk(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = var_list.Item(BlkName) & tmp
               var_list.Remove BlkName
               var_list.Add BlkName, tmp

               blk_var_list.RemoveAll
         End Sub
         
    '二维循环开始
         Public Sub UdBlk2(BlkName)
               tmp = blk_list.Item(tpl_blk)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = <!--\s+BEGIN\s+( & BlkName & )\s+-->([\s\S.]*)<!--\s+END\s+\1\s+-->
               Set Matches = re.Execute(tmp)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           'response.Write match.SubMatches(1)
                           blk_var_list.Add BlkName,
                           tmp = re.Replace(tmp, {{&BlkName&}})
                           blk_list.ReMove tpl_blk
                           blk_list.Add tpl_blk, tmp
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub      
         
    '二维循环结束      
         Public Sub PsBlk2(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = blk_var_list.Item(BlkName) & tmp
               blk_var_list.RemoveAll
               blk_var_list.Add BlkName, tmp
         End Sub

    '循环中的替换
         Public Sub SetBlkVar(s, v)
               If blk_var_list.Exists(s) then
                     blk_var_list.Remove s
                     blk_var_list.Add s, v
               Else
                     blk_var_list.Add s, v
               End if
         End Sub

    '解析模板和输出内容      
    '========================

    '执行解析
    '可以通过下面的过程取得网页内容,结合fso可以生成静态页面
         Public Property GetTpl
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & {{ & )([^}]+) & }}
               Set Matches = re.Execute(tpl)  
               for each match in Matches
                     if var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.Value
                           tpl = re.Replace(tpl, var_list.Item(match.SubMatches(1)))
                     end if
               next
               GetTpl = tpl
         End Property
         
    '输出内容
         Public Sub Parse
               Response.Write tpl
         End Sub
    End Class
    %><%
    '=========================================================
    ' File: class_template.asp
    ' Version:1.0
    ' Date: 2004-5-7
    ' Script Written by R.H
    ' Description: ASP Template Class
    '=========================================================
    ' Copyright (C) 2004 Interflower Studios. All rights reserved.
    ' Web: http://www.interflower.cn
    ' Need help? Contact: ranhuan@msn.com
    '=========================================================

    '=========================================================
    '模板中替换的部分用{{%}}表示
    '模板中的循环用<!-- BEGIN % -->开始 <!-- END % -->结束 支持一次嵌套


    Class Template
         Private tmp
         Private tpl_dir, tpl, tpl_blk
         Private var_list, blk_list, blk_var_list
         Private re, match, matchs
         Private Sub class_Initialize
               sql =
               tpl_dir = templates/
               tpl =
               blk=
               Set var_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_var_list = Server.CreateObject(Scripting.Dictionary)
               Set re = New RegExp  
         End Sub

    '取得主体模板      
    '========================

    '从变量取出
         Public Sub SetTpl(tplvar)
               tpl = tplvar
         End Sub
         
    ' 从DB中取出,自己修改sql语句
         Public Sub SetTplDb(tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT content FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               If rs.RecordCount <> 1 Then
                     Response.Write(数据库错误!<br>)
                     Response.End()
               End If
               tpl = rs(content)
               rs.Close
               Set rs = Nothing
         End Sub
         
    '从文件取出
         Public Sub SetTplFile(tplfile)
               Dim FSO, oFile
               Set FSO = Server.Createobject(Scripting.FileSystemObject)
               If FSO.FileExists(Server.Mappath(tpl_dir & tplfile)) then
                     Set oFile = FSO.OpenTextFile(Server.Mappath(tpl_dir & tplfile))
                     tpl = oFile.ReadAll
                     oFile.Close
                     Set oFile = Nothing
               Else
                     Response.Write 模板文件不存在!<br>
               End if
               Set FSO = nothing
         End Sub

    '取得区块模板      
    '========================

    '从变量取出
         Public sub SetBlk(blkname, tplvar)
               re.IgnoreCase = True
               re.Global = True
               re.Pattern = {{ & blkname & }}
               tpl = re.Replace(tpl, tplvar)
               rs.Close
         End Sub

    '从数据库取出
         Public sub SetBlkDb(blkname, tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT * FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               tmp = rs(content)
               rs.Close
               SetBlk blkname, tmp
               set rs = Nothing
         End Sub

    '从文件取出
         Public sub SetBlkFile(blkname, tplfile)
               Dim FSO, oFile
               Set FSO = createobject(Scripting.FileSystemObject)
               If FSO.FileExists(server.mappath(tpl_dir &tplfile)) Then
                     Set oFile = FSO.OpenTextFile(Server.MapPath(tpl_dir &tplfile))
                     tmp = oFile.ReadAl
                     SetBlock blkname, tmp
                     oFile.Close
                     set oFile = Nothing
               Else
                     Response.Write 区块模板文件不存在!<br>
               End If
               Set FSO = Nothing
         End Sub
         
    '设置变量替换值      
    '========================

    '简单替换
         Public Sub SetVar(sName, sValue)
               If var_list.Exists(sName) then
                     var_list.Remove sName
                     var_list.Add sName, sValue
               Else
                     var_list.Add sName, sValue
               End if
         End Sub
         
    '简单替换 追加数据
         Public Sub AppendVar(sName, sValue)
               If var_list.Exists(sName) then
                     tmp = var_list.Item(sName) & sValue
                     var_list.Remove sName
                     var_list.Add sName, tmp
               Else
                     var_list.Add sName, sValue
               End If
         End Sub

    '循环替换      
    '========================      
         
    '一维循环开始
         Public Sub UdBlk(BlkName)
               tpl_blk = BlkName
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = <!--\s+BEGIN\s+( & BlkName & )\s+-->([\s\S.]*)<!--\s+END\s+\1\s+-->
               Set Matches = re.Execute(tpl)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           var_list.Add BlkName,
                           tpl = re.Replace(tpl, {{&BlkName&}})
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub

    '一维循环结束      
         Public Sub PsBlk(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = var_list.Item(BlkName) & tmp
               var_list.Remove BlkName
               var_list.Add BlkName, tmp

               blk_var_list.RemoveAll
         End Sub
         
    '二维循环开始
         Public Sub UdBlk2(BlkName)
               tmp = blk_list.Item(tpl_blk)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = <!--\s+BEGIN\s+( & BlkName & )\s+-->([\s\S.]*)<!--\s+END\s+\1\s+-->
               Set Matches = re.Execute(tmp)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           'response.Write match.SubMatches(1)
                           blk_var_list.Add BlkName,
                           tmp = re.Replace(tmp, {{&BlkName&}})
                           blk_list.ReMove tpl_blk
                           blk_list.Add tpl_blk, tmp
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub      
         
    '二维循环结束      
         Public Sub PsBlk2(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = blk_var_list.Item(BlkName) & tmp
               blk_var_list.RemoveAll
               blk_var_list.Add BlkName, tmp
         End Sub

    '循环中的替换
         Public Sub SetBlkVar(s, v)
               If blk_var_list.Exists(s) then
                     blk_var_list.Remove s
                     blk_var_list.Add s, v
               Else
                     blk_var_list.Add s, v
               End if
         End Sub

    '解析模板和输出内容      
    '========================

    '执行解析
    '可以通过下面的过程取得网页内容,结合fso可以生成静态页面
         Public Property GetTpl
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & {{ & )([^}]+) & }}
               Set Matches = re.Execute(tpl)  
               for each match in Matches
                     if var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.Value
                           tpl = re.Replace(tpl, var_list.Item(match.SubMatches(1)))
                     end if
               next
               GetTpl = tpl
         End Property
         
    '输出内容
         Public Sub Parse
               Response.Write tpl
         End Sub
    End Class
    %>

    <%
    '=========================================================
    ' File: class_template.asp
    ' Version:1.0
    ' Date: 2004-5-7
    ' Script Written by R.H
    ' Description: ASP Template Class
    '=========================================================
    ' Copyright (C) 2004 Interflower Studios. All rights reserved.
    ' Web: http://www.interflower.cn
    ' Need help? Contact: ranhuan@msn.com
    '=========================================================

    '=========================================================
    '模板中替换的部分用{{%}}表示
    '模板中的循环用开始 结束 支持一次嵌套


    Class Template
         Private tmp
         Private tpl_dir, tpl, tpl_blk
         Private var_list, blk_list, blk_var_list
         Private re, match, matchs
         Private Sub class_Initialize
               sql =
               tpl_dir = templates/
               tpl =
               blk=
               Set var_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_var_list = Server.CreateObject(Scripting.Dictionary)
               Set re = New RegExp  
         End Sub

    '取得主体模板      
    '========================

    '从变量取出
         Public Sub SetTpl(tplvar)
               tpl = tplvar
         End Sub
         
    ' 从DB中取出,自己修改sql语句
         Public Sub SetTplDb(tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT content FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               If rs.RecordCount <> 1 Then
                     Response.Write(数据库错误!
    )
                     Response.End()
               End If
               tpl = rs(content)
               rs.Close
               Set rs = Nothing
         End Sub
         
    '从文件取出
         Public Sub SetTplFile(tplfile)
               Dim FSO, oFile
               Set FSO = Server.Createobject(Scripting.FileSystemObject)
               If FSO.FileExists(Server.Mappath(tpl_dir & tplfile)) then
                     Set oFile = FSO.OpenTextFile(Server.Mappath(tpl_dir & tplfile))
                     tpl = oFile.ReadAll
                     oFile.Close
                     Set oFile = Nothing
               Else
                     Response.Write 模板文件不存在!

               End if
               Set FSO = nothing
         End Sub

    '取得区块模板      
    '========================

    '从变量取出
         Public sub SetBlk(blkname, tplvar)
               re.IgnoreCase = True
               re.Global = True
               re.Pattern = {{ & blkname & }}
               tpl = re.Replace(tpl, tplvar)
               rs.Close
         End Sub

    '从数据库取出
         Public sub SetBlkDb(blkname, tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT * FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               tmp = rs(content)
               rs.Close
               SetBlk blkname, tmp
               set rs = Nothing
         End Sub

    '从文件取出
         Public sub SetBlkFile(blkname, tplfile)
               Dim FSO, oFile
               Set FSO = createobject(Scripting.FileSystemObject)
               If FSO.FileExists(server.mappath(tpl_dir &tplfile)) Then
                     Set oFile = FSO.OpenTextFile(Server.MapPath(tpl_dir &tplfile))
                     tmp = oFile.ReadAl
                     SetBlock blkname, tmp
                     oFile.Close
                     set oFile = Nothing
               Else
                     Response.Write 区块模板文件不存在!

               End If
               Set FSO = Nothing
         End Sub
         
    '设置变量替换值      
    '========================

    '简单替换
         Public Sub SetVar(sName, sValue)
               If var_list.Exists(sName) then
                     var_list.Remove sName
                     var_list.Add sName, sValue
               Else
                     var_list.Add sName, sValue
               End if
         End Sub
         
    '简单替换 追加数据
         Public Sub AppendVar(sName, sV, alue)
               If var_list.Exists(sName) then
                     tmp = var_list.Item(sName) & sValue
                     var_list.Remove sName
                     var_list.Add sName, tmp
               Else
                     var_list.Add sName, sValue
               End If
         End Sub

    '循环替换      
    '========================      
         
    '一维循环开始
         Public Sub UdBlk(BlkName)
               tpl_blk = BlkName
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ([\s\S.]*)
               Set Matches = re.Execute(tpl)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           var_list.Add BlkName,
                           tpl = re.Replace(tpl, {{&BlkName&}})
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub

    '一维循环结束      
         Public Sub PsBlk(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = var_list.Item(BlkName) & tmp
               var_list.Remove BlkName
               var_list.Add BlkName, tmp

               blk_var_list.RemoveAll
         End Sub
         
    '二维循环开始
         Public Sub UdBlk2(BlkName)
               tmp = blk_list.Item(tpl_blk)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ([\s\S.]*)
               Set Matches = re.Execute(tmp)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           'response.Write match.SubMatches(1)
                           blk_var_list.Add BlkName,
                           tmp = re.Replace(tmp, {{&BlkName&}})
                           blk_list.ReMove tpl_blk
                           blk_list.Add tpl_blk, tmp
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub      
         
    '二维循环结束      
         Public Sub PsBlk2(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = blk_var_list.Item(BlkName) & tmp
               blk_var_list.RemoveAll
               blk_var_list.Add BlkName, tmp
         End Sub

    '循环中的替换
         Public Sub SetBlkVar(s, v)
               If blk_var_list.Exists(s) then
                     blk_var_list.Remove s
                     blk_var_list.Add s, v
               Else
                     blk_var_list.Add s, v
               End if
         End Sub

    '解析模板和输出内容      
    '========================

    '执行解析
    '可以通过下面的过程取得网页内容,结合fso可以生成静态页面
         Public Property GetTpl
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & {{ & )([^}]+) & }}
               Set Matches = re.Execute(tpl)  
               for each match in Matches
                     if var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.Value
                           tpl = re.Replace(tpl, var_list.Item(match.SubMatches(1)))
                     end if
               next
               GetTpl = tpl
         End Property
         
    '输出内容
         Public Sub Parse
               Response.Write tpl
         End Sub
    End Class
    %><%
    '=========================================================
    ' File: class_template.asp
    ' Version:1.0
    ' Date: 2004-5-7
    ' Script Written by R.H
    ' Description: ASP Template Class
    '=========================================================
    ' Copyright (C) 2004 Interflower Studios. All rights reserved.
    ' Web: http://www.interflower.cn
    ' Need help? Contact: ranhuan@msn.com
    '=========================================================

    '=========================================================
    '模板中替换的部分用{{%}}表示
    '模板中的循环用开始 结束 支持一次嵌套


    Class Template
         Private tmp
         Private tpl_dir, tpl, tpl_blk
         Private var_list, blk_list, blk_var_list
         Private re, match, matchs
         Private Sub class_Initialize
               sql =
               tpl_dir = templates/
               tpl =
               blk=
               Set var_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_var_list = Server.CreateObject(Scripting.Dictionary)
               Set re = New RegExp  
         End Sub

    '取得主体模板      
    '========================

    '从变量取出
         Public Sub SetTpl(tplvar)
               tpl = tplvar
         End Sub
         
    ' 从DB中取出,自己修改sql语句
         Public Sub SetTplDb(tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT content FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               If rs.RecordCount <> 1 Then
                     Response.Write(数据库错误!
    )
                     Response.End()
               End If
               tpl = rs(content)
               rs.Close
               Set rs = Nothing
         End Sub
         
    '从文件取出
         Public Sub SetTplFile(tplfile)
               Dim FSO, oFile
               Set FSO = Server.Createobject(Scripting.FileSystemObject)
               If FSO.FileExists(Server.Mappath(tpl_dir & tplfile)) then
                     Set oFile = FSO.OpenTextFile(Server.Mappath(tpl_dir & tplfile))
                     tpl = oFile.ReadAll
                     oFile.Close
                     Set oFile = Nothing
               Else
                     Response.Write 模板文件不存在!

               End if
               Set FSO = nothing
         End Sub

    '取得区块模板      
    '========================

    '从变量取出
         Public sub SetBlk(blkname, tplvar)
               re.IgnoreCase = True
               re.Global = True
               re.Pattern = {{ & blkname & }}
               tpl = re.Replace(tpl, tplvar)
               rs.Close
         End Sub

    '从数据库取出
         Public sub SetBlkDb(blkname, tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT * FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               tmp = rs(content)
               rs.Close
               SetBlk blkname, tmp
               set rs = Nothing
         End Sub

    '从文件取出
         Public sub SetBlkFile(blkname, tplfile)
               Dim FSO, oFile
               Set FSO = createobject(Scripting.FileSystemObject)
               If FSO.FileExists(server.mappath(tpl_dir &tplfile)) Then
                     Set oFile = FSO.OpenTextFile(Server.MapPath(tpl_dir &tplfile))
                     tmp = oFile.ReadAl
                     SetBlock blkname, tmp
                     oFile.Close
                     set oFile = Nothing
               Else
                     Response.Write 区块模板文件不存在!

               End If
               Set FSO = Nothing
         End Sub
         
    '设置变量替换值      
    '========================

    '简单替换
         Public Sub SetVar(sName, sValue)
               If var_list.Exists(sName) then
                     var_list.Remove sName
                     var_list.Add sName, sValue
               Else
                     var_list.Add sName, sValue
               End if
         End Sub
         
    '简单替换 追加数据
         Public Sub AppendVar(sName, sValue)
               If var_list.Exists(sName) then
                     tmp = var_list.Item(sName) & sValue
                     var_list.Remove sName
                     var_list.Add sName, tmp
               Else
                     var_list.Add sName, sValue
               End If
         End Sub

    '循环替换      
    '========================      
         
    '一维循环开始
         Public Sub UdBlk(BlkName)
               tpl_blk = BlkName
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ([\s\S.]*)
               Set Matches = re.Execute(tpl)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           var_list.Add BlkName,
                           tpl = re.Replace(tpl, {{&BlkName&}})
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub

    '一维循环结束      
         Public Sub PsBlk(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = var_list.Item(BlkName) & tmp
               var_list.Remove BlkName
               var_list.Add BlkName, tmp

               blk_var_list.RemoveAll
         End Sub
         
    '二维循环开始
         Public Sub UdBlk2(BlkName)
               tmp = blk_list.Item(tpl_blk)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ([\s\S.]*)
               Set Matches = re.Execute(tmp)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           'response.Write match.SubMatches(1)
                           blk_var_list.Add BlkName,
                           tmp = re.Replace(tmp, {{&BlkName&}})
                           blk_list.ReMove tpl_blk
                           blk_list.Add tpl_blk, tmp
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub      
         
    '二维循环结束      
         Public Sub PsBlk2(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = blk_var_list.Item(BlkName) & tmp
               blk_var_list.RemoveAll
               blk_var_list.Add BlkName, tmp
         End Sub

    '循环中的替换
         Public Sub SetBlkVar(s, v)
               If blk_var_list.Exists(s) then
                     blk_var_list.Remove s
                     blk_var_list.Add s, v
               Else
                     blk_var_list.Add s, v
               End if
         End Sub

    '解析模板和输出内容      
    '========================

    '执行解析
    '可以通过下面的过程取得网页内容,结合fso可以生成静态页面
         Public Property GetTpl
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & {{ & )([^}]+) & }}
               Set Matches = re.Execute(tpl)  
               for each match in Matches
                     if var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.Value
                           tpl = re.Replace(tpl, var_list.Item(match.SubMatches(1)))
                     end if
               next
               GetTpl = tpl
         End Property
         
    '输出内容
         Public Sub Parse
               Response.Write tpl
         End Sub
    End Class
    %><%
    '=========================================================
    ' File: class_template.asp
    ' Version:1.0
    ' Date: 2004-5-7
    ' Script Written by R.H
    ' Description: ASP Template Class
    '=========================================================
    ' Copyright (C) 2004 Interflower Studios. All rights reserved.
    ' Web: http://www.interflower.cn
    ' Need help? Contact: ranhuan@msn.com
    '=========================================================

    '=========================================================
    '模板中替换的部分用{{%}}表示
    '模板中的循环用开始 结束 支持一次嵌套


    Class Template
         Private tmp
         Private tpl_dir, tpl, tpl_blk
         Private var_list, blk_list, blk_var_list
         Private re, match, matchs
         Private Sub class_Initialize
               sql =
               tpl_dir = templates/
               tpl =
               blk=
               Set var_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_list = Server.CreateObject(Scripting.Dictionary)
               Set blk_var_list = Server.CreateObject(Scripting.Dictionary)
               Set re = New RegExp  
         End Sub

    '取得主体模板      
    '========================

    '从变量取出
         Public Sub SetTpl(tplvar)
               tpl = tplvar
         End Sub
         
    ' 从DB中取出,自己修改sql语句
         Public Sub SetTplDb(tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT content FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               If rs.RecordCount <> 1 Then
                     Response.Write(数据库错误!
    )
                     Response.End()
               End If
               tpl = rs(content)
               rs.Close
               Set rs = Nothing
         End Sub
         
    '从文件取出
         Public Sub SetTplFile(tplfile)
               Dim FSO, oFile
               Set FSO = Server.Createobject(Scripting.FileSystemObject)
               If FSO.FileExists(Server.Mappath(tpl_dir & tplfile)) then
                     Set oFile = FSO.OpenTextFile(Server.Mappath(tpl_dir & tplfile))
                     tpl = oFile.ReadAll
                     oFile.Close
                     Set oFile = Nothing
               Else
                     Response.Write 模板文件不存在!

               End if
               Set FSO = nothing
         End Sub

    '取得区块模板      
    '========================

    '从变量取出
         Public sub SetBlk(blkname, tplvar)
               re.IgnoreCase = True
               re.Global = True
               re.Pattern = {{ & blkname & }}
               tpl = re.Replace(tpl, tplvar)
               rs.Close
         End Sub

    '从数据库取出
         Public sub SetBlkDb(blkname, tplname)
               Dim sql, rs
               Set rs = Server.CreateObject(ADODB.RecordSet)
               sql = SELECT * FROM templates WHERE name = '&tplname&'
               rs.Open sql,conn,1,1
               tmp = rs(content)
               rs.Close
               SetBlk blkname, tmp
               set rs = Nothing
         End Sub

    '从文件取出
         Public sub SetBlkFile(blkname, tplfile)
               Dim FSO, oFile
               Set FSO = createobject(Scripting.FileSystemObject)
               If FSO.FileExists(server.mappath(tpl_dir &tplfile)) Then
                     Set oFile = FSO.OpenTextFile(Server.MapPath(tpl_dir &tplfile))
                     tmp = oFile.ReadAl
                     SetBlock blkname, tmp
                     oFile.Close
                     set oFile = Nothing
               Else
                     Response.Write 区块模板文件不存在!

               End If
               Set FSO = Nothing
         End Sub
         
    '设置变量替换值      
    '========================

    '简单替换
         Public Sub SetVar(sName, sValue)
               If var_list.Exists(sName) then
                     var_list.Remove sName
                     var_list.Add sName, sValue
               Else
                     var_list.Add sName, sValue
               End if
         End Sub
         
    '简单替换 追加数据
         Public Sub AppendVar(sName, sValue)
               If var_list.Exists(sName) then
                     tmp = var_list.Item(sName) & sValue
                     var_list.Remove sName
                     var_list.Add sName, tmp
               Else
                     var_list.Add sName, sValue
               End If
         End Sub

    '循环替换      
    '========================      
         
    '一维循环开始
         Public Sub UdBlk(BlkName)
               tpl_blk = BlkName
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ([\s\S.]*)
               Set Matches = re.Execute(tpl)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           var_list.Add BlkName,
                           tpl = re.Replace(tpl, {{&BlkName&}})
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub

    '一维循环结束      
         Public Sub PsBlk(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = var_list.Item(BlkName) & tmp
               var_list.Remove BlkName
               var_list.Add BlkName, tmp

               blk_var_list.RemoveAll
         End Sub
         
    '二维循环开始
         Public Sub UdBlk2(BlkName)
               tmp = blk_list.Item(tpl_blk)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ([\s\S.]*)
               Set Matches = re.Execute(tmp)
               If Matches.Count > 0 Then
                     Set match = Matches
                     For Each match In Matches
                           blk_list.Add BlkName, match.SubMatches(1)
                           'response.Write match.SubMatches(1)
                           blk_var_list.Add BlkName,
                           tmp = re.Replace(tmp, {{&BlkName&}})
                           blk_list.ReMove tpl_blk
                           blk_list.Add tpl_blk, tmp
                     next
               Else
                     Response.Write Block & BlkName & does not exists!
               End If      
         end sub      
         
    '二维循环结束      
         Public Sub PsBlk2(BlkName)
               tmp = blk_list.Item(BlkName)
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & p_var_tag_o & )([^}]+) & p_var_tag_c
               Set Matches = re.Execute(tmp)  
               for each match in Matches
                     if blk_var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.value
                           tmp = re.Replace(tmp, blk_var_list.Item(match.SubMatches(1)))
                     end if
               next
               tmp = blk_var_list.Item(BlkName) & tmp
               blk_var_list.RemoveAll
               blk_var_list.Add BlkName, tmp
         End Sub

    '循环中的替换
         Public Sub SetBlkVar(s, v)
               If blk_var_list.Exists(s) then
                     blk_var_list.Remove s
                     blk_var_list.Add s, v
               Else
                     blk_var_list.Add s, v
               End if
         End Sub

    '解析模板和输出内容      
    '========================

    '执行解析
    '可以通过下面的过程取得网页内容,结合fso可以生成静态页面
         Public Property GetTpl
               re.IgnoreCase = True
               re.Global = True

               re.Pattern = ( & {{ & )([^}]+) & }}
               Set Matches = re.Execute(tpl)  
               for each match in Matches
                     if var_list.Exists(match.SubMatches(1)) then
                           re.Pattern = match.Value
                           tpl = re.Replace(tpl, var_list.Item(match.SubMatches(1)))
                     end if
               next
               GetTpl = tpl
         End Property
         
    '输出内容
         Public Sub Parse
               Response.Write tpl
         End Sub
    End Class
    %>
    首页 | 1 | 尾页  共 1 页
     
    hch004 打印本页 关闭窗口

         文 章 评 论
    评论人 查看该文章的评论 发表时间
       笔 名* : 0 50分 60分 70分 80分 90分 100分
    评论内容 *: (最多1000字。当前字数:0)


    没有相关评论,欢迎您参与!

    - 关于本站 - 网站帮助 - 下载声明 - 友情连接 - 网站地图 -
    Copyright © 2005-2006 myTopWin.Com. All Rights Reserved . [桂ICP备06004496号]