asp生成html页面的模板类

来源:互联网 发布:unity3d物体沿轴运动 编辑:程序博客网 时间:2024/05/22 17:15
一直就想把页面静态化的功能实现
正好现在的项目用得到,写了一个简单的类
过几天再细化一下
 
<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>
<%
'-------------------------------------------------------
'
模板类
'
blindcat
'
2006/07/12
'
-------------------------------------------------------

Class cls_Template
    
Private fso
    
Private html_in
    
Private html_out
    
Private htmlcode
    

    
'类初始化
    Private Sub Class_Initialize()
        
Set fso=Server.CreateObject("Scripting.FileSystemObject"
    
End Sub

    
    
'载入模板文件
    Public Sub loadTemplate(template)
        
On Error Resume Next
        
Set html_in=fso.OpenTextFile(Server.MapPath(template))  
        htmlcode 
= html_in.ReadAll
        html_in.close
        
Set html_in = Nothing  
    
End Sub

    
'替换模板内容
    Public Sub replaceTag(sourceTag,targetTag)
        htmlcode 
= Replace(htmlcode,sourceTag,targetTag)
    
End Sub
    
        
    
'生成html文件
    Public function makeHtml(htmlPath,filename)
        makeHtml 
= false
        
'On Error Resume Next
        Set fso = Server.CreateObject("Scripting.FileSystemObject")
        
if htmlpath<>"" then
            
if Not fso.FolderExists(Server.MapPath(htmlpath))then
                fso.CreateFolder Server.MapPath(htmlPath)
            
end if
            
if Not fso.FolderExists(Server.MapPath(htmlpath&"img/")) then
                fso.CopyFolder Server.MapPath(
"/template"),Server.MapPath(htmlpath),True
                
'fso.CopyFile Server.MapPath("cls_template.asp"),Server.MapPath("tttt.asp"),True
            end if
        
end if    
        
Set html_out = fso.CreateTextFile(Server.MapPath(htmlPath&filename))
        html_out.Write htmlcode
        html_out.close
        
Set html_out = Nothing
        makeHtml 
= true
    
End Function


    
Private Sub class_terminate()
        
set fso=Nothing 
    
End Sub 

end Class
%
>
<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>
原创粉丝点击