Publish a simple point of ASP Touch Board class

Source: Internet
Author: User
Tags date array key tagname variable touch
Oh, in fact, this writing has been quite a long time, look at the date inside know, just always do not want to publish, this time in a small forum, the original own that complex touch board engine modified a turn to use, because the ASP code and HTML code to separate, so the forum can be transformed style, In the process of using this touch plate engine found that it is still a bit insufficient function, that is, in the circular label replacement, but if the combination of an array can be easily realized, oh, the specific use of the moment do not say ... When you have time to write the tutorials.


<script language= "VBScript" runat= "Server" >

'--------------------------------------
' Copyright Description:
' Author: The cold month of the West building
' Date:2005-8-21
' HomeSite: Www.xilou.Net|-West Building Community-| // www.chinaCMS.org
' E-mail:ch_56@163.com
' qq:39949376 CMS Discussion group: 11497202
' Version: West Building template Engine V1.0 Compact version Xilou-easytemplate v1.0
'--------------------------------------
' Function Description:
' Set_block (blkname)
' Set_bvar (Tagname,tagvalue)
' Prase_block (blkname,blklist)
' Replace_block (blknamelist)
' Set_var (Tagname,tagvalue)
' Prase_temp ()
' OutPut ()
'--------------------------------------
' Variable Description:
' Key (), Value (), Num '//--------single label Save Array
' Bkey (), Bvalue (), Bnum '//--------block inside single label Save Array
' Temp '//----------template global variable
' Beginblockstart,beginblockend,endblockstart,endblockend '//----------block tab settings
' Varbegin,varend '//------------single label settings
' Re,match,mathes
'--------------------------------------
' Set Description:
' Block '//save the replaced chunk content
' Block_list '//Remove block, save the contents of the block
' BLOCKNC '//Take out blocks, save the entire block contents including the chunk label
'---------------------------------------

On Error Resume Next

Class easytemplate

Private Key (), Value (), Num
Private bkey (), Bvalue (), Bnum
Public BLOCK,BLOCK_LIST,BLOCKNC
Public Temp
Private Beginblockstart,beginblockend,endblockstart,endblockend
Private Varbegin,varend
Private re,match,mathes
'--------------------------------------------------------
Private Sub Class_Initialize
' Response.Write ' West Building template engine started, haha! <br> "
Set Block =createobject ("scripting.dictionary") ' Append content, update content
Set Block_list =createobject ("Scripting.Dictionary") ' stores chunk content
Set BLOCKNC =createobject ("scripting.dictionary") '//storage of block contents including block labels
Set Re=new REGEXP

ReDim Key (20)
ReDim Value (20)
Num=0
ReDim Bkey (20)
ReDim Bvalue (20)
Bnum=0
ReDim Pbblockname (20)
Blocknum=0
'------------default label mode------------
beginblockstart= "<beginblock:"
Beginblockend= ">"
endblockstart= "<endblock:"
Endblockend= ">"
Varbegin= "{Tag:"
Varend= "}"

End Sub

Private Sub Class_Terminate
Set block=nothing
Set block_list=nothing
Set blocknc=nothing
Set re=nothing

Erase Key
Erase Value
Erase Bkey
Erase bvalue
The ' Response.Write ' West Building template engine is over! "
End Sub

'-------------------------------------------------------
Public Property Let Settag (bs,be,es,ee,bg,ed) '//--------Reset label mode
Beginblockstart= BS
Beginblockend=be
Endblockstart=es
Endblockend=ee
Varbegin=bg
Varend=ed
End Property

'-------------------------------------------------------
Public Sub Set_var (tagname,tagvalue) ' single label resolution
Dim k
If IsArray (TagName) and IsArray (Tagvalue) Then
For K=lbound (TagName) to Ubound (TagName)
Key (Num) =tagname (k)
Value (Num) =tagvalue (k)
Num=num+1
If UBound (Key) =num then ' dynamically allocate space if the array is too small
ReDim Preserve Key (NUM+20)
ReDim Preserve Value (NUM+20)
End If
Next
Else
Key (Num) =tagname
Value (Num) =tagvalue
Num=num+1
If UBound (Key) =num Then
ReDim Preserve Key (NUM+20)
ReDim Preserve Value (NUM+20)
End If
End If
End Sub

Public Sub prase_temp () '//------------single label replacement
Dim i
For I=lbound (Key) to UBound (Value)
Temp=replace (Temp,varbegin&key (i) &varend,value (i))
Next
End Sub

' =============== block parsing ============================
Single label parsing in public Sub Set_bvar (tagname,tagvalue) ' blocks
Dim k
If IsArray (TagName) and IsArray (Tagvalue) Then
For K=lbound (TagName) to Ubound (TagName)
Bkey (Bnum) =tagname (k)
Bvalue (Bnum) =tagvalue (k)
Bnum=bnum+1
If UBound (bkey) =bnum then ' dynamically allocate space if the array is too small
ReDim Preserve Bkey (BNUM+20)
ReDim Preserve Bvalue (BNUM+20)
End If
Next
Else
Bkey (Bnum) =tagname
Bvalue (Bnum) =tagvalue
Bnum=bnum+1
If UBound (bkey) =bnum Then
ReDim Preserve Bkey (BNUM+20)
ReDim Preserve Bvalue (BNUM+20)
End If
End If
End Sub

Public Sub Set_block (Blkname) ' Set block, remove chunk contents
Re. Global=true
Re. Ignorecase=true
Re. pattern=beginblockstart&blkname&beginblockend& "([\s\s.] *?)" &endblockstart&blkname&endblockend
Set Matches=re. Execute (Temp)
Blocknc.add blkname,matches (0) '//establish the entire block name and corresponding key values
Match=matches (0). Submatches (0)
Block_list.add Blkname,match '//build block name and corresponding key value
Set matches=nothing
End Sub

Public Sub Prase_block (blkname) '//---parsing block
Dim blk_content,tag,k
Blk_content=block_list.item (Blkname)
K=lbound (Bkey)
For each tag in Bkey
Blk_content=replace (Blk_content,varbegin&tag&varend,bvalue (k))
K=k+1
Next

ReDim Bkey (20) ' re-declare array
ReDim Bvalue (20)
Bnum=0 ' initial number changed to 0

If Block.exists (blkname) Then '//non-duplicate record content
Dim M:m=block.item (Blkname)
Block.remove (Blkname)
Block.add blkname,blk_content
Else
Block.add blkname,blk_content
End If
End Sub
'==============================================
Public Sub Cleartag () '//----------Clear Excess label
Re. Global=true
Re. Ignorecase=true
Re. pattern=beginblockstart& "([\s\s.] *?)" &BeginBlockEnd& "([\s\s.] *?)" &EndBlockStart& "([\s\s.] *?)" &endblockend
Set Matches=re. Execute (Temp)
For the Match in matches
Temp=replace (Temp,match, "")
Next
Re. pattern=varbegin& "([\s\s.] *?)" &varend
Set Matches=re. Execute (Temp)
For the Match in matches
Temp=replace (Temp,match, "")
Next
End Sub
'=============================================
Public Sub output () '//----------outputs parsed template, method
Response.Write Temp
End Sub

End Class
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.