ASP Crazy 模版操作類(最簡(jiǎn)單的模板類、僅提供交流)
更新時(shí)間:2009年10月19日 16:00:26 投稿:mdxy-dxy
ASP Crazy 模版操作類 最簡(jiǎn)單的模板類需要的朋友可以參考下。
文件名:Awa_temp.Class.asp
復(fù)制代碼 代碼如下:
<%
'Crazy蛙!模板操作類
'作者Crazy~蛙! QQ:379969387 歡迎交流
'版本V1.0;
Class AwaTemp
Public aa
Private FSO,StrTemp,FileData,GetDatas,StrHtmlName,htmlwrite,StrLabel,StrLValues
'===========================================
'構(gòu)造函數(shù)_初始化FSO組件
'===========================================
Private Sub Class_Initialize()
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
End Sub
'===========================================
'構(gòu)析函數(shù)_銷毀FSO組件
'===========================================
Private Sub Class_terminate()
Set FSO=nothing
End Sub
'===========================================
'類屬性
'===========================================
'版本信息
Public Property Get Version
Version="Crazy~蛙! 模板操作類!V1.0版本;"
End Property
'獲取模板地址以及名稱
Public Property Let Temp(ByVal Values)
StrTemp=Values
End Property
'獲取生成文件的文件名
Public Property Let HtmlName(ByVal Values)
StrHtmlName=Values
End Property
'獲取標(biāo)簽
Public Property Let Label(ByVal Values)
StrLabel=Values
End Property
'獲取將標(biāo)簽替換的值
Public Property Let LValues(ByVal Values)
StrLValues=Values
End Property
'===========================================
'類方法
'===========================================
'檢查模板設(shè)置以及是否存在
Private Function Check()
If StrTemp="" Then
Check="<span style='color:red;'>錯(cuò)誤:未設(shè)置模板文件存儲(chǔ)位置!</span>"
Else
If FSO.FileExists(StrTemp)=false Then
Check="<span style='color:red;'>錯(cuò)誤:指定模板不存在!</span>"
Else
Check=true
End If
End If
End Function
'讀取模板頁
Public Sub ReadTemp()
If Check()<>true Then
Response.Write Check()
Response.End()
Else
Set GetDatas=FSO.OpenTextFile(Server.MapPath(StrTemp))
FileData=GetDatas.ReadAll
GetDatas.Close
Set GetData=nothing
End If
End Sub
'替換內(nèi)容
Public Function Rep()
If StrLabel="" Then
Response.Write "<span style='color:red;'>錯(cuò)誤:未設(shè)置欲替換的標(biāo)簽!</span>"
Response.End()
End If
If StrLValues="" Then
Response.Write "<span style='color:red;'>錯(cuò)誤:未設(shè)置替換標(biāo)簽的數(shù)據(jù)!</span>"
Response.End()
End If
FileData=Replace(FileData,StrLabel,StrLValues)
End Function
'輸出
Public Sub Echo()
Response.Write FileData
End Sub
'生成靜態(tài)頁面
Public Sub GetHtml()
If StrHtmlName="" Then
Response.Write "<span style='color:red;'>錯(cuò)誤:未設(shè)置生成Html文件存儲(chǔ)位置以及文件名稱!</span>"
Response.End()
End If
Set htmlwrite=FSO.CreateTextFile(Server.MapPath(StrHtmlName),true)
'寫入網(wǎng)頁內(nèi)容
htmlwrite.WriteLine FileData
htmlwrite.Close
set htmlwrite=Nothing
End Sub
End Class
%>
用法示例:
index.asp
復(fù)制代碼 代碼如下:
<!--#include file="Awa_temp.Class.asp"-->
<%
Set awa=New AwaTemp
With awa
.Temp="temp.tpl"
.ReadTemp
.Label="{tl1}"
.LValues="蛋/疼"
.Rep
.Echo
'.HtmlName="aa/index.html"
'.GetHtml
End With
Set awa=nothing
%>
模版
temp.tpl:
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標(biāo)題文檔</title>
</head>
<body>
<table width="200" border="1">
<tr>
<td>{tl1}</td>
<td>{tl2}</td>
<td>{tl3}</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
相關(guān)文章
asp 批量刪除選中的多條記錄的實(shí)現(xiàn)代碼
如果需要?jiǎng)h除記錄,一條一條的刪比較耗時(shí),所以批量刪除記錄是個(gè)不錯(cuò)的功能,原理就是利用asp數(shù)組來實(shí)現(xiàn)。2011-06-06asp #include file 與 #include virtual 的區(qū)別小結(jié)
簡(jiǎn)單來說,#include file后面跟的是文件的“相對(duì)路徑”, #include virtual后面跟的是文件的“絕對(duì)路徑”。2009-06-06用ASP+DLL實(shí)現(xiàn)WEB方式修改服務(wù)器時(shí)間
用ASP+DLL實(shí)現(xiàn)WEB方式修改服務(wù)器時(shí)間...2006-09-09Dom遍歷XML的一個(gè)例子,結(jié)果為樹狀結(jié)構(gòu)
Dom遍歷XML的一個(gè)例子,結(jié)果為樹狀結(jié)構(gòu)...2007-01-01asp實(shí)現(xiàn)圖片右鍵滑輪控制大小的函數(shù)
asp實(shí)現(xiàn)圖片右鍵滑輪控制大小的函數(shù)...2007-08-08