<% '================================================ ========== 'file: class_template.asp' version: 1.0 'Date: 2004-5-7' script write by rh 'description: ASP template class' ========== ======================================================= 'CopyRight ( C) 2004 Interflower Studios. ALL Rights Reserved. 'Web: http://www.interflower.cn' NEED HELP? Contact: Ranhuan@msn.com'================ ========================================== ======== =================================================== The part replaced in the template uses {{%}} represents the "loop in the template" "starting End Support once Nested 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 'acquired the main template' ========================= 取 PUBLIC SUB Settpl (TPLVAR) TPL from the variable = tplvar End Sub 'is removed from the DB, modify their own sql statement 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 ("Database Error!
") Response.end () end if TPL = RS ("Content") RS .Close set = Nothing end sub 'Remove Public SETTPLFILE (TPLFILE) DIM FSO, OXILE SET FSO = Server.createObject ("SCR ipting.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 "template file does not exist!
"end if set fso =
Nothing end sub 'getting block template' ========================= From variables remove public sub setblk (blkname, tplvar) Re.ignoreCase = True Re.global = true re.pattern = {{& blkname &}} TPL = Re.Replace (TPL, TPLVAR) RS.CLOSE End Sub 'Digital from the database DIM SUBSTBLKDB (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 'is removed from the file 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.C Lose Set Ole = Nothing Else Response.write "block template file does not exist!
"end if set fso = Nothing end sub 'sets the variable replacement value' =========================
Simple replacement of 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 'simple replacement of the additional data Public Sub AppendVar (sName, Svalue) If VAR_LIST.EXISTS (SNAME) TMP = var_list.item (sname) & svalue var_list.remove sname, tmp else var_list.add sname, svalue end if End sub 'cycle replacement' ===== =================== 'One-dimensional cycle start 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 'One-dimensional loop end public sub psblk (blkname) TMP = BLK_LIST.ITEM (BLKNAME) Re.ignoreCase = true re.global = true rue 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 'Two-dimensional cycle start 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) 'Respon se.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 'two-dimensional loop end 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 Replacement in the sub 'cycle PUBLIC SUB SETBLKVAR (S, V) if BLK_VAR_LIST.EXISTS (S) THEN BLK_VAR_LIST.REMOVE S BLK_VAR_LIST.ADD S, V ELSE BLST.ADD S, V ELSE BLK_VAR_LIST.ADD S, V end if End sub' parsing template and output content ' ======================== 'Performing parsing' can obtain web content by the following process, combined with FSO can generate static page public property gettpl Re.ignoreCase = True Re.global = True Re.pattern = "(" & {{& ") ([^}] )" &}} set matches = Re.execu TE (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 protection 'Output PUBLIC SUB PARSE RESPONSE.WRITE TPL End Subend Class%> <%' ===================
=================================================== : 2004-5-7 'Script Written By RH' Description: ASP Template Class' ================================ ========================= 'CopyRight (c) 2004 Interflower Studios. ALL Rights Reserved.' Web: http://www.interflower.cn 'NEED HELP? Contact: ranhuan@msn.com'========================================= ==================== =============================================================================================================================================== ============================================================================================================================================= bEGIN% -> start <-! eND% -> end its support once nested 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 'made the main template '========================' From the variable remove the public sub settpl (tplvar) TPL = TPLVAR END SUB 'from DB, modify SQL statement 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 ("Database Error!
") Response.end () end if TPL = rs ("content") rs.close set = nothing end sub 'removes public SUB from the file SetTPLFile (TPLFile) DIM FSO, OXILE SET FSO = Server.createObject ("scripting.filesystemObject") if fso.fileexists (Server.MAppath TPL_DIR & TPLFILE) "The set ofile = fso.opentextfile (server.mappath (tpl_dir & tplfile) TPL = Ofile.Readall Ofile.close Set Ofile = Nothing else response.write" Template file does not exist!
"end if set fso = Nothing end sub 'acquisition block template' ================
========= 'From the variable remove public sub setblk (blkname, tplvar) Re.ignoreCase = true re.global = true re.pattern = {& blkname &}} TPL = Re.Replace (TPL, tplvar) rs.Close End Sub 'is removed from the database 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' Remove Public SUB SetBlkfile (BLKNAME, TPLFILE) DIM FSO, OXILE 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 "block template file does not exist!
"end if set fso = Nothing end sub 'set variable replacement value' ======================== 'simple replacement 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
Simple replacement of additional data 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 'cycle replacement' ======================================================================================================================================================== Global = true re.pattern = " "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 'One-dimensional cycle end 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 'two dimensional cycle start 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 B LKNAME, "" 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 'Two-dimensional cycles End 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 'replacement cycle 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 'analysis template and output content' ====================== == 'Performing parsing' can obtain web content by the following process, combined with FSO can generate static pages public protection 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 'output Content Public Sub Parse Response.Write TPL End Subend Class%> <% '================================== =====
================== File: class_template.asp 'version: 1.0' date: 2004-5-7 'script write by rh' description: ASP TEMPLATE CLASS '== ============================================================================================================================================================================================================= ===== 'CopyRight (c) 2004 Interflower Studios. ALL Rights Reserved.' Web: http://www.interflower.cn 'NEED HELP? Contact: ranhuan@msn.com'======== =================================================== ============================================================================================================================================================================================================= ======== The replacement of the template is used for {{%}} to represent the cycle in the 'template to start end support for a nest 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 'acquired the main template' ============== ========= 'Remove the PUBLIC SUB set from the variable TPL = TPLVAR END SUB' from DB, modify SQL statement 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 ("Database Error! < Br> ") response.end () end if TPL = rs (" content ") rs.close set = Nothing end sub 'removes public sub settplfile (TPLFILE) DIM FSO, OXILE SET FSO = Server.createObject (" Scripting.filesystemObject ") if fso.fileexists (Server.Mappath) THEN SET OFILE = fso.opentextfile (Server.MAppath (TPL_DIR & TPLFILE)) TPL = Ofile.Readall Ofile.close Set ofile = Nothing else response.write "Template file does not exist!
"end if set fso = nothing end sub 'acquisition block template' =========================
Remove Public SUB Setblk (BLKNAME, TPLVAR) Re.ignoreCase = true re.global = true re.pattern = {{& bl, tplvar = {& br. Remove 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 'is removed from the file 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 "block template file does not exist!
"end if set fso = Nothing end sub 'set variable replacement value' ======================== 'simple replacement 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
Simple replacement of additional data 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 'cycle replacement' ======================================================================================================================================================== Global = true re.pattern = " "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 'One-dimensional cycle end 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 'two dimensional cycle start 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 B LKNAME, "" 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 'Two-dimensional cycles End 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 'replacement cycle 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 'analysis template and output content' ====================== == 'Performing parsing' can obtain web content by the following process, combined with FSO can generate static pages public protection 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 'output Content Public Sub Parse Response.write TPL End Subend Class%> BLOG:
http://blog.9cbs.net/ranhuan/