ASP通用模板類

來源:互聯網
上載者:User

   ASP 通用模板類。

  適合存在較少迴圈的模板。未實現內部迴圈,需要使用Regex,較浪費資源和時間,如需使用可參考這篇文章.

  特性

  可設定私人緩衝或公用緩衝,提高效率

  可自由選擇使用 Stream 組件或 FSO 組件

  支援自訂檔案編碼

  可儲存檔案

  屬性

  Name

  文本,該模板名稱,主要用於使用公用緩衝時區分不同模板。

  Format

  文本,檔案編碼類別型,可設定值。

  Object

  文本,使用組件,可設定值:

  Stream

  FSO

  PublicCache

  布爾值,使用公用緩衝,開啟時模板檔案將儲存到Application對象,其他引用此模板類的對象設定相同Name值並同樣開啟公用緩衝即可從緩衝讀取。(Load方法)

  PrivateCache

  布爾值,使用私人緩衝,開啟時模板檔案將儲存到對象內部變數,同一引用此模板類的對象可讀取。(Load方法)

  Direction

  文本,模板檔案所在目錄,前後無需斜杠或反斜線,如:template/default

  File

  文本,模板檔案名稱,前邊無需斜杠或反斜線,如:default.html

  SaveDirection

  文本,儲存檔案所在目錄,前後無需斜杠或反斜線,如:html/default

  SaveFile

  文本,儲存檔案名稱,前邊無需斜杠或反斜線,如:default.html

  對象

  Code

  文本,當前文本,使用SetVar方法時對此對象進行替換,使用Load方法時將模板重載到此對象

  Storage

  文本,已儲存文本,使用SaveFront或SaveLast方法時將Code對象中文本儲存到此對象的開頭或結尾,可用於迴圈後得到所有代碼

  方法

  ClearCache

  清除公用緩衝和私人緩衝(強制從檔案重載模板)

  ClearPublicCache

  清除公用緩衝

  ClearPrivateCache

  清除私人緩衝

  ClearCode

  清除Code對象

  ClearStorage

  清除Storage對象

  SaveFront

  將當前Code對象中文本儲存到Storage對象開頭

  SaveLast

  將當前Code對象中文本儲存到Storage對象結尾

  SaveCode

  將當前Code對象中文本儲存到檔案

  SaveStorage

  將當前Storage對象中文本儲存到檔案

  SetVar

  對當前Code對象中文本進行替換

  參數:需要被替換的文本,欲替換後的文本

  Load

  將模板檔案載入Code對象,當開啟並存在私人緩衝時,從私人緩衝載入,當開啟並存在公用緩衝時,從公用緩衝載入,若無緩衝則從檔案載入

  內部變數

  ccStrPath

  預設根目錄

  ccStrCookieName

  預設Application對象名首碼

  代碼

  Class ccClsTemplate

  Private ccStrCode,ccStrStorage

  Private ccStrCacheCode

  Private ccBlnPublicCache,ccBlnPrivateCache

  Private ccStrName,ccStrCookieName

  Private ccStrDirection,ccStrSaveDirection,ccStrFile,ccStrSaveFile,ccStrPath

  Private ccObjStream,ccObjFSO,ccStrFormat,ccIntObject,ccObjText,ccIntFormat

  Private Sub Class_Initialize

  ccStrName = "default" '預設名稱

  ccBlnPublicCache = False

  ccBlnPrivateCache = False

  ccStrFile = "cache.html"

  ccStrSaveFile = "save_cache.html"

  ccStrCookieName = "ccClass_Template" 'Application對象名首碼

  ccStrFormat = "UTF-8" 'UTF-8|ASCII|GB2312|BIG5

  ccIntFormat = -1

  ccIntObject = 1 '預設讀取/儲存模板組件 1:ADODB.Stream 2:FSO

  ccStrPath = Server.MapPath("./")&"" '預設根路徑

  End Sub

  Public Property Let Name(ccStrName_in)

  ccStrName = LCase(Trim(ccStrName_in))

  End Property

  Public Property Let Format(ccStrFormat_in)

  ccStrFormat = ccStrFormat_in

  If InStr(LCase(Trim(ccStrFormat_in)),"utf") > 0 Then

  ccIntFormat = -1

  Else

  ccIntFormat = 0

  End If

  End Property

  Public Property Let Object(ccStrObject_in)

  ccStrObject_in = LCase(Trim(ccStrObject_in))

  If InStr(ccStrObject_in,"fso") > 0 Then

  ccIntObject = 2

  Else

  ccIntObject = 1

  End If

  End Property

  Public Property Let PublicCache(ccBlnPublicCache_in)

  If ccBlnPublicCache_in = True Then

  ccBlnPublicCache = True

  Else

  ccBlnPublicCache = False

  End If

  End Property

  Public Property Let PrivateCache(ccBlnPrivateCache_in)

  If ccBlnPrivateCache_in = True Then

  ccBlnPrivateCache = True

  Else

  ccBlnPrivateCache = False

  End If

  End Property

  Public Property Let Direction(ccStrDirection_in)

  ccStrDirection = ccStrDirection_in

  End Property

  Public Property Let File(ccStrFile_in)

  If ccStrFile_in <> "" Then

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.