当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP Crazy 模版操作类(最简单的模板类、仅提供交流)

ASP
ASP字符串大写转换成小写 ASP小写转换成大写 ucase lcase
asp base64加解密函数代码
Discuz!NT 论坛整合ASP程序论坛
discuz 2.0整合asp系统,用户添加函数
P3P 和 跨域 (cross-domain) cookie 访问(读取和设置)
通过asp程序来创建access数据库
检查access数据库中是否存在某个名字的表的asp代码
asp #include file 与 #include virtual 的区别小结
一个带采集远程文章内容,保存图片,生成文件等完整的采集功能
asp 横排显示数据
asp base64 utf-8为了兼容asp.net的base64
两个非常规ASP木马(可躲过扫描)
asp DateDiff实现文字在特定时间后消失
ASP所有的Session变量获取实现代码
关于ASP eof与bof 区别分析
asp ajax注册验证之 防止用户名输入空格
asp sqlserver 执行存储过程返回记录集报对象关闭时不允许操作
ASP 获取文件扩展名函数getFileExt()
asp 简单分页代码
asp删除mssql数据库中没有记录的图片代码

ASP Crazy 模版操作类(最简单的模板类、仅提供交流)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 217 ::
收藏到网摘: n/a

ASP Crazy 模版操作类 最简单的模板类需要的朋友可以参考下。 文件名:Awa_temp.Class.asp
复制代码 代码如下:

<%
'Crazy蛙!模板操作类
'作者Crazy~蛙! QQ:379969387 欢迎交流
'版本V1.0;
Class AwaTemp
Public aa
Private FSO,StrTemp,FileData,GetDatas,StrHtmlName,htmlwrite,StrLabel,StrLValues
'===========================================
'构造函数_初始化FSO组件
'===========================================
Private Sub Class_Initialize()
Set FSO=Server.CreateObject("Scripting.FileSystemObject")
End Sub
'===========================================
'构析函数_销毁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
'获取标签
Public Property Let Label(ByVal Values)
StrLabel=Values
End Property
'获取将标签替换的值
Public Property Let LValues(ByVal Values)
StrLValues=Values
End Property
'===========================================
'类方法
'===========================================
'检查模板设置以及是否存在
Private Function Check()
If StrTemp="" Then
Check="<span style='color:red;'>错误:未设置模板文件存储位置!</span>"
Else
If FSO.FileExists(StrTemp)=false Then
Check="<span style='color:red;'>错误:指定模板不存在!</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
'替换内容
Public Function Rep()
If StrLabel="" Then
Response.Write "<span style='color:red;'>错误:未设置欲替换的标签!</span>"
Response.End()
End If
If StrLValues="" Then
Response.Write "<span style='color:red;'>错误:未设置替换标签的数据!</span>"
Response.End()
End If
FileData=Replace(FileData,StrLabel,StrLValues)
End Function
'输出
Public Sub Echo()
Response.Write FileData
End Sub
'生成静态页面
Public Sub GetHtml()
If StrHtmlName="" Then
Response.Write "<span style='color:red;'>错误:未设置生成Html文件存储位置以及文件名称!</span>"
Response.End()
End If
Set htmlwrite=FSO.CreateTextFile(Server.MapPath(StrHtmlName),true)
'写入网页内容
htmlwrite.WriteLine FileData
htmlwrite.Close
set htmlwrite=Nothing
End Sub
End Class
%>

用法示例:
index.asp
复制代码 代码如下:

<!--#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:
复制代码 代码如下:

<!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>无标题文档</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>