分享
 
 
 

aspTemplate : 类似 phpLib::Template 的分离层实现

王朝php·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

MVC 模式在网站架构中十分常见。它允许我们建立一个三层结构的应用程式,从代码中分离出有用的层,帮助设计师和开发者协同工作以及提高我们维护和扩展既有程式的能力。

PHP 中有一个很著名的类库 phpLib,其中有 Template 模板类。能够很方便地实现代码分离在 ASP 中是否也可以这样做呢?当然可以,这就是 aspTemplate 的初衷。它完全实现了 phpLib Template 的全部功能,你可以象使用 phpLib Template 一样使用它,连习惯也基本不用改。:)

<%

'#######################################################################

'## NAME: aspTemplate

'## BY: BigHan

'## DATE: Nov. 28, 2003

'## SITE: http://aspTemplate.yeah.net/

'## EMAIL: aspTemplate@21cn.com

'##

'## (C) Copyright 2003-2004 bighan

'#######################################################################

Class aspTemplate

'####

'## name of this class

'## var string

'## @access Private

'## @see property: Name

'####

Private m_strName

'####

'## version of this class

'## var string

'## @access Private

'## @see property: Version

'####

Private m_strVersion

'####

'## Determines how much debugging output Template will produce.

'## This is a bitwise mask of available debug levels:

'## 0 = no debugging

'## 1 = debug variable assignments

'## 2 = debug calls to get variable

'## 4 = debug internals (outputs all function calls with parameters).

'##

'## @var int

'## @access Private

'## @see property: Debug

'####

Private m_intDebug

'####

'## The base directory from which template files are loaded.

'##

'## @var string

'## @access private

'## @see property: Root, Dir; method: SetRoot, set_root

'####

Private m_strRoot

'####

'## Determines how to output variable tags with no assigned value in templates.

'##

'## @var string

'## @access private

'## @see property Unknown; method: SetUnknowns, set_unknowns

'####

Private m_strUnknowns

'####

'## Determines how Template handles error conditions.

'## "yes" = the error is reported, then execution is halted

'## "report" = the error is reported, then execution continues by returning "false"

'## "no" = errors are silently ignored, and execution resumes reporting "false"

'##

'## @var string

'## @access private

'## @see property IsHalt; method: halt

'####

Private m_strHaltError

'####

'## The last error message is retained in this variable.

'##

'## @var string

'## @access private

'## @see property LastError

'##

Private m_strLastError

'####

'## Opening delimiter (usually "{")

'##

'## @var string

'## @access private

'## @see property BeginTag

'####

Private m_strBeginTag

'####

'## Closing delimiter (usually "}")

'##

'## @var string

'## @access private

'## @see private EndTag

'####

Private m_strEndTag

'####

'## A hash of strings forming a translation table which translates variable names

'## into names of files containing the variable content.

'## m_oFile.Item(varname) = "filename";

'##

'## @var object

'## @access private

'## @see method: SetFile, SetFiles, set_file

'####

Private m_oFile

'####

'## Regular Expression Object

'##

'## @var object

'## @access private

'####

Private m_oRegExp

'####

'## A hash of strings forming a translation table which translates variable names

'## into regular expressions for themselves.

'## m_oVarKeys.Item(varname) = "{varname}"

'##

'## @var object

'## @access private

'## @see method: SetVar, SetVars, SetAppendVar, SetAppendVars, set_var

'####

Private m_oVarKeys

'####

'## A hash of strings forming a translation table which translates variable names

'## into values for their respective varkeys.

'## m_oVarVals.Item(varname) = "value"

'##

'## @var object

'## @access private

'## @see method: SetVar, SetVars, SetAppendVar, SetAppendVars, set_var

'####

Private m_oVarVals

'####

'## get class name attribute.

'##

'## usage: oTemplate.Name

'## access public

'##

Public Property Get Name()

'############################################################

Name = m_strName

End Property

'####

'## get class version attribute.

'##

'## usage: oTemplate.Version

'## access public

'##

Public Property Get Version()

'############################################################

Version = m_strVersion

End Property

'####

'## get/set m_intDebug attribute.

'##

'## usage: oTemplate.Debug = A_intDebug

'## access public

'##

Public Property Let Debug(ByVal A_intDebug)

'############################################################

m_intDebug = CInt(A_intDebug)

End Property

Public Property Get Debug()

Debug = m_intDebug

End Property

'####

'## Sets the policy for dealing with unresolved variable names.

'##

'## unknowns defines what to do with undefined template variables

'## "remove" = remove undefined variables

'## "comment" = replace undefined variables with comments

'## "keep" = keep undefined variables

'##

'## Note: "comment" can cause unexpected results when the variable tag is embedded

'## inside an HTML tag, for example a tag which is expected to be replaced with a URL.

'##

'## usage: oTemplate.Unknown = A_unknowns

'##

'## @param A_unknowns new value for unknowns

'## @see unknowns, SetUnknowns, set_unknowns

'## @access public

'##

Public Property Let Unknown(ByVal A_unknowns)

'############################################################

If Debug = 4 Then Response.Write "<p><b>Unknown:</b> unknown = " & A_unknowns & "</p>" & VbCrLf

A_unknowns = LCase(A_unknowns)

Select Case A_unknowns

Case "keep"

m_strUnknowns = "keep"

Case "remove"

m_strUnknowns = "remove"

Case "comment"

m_strUnknowns = "comment"

Case Else

m_strUnknowns = "remove"

End Select

End Property

Public Property Get Unknown()

Unknown = m_strUnknowns

End Property

'####

'## Checks that root is a valid directory and if so sets this directory as the

'## base directory from which templates are loaded by storing the value in

'## Root. Relative filenames are prepended with the path in Root.

'##

'## usage: oTemplate.Root = A_root

'##

'## @param A_root string containing new template directory

'## @see m_strRoot, SetRoot, set_root

'## @access public

'##

Public Property Let Root(ByVal A_root)

'############################################################

If Debug = 4 Then Response.Write "<p><b>Root:</b> root = " & A_root & "</p>" & VbCrLf

Dim MM_FSO

If Len(A_root) > 0 Then

Set MM_FSO = CreateObject("Scripting.FileSystemObject")

If MM_FSO.FolderExists(Server.MapPath(A_root)) Then

If Right(A_root, 1) <> "/" Then

[1] [2] [3] [4] [5] [6] [7] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有