使用模板实现ASP代码与页面分离

2019-04-02 22:40:53于海丽

' End Property
' Public Property Get File()
' File = m_FileName
' End Property

'设置对未指定的标记的处理方式,有keep、remove、comment三种
Public Sub set_unknowns(ByVal unknowns)
m_Unknowns = unknowns
End Sub
Public Function get_unknowns()
get_unknowns = m_Unknowns
End Function
Public Property Let Unknowns(ByVal unknown)
m_Unknowns = unknown
End Property
Public Property Get Unknowns()
Unknowns = m_Unknowns
End Property

Public Sub set_block(ByVal Parent, ByVal BlockTag, ByVal Name)
Dim Matches
m_RegExp.Pattern = "<!--s+BEGIN " & BlockTag & "s+-->([sS.]*)<!--s+END " & BlockTag & "s+-->"
If Not m_BlockList.Exists(Parent) Then ShowError("未指定的块标记" & Parent)
set Matches = m_RegExp.Execute(m_BlockList.Item(Parent))
For Each Match In Matches
m_BlockList.Add BlockTag, Match.SubMatches(0)
m_BlockList.Item(Parent) = Replace(m_BlockList.Item(Parent), Match.Value, "{" & Name & "}")
Next
set Matches = nothing
End Sub

Public Sub set_var(ByVal Name, ByVal Value, ByVal Append)
Dim Val
If IsNull(Value) Then Val = "" Else Val = Value
If m_ValueList.Exists(Name) Then
If Append Then m_ValueList.Item(Name) = m_ValueList.Item(Name) & Val _
Else m_ValueList.Item(Name) = Val
Else
m_ValueList.Add Name, Value
End If
End Sub

Public Sub unset_var(ByVal Name)
If m_ValueList.Exists(Name) Then m_ValueList.Remove(Name)
End Sub

Private Function InstanceValue(ByVal BlockTag)
Dim keys, i
InstanceValue = m_BlockList.Item(BlockTag)
keys = m_ValueList.Keys
For i=0 To m_ValueList.Count-1
InstanceValue = Replace(InstanceValue, "{" & keys(i) & "}", m_ValueList.Item(keys(i)))
Next
End Function

Public Sub parse(ByVal Name, ByVal BlockTag, ByVal Append)
If Not m_BlockList.Exists(BlockTag) Then ShowError("未指定的 块标记" & Parent)
If m_ValueList.Exists(Name) Then
If Append Then m_ValueList.Item(Name) = m_ValueList.Item(Name) & InstanceValue(BlockTag) _
Else m_ValueList.Item(Name) = InstanceValue(BlockTag)
Else
m_ValueList.Add Name, InstanceValue(BlockTag)