关于通过vbs类处理模板实现代码与界面分离的程序,建议入精华备查。有演示

程序|精华|模板

文章标题:vbs类处理模板实现代码与界面分离
'作者:yanek
'email:aspboy@263.net

本程序通过vbs类处理模板实现代码与界面分离的程序,主要有下面文件组成
index.asp,parse_cls.asp,template.html
下面是代码

1。index.asp 调用vbs类处理模板

<%
'作者:yanek
'email:aspboy@263.net

'---  ---
' index.asp
'------  ----
' (c)2000 James Q. Stansfield (james.stansfield@iridani.com)
' This code is free for use by anyone. It is meant as a learning tool and can be passed along in any format.
option explicit
%>
<!--#INCLUDE FILE="parse_cls.asp"-->
<%
'Declare our variables
dim g_oPageGen
'Cerate the class object
set g_oPageGen = New parseTMPL
'Set the template file
g_oPageGen.TemplateFile = "template.html"
'Add some custom tags to the dictionary
g_oPageGen.AddToken "title", "Template Example"
g_oPageGen.AddToken "copyright", "This is mine! All mine!"
g_oPageGen.AddToken "quote", """Tell Jabba I've got his money!""<br>--Han Solo, Star Wars 1977"
g_oPageGen.AddToken "menu", "Home Page<br>News Page<br>Link Page"
g_oPageGen.AddToken "content", "Welcome To My Home Page... Yadda Yadda Yadda!"
'Generate the page
g_oPageGen.GenerateHTML
'Destroy our objects
set g_oPageGen = nothing
%>

2。parse_cls.asp  处理模板类文件

<%
'作者:yanek
'email:aspboy@263.net

'---  ---
' parse_cls.asp
' This code is free for use by anyone. It is meant as a learning tool and can be passed along in any format.
class parseTMPL
    'Dimension variables
    private g_sTMPLFILE
    private g_oDict
    private g_bFILE

    private sub class_Initialize
        'Create the Scripting.Dictionary Object,
        'Set the compare mode to 1 so that it is case insensitive.
        'Also flag a boolean file so we know whether our file is there or not.
        set g_oDict = createobject("Scripting.Dictionary")
        g_oDict.CompareMode = 1
        g_bFILE = FALSE
    end sub
    
    private sub class_Terminate
        'Destroy our object.
        set g_oDict = nothing
    end sub
    
    public property let TemplateFile(inFile)
        'A file & path must be specified for the routine to work.
        g_sTMPLFILE = server.mappath(inFile)
    end property
    
    private property get TemplateFile()
        TemplateFile = g_sTMPLFILE
    end property
    
    public sub AddToken(inToken, inValue)
        'This property allows us to set our tokens.
        g_oDict.Add inToken, inValue
    end sub
    
    public sub GenerateHTML
        'This is the main, and only public method of the class.
        'This method will check whether we've specified a file or not.
        'Check for the files existance if we have specified it.
        'If the file exists we will open it and dumps it's contents into an array.
        'The array is split on VbCrLf to make it more manageable.
        if len(g_sTMPLFILE) > 0 then
            dim l_oFSO, l_oFile, l_arrFile
            set l_oFSO = createobject("Scriptin

时间: 2024-09-16 13:11:00

关于通过vbs类处理模板实现代码与界面分离的程序,建议入精华备查。有演示的相关文章

在asp中通过vbs类实现rsa加密与解密,建议入精华

加密|解密|精华 在asp中通过vbs类实现rsa加密与解密,建议入精华 本文章有两文件组成 test.asp 测试演示文件 clsrsa.asp 实现rsa加密与解密的vbs类文件下面是代码: 1. test.asp <%rem 文章标题:在asp中通过vbs类实现rsa加密与解密rem 收集整理:yanekrem 联系:aspboy@263.net %><%Option Explicit%><!--#INCLUDE FILE="clsRSA.asp"-

利用vbs类实现css按钮,建议入精华

<%rem 文章标题: 利用vbs类实现css按钮rem 作者:yanekrem 联系:aspboy@263.netClass CssButton    Public Name    Public BackColor    Public BorderColor    Public Font    Public FontColor    Public Width    Public Text    Public Url    Public MouseOverColor        Public

在asp中通过vbs类实现rsa加密与解密的代码_应用技巧

在asp中通过vbs类实现rsa加密与解密,建议入精华 本文章有两文件组成 test.asp 测试演示文件 clsrsa.asp 实现rsa加密与解密的vbs类文件 下面是代码: 1. test.asp  复制代码 代码如下: <%  rem 文章标题:在asp中通过vbs类实现rsa加密与解密  rem 收集整理:yanek  rem 联系:aspboy@263.net  %>  <%Option Explicit%>  <!--#INCLUDE FILE="cl

在asp中通过vbs类实现rsa加密与解密

加密|解密 本文章有两文件组成test.asp 测试演示文件clsrsa.asp 实现rsa加密与解密的vbs类文件下面是代码: 1. test.asp <%rem 文章标题:在asp中通过vbs类实现rsa加密与解密rem 收集整理:yanekrem 联系:aspboy@263.net %><%Option Explicit%><!--#INCLUDE FILE="clsRSA.asp"--><% Dim LngKeyEDim LngKeyD

QTP中使用自定义vbs类

发现直接在resource中加载含有calss的vbs文件,QTP无法识别类,导致脚本中无法new类对象. 解决办法有四种: 1.直接在action脚本中定义类,然后action中任何地方都可以实例化类 2.用executefile引入类定义文件,然后action中任何地方都可以实例化类 3.在function lib中定义类,并实例化类,然后再action中直接使用类实例 4.在function lib中定义类,并定义一个实例化类的函数,然后再action中调用该函数对类进行实例化 补充:第四

利用vbs类实现css按钮的代码_vbs

复制代码 代码如下: <%  rem 文章标题: 利用vbs类实现css按钮  rem 作者:yanek  rem 联系:aspboy@263.net  Class CssButton    Public Name    Public BackColor    Public BorderColor    Public Font    Public FontColor    Public Width    Public Text    Public Url    Public MouseOverC

用模板实现代码和页面的分离

模板|页面 为了避免ASP程序和HTML代码混写造成维护困难的情况,本文介绍了一种方法,利用模板来分离程序和页面,使程序设计更加轻松. 在使用ASP制作一个站点的时候,常常会出现一个ASP文件中,程序代码和HTML代码混合的情况.这样子做有许多缺点: 1. 且不说编程时就要对页面布局进行设计和编排,造成代码混乱难懂,不规范: 2. 当需要改变页面外观时,你不仅要改变HTML部份,也需要改变ASP代码,不易维护. 那么,要如何才能避免这些麻烦呢? 答案就是使用模板文件,将ASP代码和HTML页面分

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

模板|页面 使用模板实现ASP代码与页面分离 每个进行过较大型的ASP-Web应用程序设计的开发人员大概都有如下的经历:ASP代码与页面HTML混淆难分,业务逻辑与显示方式绞合,使得代码难以理解.难以修改:程序编写必须在美工之后,成为项目瓶颈:整合的程序代码和HTML静态页面时,花费大量的时间才能得到理想的效果,兼作了美工.的确,用脚本语言开发Web应用不容易将数据的处理和数据的显示分开,但在多人合作的情况下,如果无法将数据和显示分开,将大大影响开发的效率,专业分工的发挥. 其它的脚本语言,如J

C++:派生类访问模板化基类(templatized base class)的命名

派生类继承模板化基类的成员函数, 默认是无法访问, 模板化基类的命名. 原因是模板的定制化有可能取消某些函数, 为了能在编译期检测出错误, 所以默认无法访问. 派生类访问模板化基类, 包含三种方法: 1. 调用基类函数时, 使用"this->", 指明调用的类, 是本类, 在编译时, 可以进行检查; 2. 使用using声明式, 可以把基类的函数引入派生类, 在编译时, 可以进行检查; 3. 使用显示修饰(explicit qualification), 不推荐, 显示修饰会屏蔽