123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home

Source Codes

Engineering Colleges

BE Students

Training  Reports (updated)

Seminar Reports (updated

Placement Papers (updated)

Forums

   Computer Science / IT

   Electronics

   Electrical

   Mechanical

   Chemical

   Civil

   CAT / MBA

   GMAT / Foreign MBA

Latest Jobs

Engineering Jobs / Technical Jobs

Management Jobs

Sitemap

About-Us

Terms of use

Displaying  Source Code(s)  
 

 
EasyASP Template Engine.

--------------------------------------------------------------------------------

Description : The ultimate class if you want to seperate your ASP code from your HTML/XML/other data.

Seperation of code will result in extremely neat and well-readable code. Once you get to know ASPTemplate you can't do without anymore! I garantuee, just take some time to learn
and understand the way this template class works, and you will discover that you are able to
use it for EVERY ASP programming challenge you face.

<%
Response.Buffer=false
Server.ScriptTimeOut=5

'-------------------------------------------------------------------------
' ASPTemplate Class
' Written by Tjoekbezoer, copyright (c) 2003
' Quickmanual written at 21-03-2003, extensive manual at
http://www.tjoekbezoer.tk
' This class can be freely used, in non-commercial as well as in
commercial sites. As long as this copyright
' information remains intact. Logfile and quickmanual can be erased
ofcourse.
'
' Separate your ASP code from your HTML code. This way you will easily
keep track of your sourcecode.
' Very useful if several people are working on the same scripts, and all
have different skills.
' This is a rather advanced class. You have many possibilities, and its
always possible to Add more functio-
' nality to it (and of course delete to speed things up). Below is a very
short survey of how to write a
' template, and how to use the funtions of this class.
' To get to know how the main functions work, visit
http://www.tjoekbezoer.tk
'
'
' IMPORTANT: the #s used here are to indicate what is a value!!!! so when
you create a variable, for example Header,
' you must type {Header} in your template, and not {#Header#}!!!
'
' ---[ WRITING A TEMPLATE ]---
' {#NAME#}
' Plain variable. #NAME# will be replaced by its value if the block is
parsed. If no value is assigned
' {#NAME#} will be replaced by "" (nothing).
' {{#NAME#}}
' Dynamic variable assignment. lets say the value of #NAME#="test". Upon
parsing the block {#NAME#}
' will be replaced by "test", so you get {test}. Since parsing variables
is recursive, the engine will recognize
' the variable {test}, and will look for a value. If you assigned a value
for "test" somewhere, {test} will then
' be replaced by its value. Since its recursive {{{#NAME}}},
{{{{#NAME}}}} etc is also possible.
' {#NAME#} to escape. It will print {#NAME#} in the clients browser then,
and not the value
' of {#NAME}. Recursive is also possible. {{#NAME}}, where the value of
#NAME#
' is "test" again, will be parsed like "{test}" in the browser.
' Following characters can be used in variablename: [a-zA-Z0-9._]
' If you use other characters, the variable will not be parsed, whether
you have assigned it or not
' {FILE: #NAME#}
' The FILE: command is use to include another template right at that
place. So the contents of template file
' #NAME# will be inserted at the very spot where you typed this command.
' Following characters can be used in TemplateName: [a-zA-Z0-9/ _.-]
(includes space)
' {FILE: {#NAME#}}
' Include templates dynamically!
' But be cautious! when you use a variable here you must assign a value
to this variable BEFORE YOU LOAD
' THE MAIN TEMPLATE! Otherwise errors will occur.
' [% BEGIN: BlockName %]
' Begin a new (sub)block
' [% END: BlockName %]
' End a (sub)block
' Blocks can be nested in eachother. See the example for more explanation
about blocks.
'
' ---[ USING THE CLASS ]---
' Load(Template)
' Load the contents of the template you want to use. Server.MapPath is
included in the function, you
' dont need to use it yourself when defining location of the template.
The real Function For getting the
' template is private function GetFile(). If you want do delete the
standard Server.MapPath, do it in
' te GetFile() function.
' Assign(Variable, Value)
' Assign Value to Variable.
' Example: Assign "test", "hello"
' This wil give {test} value "hello".
' Unassigned variables in the template will not be displayed (so no
stupid {variablename} in browser
' when you forgot to assign a variable, or did not assign it on purpose)
' ListVars()
' Returns a two-dimensional array with all the variables assigned at that
moment.
' Find(Input)
' Searches for Input in the unparsed template, and returns an array with
the block(s) it is found in.
' Parse(BlockName)
' Parses BlockName (meaning assigning values of the variables to that
block, and add it to the
' temporary ParsedBlocks dictionary, ready to be written out)
' Out(BlockName)
' Writes the parsed contents of BlockName to the client's browser.
' Give(BlockName)
' Returns the parsed content of BlockName.
' Exec(BlockName)
' If the block only contains ASP after parsing, you can execute is as
though it was a piece of ASP code.
' Be careful though, this can be dangerous for your scripts.
' If used right it can be pretty handy. Even though the block can only
contain ASP, you can still use variables
' in it, define other blocks in it, and include other templates in it. As
long as the parsed Block only contains ASP
' NOTICE: Be sure that there are no '< %' and '% >' in the block(s) that
will be executed!!
'
'
' You can add and delete as many public functions as you want, but be sure
to leave the private functions
' alone. Much of them are used several times in different public
functions. Deleting one might cause the
' entire class to crash :) Additional public functions will soon be
available at http://www.tjoekbezoer.tk
' You can also request special additions.
'
' This was just a very short manual. For extra help visit
http://www.tjoekbezoer.tk
' Here you can find the latest updates/additions to this class, and you
are able to request features.
' And of course more classes, functions and applications are available as
free downloads.
' If you want me to make more classes/functions/apps, please stimulate me
by sending me your
' comments, ideas and requests to tjoekbezoer2000v@hotmail.com Thanks a
lot!
'
'
' LOG
' 3 nov 2003
' In PARSEVARS added a new functionality so that the syntax of variables
is a little extended:
' Syntax: {variable[=value][;status]}
' variable = variable name
' value = standard value of this variable
' status = for now only hidden is possible. if ;status is set to hidden,
the variable will not be shown in the
' final result. The value will be assigned, but its value will not be.
'
' Fixed a check in ASSIGN: it checks if the value assigned is not empty,
but "" was also empty for him
' Fixed that by checking with IsEmpty()
' 4 nov 2003
' in PARSEVARS, in the [=value] param value can now also be empty.
'
' also in PARSEVARS, coded in an option that allows supervar values to be
overwritten by ASSIGN
'
' fixed ASSIGN: the IsObject check to assign dictionary items to
variables prevented the usage of other
' objects to assign values to variables.
'
' Added a Get property that can get the value of a variable. returns
False if empty
' 6 nov 2003
' Changed PARSEVARS again: the regexp now doesnt allow variable names to
start and end with spaces
' s to start and end with is now disallowed.
'
' 1 dec 2003
' Added a new check in CONSTRUCTTEMPLATE:
' a new property IGNOREINCLUDES will get, and let u define if ASPTemplate
should ignore template
' includes in the main template. This way you can analyze blocks without
parsing or including
' 4 dec 2003
' Finally fixed the regexp problem for analyzing a template's blocks!! :D
So no filthy replaces anymore,
' just clean regexp code. Also centralized all regexps in
CLASS_INITIALIZE so that they can be easily
' editted.
' 21 dec 2003
' Made some changes in the regular expression for the block- and varname.
Now its possible to
' use all the characters for a block/var name, except characters that
cause a line break or a tab.
' 23 dec 2003
' Again changes in the regexp for vars this time. vars with "module_"
prefixed are not recognized as
' vars anymore, this is especially for CIMS.
' Also, the B and were not needed in var regexp (to "unvar" vars that
were prefixed ur suffixed with
' spaces), so i removed them.
' 25 dec 2003
' Added an extra function to PARSEVARS: especially for CIMS it now also
parses {module_###} vars
' with their module content. Those vars are normally omitted when parsing
vars (see regexp).
'-------------------------------------------------------------------------


Class ASPTemplate
Dim DefaultTemplate, BlockStart, BlockEnd, BlockClose, Reg, BlocksRAW,
BlocksParsed, Vars, i
Dim regSearchBlockMarkers
Dim regSearchEscapedVars
Dim regSearchModules
Dim regSearchStaticIncludes
Dim regSearchVariableIncludes
Dim regSearchVariables
Dim regAnalyzeBlocks

'-------------------------------------------------------------------------
' Contructor

'-------------------------------------------------------------------------
Private Sub Class_Initialize
// This RegExp class is used in entire class. Patterns defined below
Set Reg=new RegExp
With Reg
.MultiLine=True
.Global=True
.IgnoreCase=True
End With

// Create the Vars Dictionary
Set Vars = Server.CreateObject("Scripting.Dictionary")
Set BlocksRAW = Server.CreateObject("Scripting.Dictionary")
Set BlocksParsed = Server.CreateObject("Scripting.Dictionary")

// Set the regular expressions
regAnalyzeBlocks =<BR>(BEGIN:|END:)s*([^f

v]+?)s*%]([sS]*?)[%"
regSearchBlockMarkers = "([% _BLOCK_([^f

v]+?) %])"
regSearchEscapedVars =<BR>({\([^ ][^f

v{}]+?[^ ])(=([^{}f

v;]*))?(;?(hidden)
?)})"
regSearchModules = "({((module_)([^f

v{}]+))})"
regSearchStaticIncludes = "({s*FILE:s*([a-zA-Z0-9 /_.-]+)s*})"
regSearchVariableIncludes =<BR>(({s*FILE:s*){([^f

v{}]+?)}(s*}))"
regSearchVariables =<BR>({(?!module_|\| )([^f

v{}]+?[^ ])(=([^{}f

v;]*))?;
?(hidden)?})"
End Sub


'-------------------------------------------------------------------------
' Destructor

'-------------------------------------------------------------------------
Private Sub Class_Terminate
EmptyDictionaries()

Set Vars=Nothing
Set BlocksRAW=Nothing
Set BlocksParsed=Nothing
End Sub

'------[ PUBLIC
FUNCTIONS ]---------------------------------------------------------------


'-------------------------------------------------------------------------
' To start working with a template, you have 3 ways to load the template,
with LOAD, ANALYZEBLOCKS
' and with ANALYZEVARS. Load is the simplest and fastest way. But if you
need an array of blocks or
' vars after loading the template you can use one of the other two. Using
two or more load functions
' makes no sense, and might result in an error or unexplainable behaviour
of the class.

'-------------------------------------------------------------------------


'-------------------------------------------------------------------------
' LOAD
'
' Load template and process blocks if template is found

'-------------------------------------------------------------------------
Public Function Load(Template)
EmptyDictionaries()
// Make the tree after all includes are put together in one template
MakeTree(ConstructTemplate(Template))
// Assign the server variables to the according template variables
//AssignServerVariables()
End Function



'-------------------------------------------------------------------------
' ANALYZEBLOCKS
'
' Load template and analyze its blocks. They will be stored in an array

'-------------------------------------------------------------------------
Public Function AnalyzeBlocks(Template)
EmptyDictionaries()
// Get the contents of the template... which also takes care of the file
includes
MakeTree(ConstructTemplate(Template))
ReDim Blocks(0)

For Each Block in BlocksRAW
Blocks(UBound(Blocks)) = Block // We want the name of the block
ReDim Preserve Blocks(Ubound(Blocks)+1)
Next

Redim Preserve Blocks(UBound(Blocks)-1)

AnalyzeBlocks=Blocks
End Function



'-------------------------------------------------------------------------
' ANALYZEVARS
'
' Load template and analyze its vars. The difference with LISTVARS is
that this function gives only
' names, and from all vars in this tpl. LISTVARS only gives the vars
already assigned, and their values
' Output is an array of all variables occuring in this template, which is
enough for now.
' Function does NOT list

'-------------------------------------------------------------------------
Public Function AnalyzeVars(Template)
EmptyDictionaries()
// Get the contents of the template... which also takes care of the file
includes
// MAKETREE takes care of interpreting the tpl so that it can be used
for parsing etc
// It's done after TemplateContent var assigning cos MakeTree doesnt
give the desired output for this function
TemplateContent = ConstructTemplate(Template)
MakeTree(TemplateContent)

Redim Vars(0)

Reg.Pattern = regSearchVariables
Set Matches = Reg.Execute(TemplateContent)
For Each Match in Matches
Vars(UBound(Vars)) = Match.SubMatches(1)
Redim Preserve Vars(Ubound(Vars)+1)
Next

Redim Preserve Vars(UBound(Vars)-1)

AnalyzeVars = Vars
End Function


'-------------------------------------------------------------------------
' ANALYZEBLOCKVARS
'
' Return an array of all the vars in this Block
' You need to run LOAD, ANALYZEBLOCKS or ANALYZEVARS first to load and
interpret the template.
' The difference with ANALYZEBLOCKS is that this function returns an
array of vars of a specific block.

'-------------------------------------------------------------------------
Public Function AnalyzeBlockVars(BlockName)
BlockContent = BlocksRAW.Item(BlockName)

Dim Vars
Redim Vars(0)

Reg.Pattern = regSearchVariables
Set Matches = Reg.Execute(BlockContent)

For Each Match in Matches
Vars(UBound(Vars)) = Match.SubMatches(1)
Redim Preserve Vars(Ubound(Vars)+1)
Next

Redim Preserve Vars(UBound(Vars)-1)

AnalyzeBlockVars = Vars
End Function



'-------------------------------------------------------------------------
' ASSIGN
'
' Assign values to the variables in the template. For vars and single
dimension arrays

'-------------------------------------------------------------------------
Public Function Assign(strVariable, strValue)
// When object is a dictionary, assign all
// dictionary items to a variable, where variablename is itemname
If LCase(TypeName(strValue))="dictionary" Then
For Each Var in strValue
If NOT IsEmpty(Var) Then
Vars.Item(Var) = strValue.Item(Var)
End If
Next
Else
//If NOT IsEmpty(strValue) Then
Vars.Item(strVariable)=strValue
//Else
// Response.Write "<p>---ERROR: variable <b>[" & strVariable & "]</b>
was assigned a NULL value!---</p>"
// Response.End
//End If
End If
End Function


'-------------------------------------------------------------------------
' LISTVARS
'
' Returns an array with all the variables (and their values) currently
assigned
' Difference with ANALYZEVARS is that tha function returns ALL variables
in the template without values.
' This function only returns the variables which are assigned a value. It
also returns the value, so it returns
' a two-dimensional array.

'-------------------------------------------------------------------------
Public Function ListVars()
ReDim Result(2, 0)
If IsObject(Vars) Then
For Each Var in Vars
ResultSize=UBound(Result, 2)
ReDim Preserve Result(2, (ResultSize+1))
Result(1, ResultSize)=Var
Result(2, ResultSize)=Vars.Item(Var)
Next
ReDim Preserve Result(2, (UBound(Result, 2)-1)) // Last element is
empty, so erase it
ListVars=Result
End If
End Function


'-------------------------------------------------------------------------
' FIND
'
' Returns an array with the blockname(s) in which the input is found.
' Function searches in unparsed blocks, and can take long with big
templates!

'-------------------------------------------------------------------------
Public Function Find(Input)
ReDim Result(0)
If IsObject(BlocksRAW) Then
For Each Block in BlocksRAW
If InStr(BlocksRAW.Item(Block), Input)<>0 Then
// Variable found.
ResultSize=UBound(Result)
ReDim Preserve Result(ResultSize+1)
Result(ResultSize)=Block
End If
Next
ReDim Preserve Result(UBound(Result)-1) // Last element is empty
Find=Result
End If
End Function


'-------------------------------------------------------------------------
' ISASSIGNED
'
' Check if a variable is already assigned. If it is, return value. If its
not, Return false

'-------------------------------------------------------------------------
Public Function IsAssigned(Variable)
If IsObject(Vars) Then
If Vars.Exists(Variable) Then
IsAssigned=Vars.Item(Variable)
Else
IsAssigned=False
End If
Else
IsAssigned=False // Vars is no object, so variable is not assigned
anyway
End If
End Function


'-------------------------------------------------------------------------
' PARSE
'
' Parse a block
' Replaces the variables with their values. Variables that have not been
assigned a value are not displayed

'-------------------------------------------------------------------------
Public Function Parse(BlockName)
ParsedBlockContent=""
NewBlockContent=BlocksRAW.Item(BlockName)

// Call function to recursively parse variables
NewBlockContent=ParseVars(NewBlockContent)

// Replace the escaped variables so that they will be displayed as RAW
variablenames
Reg.Pattern=regSearchEscapedVars
NewBlockContent=Reg.Replace(NewBlockContent, "{$2$3$5}")

// The replace the _BLOCK_ instances with the matching parsed block(s)
from the BlocksParsed Dictionary
Reg.Pattern=regSearchBlockMarkers
Set Matches=Reg.Execute(NewBlockContent)
For Each Match in Matches
NewBlockContent=Replace(NewBlockContent, Match.SubMatches(0),
BlocksParsed.Item(Match.SubMatches(1)), 1, -1, 1)
BlocksParsed.Remove(Match.SubMatches(1))
Next

If BlocksParsed.Exists(BlockName) Then

BlocksParsed.Item(BlockName)=BlocksParsed.Item(BlockName)&NewBlockContent
Else
BlocksParsed.Add BlockName, NewBlockContent
End If
End Function


'-------------------------------------------------------------------------
' OUT
'
' Write out a block to the browser. When writing out a block it will
write out its parsed children blocks too.
' So lets say you have a block Main, and a block Main.Test
' You first assign a value to the variables in block Test, and then you
parse it. After that you assign a value
' to the vars in block Main, and you parse that one too. Then you OUT
block Main. Since Main.Test is a child
' of of block Main, it also gets printed out. If Main.Test would also
have a child Main.Test.Row, and you would
' have parsed it, it would also be printed out, because indirectly its
family of Main.
'
' So summarized you can say that, when you OUT a block, all the parsed
FAMILY of that block is printed out
' too!

'-------------------------------------------------------------------------
Public Function Out(BlockName)
If BlocksParsed.Exists(BlockName) Then
Response.Write BlocksParsed.Item(BlockName)
BlocksParsed.Remove(BlockName)
End If
End Function


'-------------------------------------------------------------------------
' GIVE
'
' Assign contents of a parsed block to a variable
' Instead of printing a block and its parsed family, you return it, so it
can be used for further editting

'-------------------------------------------------------------------------
Public Function Give(BlockName)
If BlocksParsed.Exists(BlockName) Then
Give=BlocksParsed.Item(BlockName)
BlocksParsed.Remove(BlockName)
End If
End Function


'-------------------------------------------------------------------------
' EXEC
'
' Execute a block (!)
' When you execute a block it can only contain ASP code, NOTHING else!
' Block can be dynamic tho (so you can use ASP-only blocks inside them,
include ASP-only templates in it
' and assign variables in it. Be sure no '< %' and '% >' instances are
located in executed blocks!

'-------------------------------------------------------------------------
Public Function Exec(strBlockName)
If IsObject(BlocksParsed) AND BlocksParsed.Exists(strBlockName) Then
strBlockContent = BlocksParsed.Item(strBlockName)

// Filter out the ASP tags
strBlockContent = Replace(strBlockContent, Chr(60)&Chr(37), "")
strBlockContent = Replace(strBlockContent, Chr(37)&Chr(62), "")
// Filter out comment tags cos they return errors
Reg.Pattern = "^[ ]*(//|')[sS]*?$"
strBlockContent = Reg.Replace(strBlockContent, "")

//arrBlockContent = Split(strBlockContent, Chr(10))

On Error Resume Next
//For i=0 TO UBound(arrBlockContent)
Execute strBlockContent

If Err.Number>0 Then
Response.Write "---FATAL ERROR: while trying to execute <b>" &
strBlockName & "</b>---<BR>
Response.Write "---Error description: " & Err.Description & "<BR>
Response.Write "---Error Source: " & Err.Source & "<hr>"
// Response.Write "---Error Line: " & i & "<hr>"
// Response.Write "<b>Script Source</b>
<font face=""courier"">"
// If i>1 Then Response.Write "<span style=""width:50px;"">" & i+1-2 &<BR></span>" & Replace(Server.HTMLEncode(arrBlockContent(i-2)), Chr(9),<BR> ") & "<BR>
// If i>0 Then Response.Write "<span style=""width:50px;"">" & i+1-1 &<BR></span>" & Replace(Server.HTMLEncode(arrBlockContent(i-1)), Chr(9),<BR> ") & "<BR>
// Response.Write "<div style=""background-color=#FFFFC0""><span
style=""width:50px;"">" & i+1 & "</span>" &
Replace(Server.HTMLEncode(arrBlockContent(i)), Chr(9),<BR> ") & "</div>"
// If UBound(arrBlockContent)>=i+1 Then Response.Write "<span
style=""width:50px;"">" & i+2 & "</span>" &
Replace(Server.HTMLEncode(arrBlockContent(i+1)), Chr(9),<BR> ") & "<BR>
// If UBound(arrBlockContent)>=i+2 Then Response.Write "<span
style=""width:50px;"">" & i+3 & "</span>" &
Replace(Server.HTMLEncode(arrBlockContent(i+2)), Chr(9),<BR> ") & "<BR>
// Response.Write "</font>"
Response.End
End If
// Next

BlocksParsed.Remove(strBlockName)
On Error GoTo 0
End If
End Function

'------[ PUBLIC
PROPERTIES ]--------------------------------------------------------------

'-------------------------------------------------------------------------
' GETVAR
'
' Get the value from a var

'-------------------------------------------------------------------------
Public Property Get GetVar(Name)
If Vars.Exists(Name) Then
GetVar = Vars.Item(Name)
Else
GetVar = False
End If
End Property


'-------------------------------------------------------------------------
' IGNOREINCLUDES
'
' Whether or not to ignore template includes in the main template.

'-------------------------------------------------------------------------
Dim blIgnoreInc
Public Property Let IgnoreIncludes(blStatus)
If blStatus<>True and blStatus<>False Then blStatus = False

blIgnoreInc = blStatus
End Property

Public Property Get IgnoreIncludes()
If blIgnoreInc="" Then blIgnoreInc = False

IgnoreIncludes = blIgnoreInc
End Property


'-------------------------------------------------------------------------
' IGNOREERRORS
'
' Whether or not to ignore errors

'-------------------------------------------------------------------------
Dim blIgnoreErrors
Public Property Let IgnoreErrors(blStatus)
If blStatus<>True and blStatus<>False Then blStatus = False

blIgnoreErrors = blStatus
End Property

Public Property Get IgnoreErrors()
If blIgnoreErrors="" Then blIgnoreErrors = False

IgnoreErrors = blIgnoreErrors
End Property


'-------------------------------------------------------------------------
' DEFAULTINCLUDEPATH
'
' To set the default include path, so it doesnt have to be typed every
time.

'-------------------------------------------------------------------------
Dim strDefaultIncPath
Public Property Let DefaultIncludePath(strPath)
strDefaultIncPath = strPath
End Property

Public Property Get DefaultIncludePath()
If strDefaultIncPath<>"" Then
DefaultIncludePath = strDefaultIncPath
Else
DefaultIncludePath = False
End If
End Property



'------[ PRIVATE
FUNCTIONS ]---------------------------------------------------------------

'-------------------------------------------------------------------------
' MAKETREE
'
' Analyze template blocks and make them ready for processing. This
function is for internal use, and should
' not be changed unless you know what you are doing.

'-------------------------------------------------------------------------

Private Function MakeTree(Template)
// Input parameter Template comes from TemplateContent in LoadTpl()
Dim Matches, Match, level
Dim BlockName, Position, Content, TempContent

// Set up regular expression for analyzing template
Reg.Pattern = regAnalyzeBlocks

Set Matches=Reg.Execute(Template)
level=0
CurrentBlockName=""
ParentBlockName=""

For Each Match in Matches
BlockName=Match.SubMatches(1)
Position=Match.SubMatches(0) // BEGIN: or END:
Content=Match.SubMatches(2)

If InStr(Position, "BEGIN:")>0 Then
If CurrentBlockName="" Then CurrentBlockName=BlockName Else
CurrentBlockName=CurrentBlockName&"."&BlockName
// Content replace to catch up a fucked up regexp in GETFILE
BlocksRAW.Item(CurrentBlockName)=Content
level=level+1
Else
level=level-1
// To prevent error when trying to add code after main block has ended
If level>0 Then
ParentBlockName=Left(CurrentBlockName, InStrRev(CurrentBlockName,<BR>.")-1)
TempContent=BlocksRAW.Item(ParentBlockName)

BlocksRAW.Remove(ParentBlockName)
// Again a replace for content to catch up the fucked up regexp in
GETFILE
BlocksRAW.Add ParentBlockName, TempContent & "[% _BLOCK_" &
CurrentBlockName & " %]" & Replace(Content, "?", "[")

CurrentBlockName=ParentBlockName
End If
End If
Next

Set Matches=Nothing
End Function


'-------------------------------------------------------------------------
' PARSEVARS
'
' Recursively parse the variables in a block. Input is the content of
that block

'-------------------------------------------------------------------------

Private Function ParseVars(NewBlockContent)
Reg.Pattern = regSearchVariables
Set Matches = Reg.Execute(NewBlockContent)
For Each Match in Matches
If Match.Submatches(2) <> "" Then
// Variable has a default value, because an = sign is found
Variable = Match.Submatches(1)
Value = Match.Submatches(3)

// Assign the value to the variable, but only if none was assigned
yet.
// This value is used as default value, it can be overruled at any
time.
If NOT Vars.Exists(Variable) Then
Vars.Item(Variable) = Value
End If

// Now check if the parameter hidden was given. If it was, delete the
var from the tpl.
// If it wasnt, replace the value assigning part from the var, and
just give a plain var
// so {var=value} will become {var}... Later on it will be parsed as
value.
If Match.Submatches(4) = "hidden" Then
// var is hidden
NewBlockContent=Replace(NewBlockContent, Match.Submatches(0), "",
1, -1, 1)
Else
// var is not hidden, replace the entire varstring with a normal var
NewBlockContent=Replace(NewBlockContent, Match.Submatches(0), "{" &
Variable & "}", 1, -1, 1)
End If
Else
// Normal variable. Parse it as a normal one
NewBlockContent=Replace(NewBlockContent, Match.Submatches(0),
Vars.item(Match.SubMatches(1)), 1, -1, 1)
End If

NewBlockContent=ParseVars(NewBlockContent)
Next

// CIMS Special:
// Parse the modules.
Reg.Pattern = regSearchModules
Set Matches = Reg.Execute(NewBlockContent)
For Each Match In Matches
If Vars.Exists(Match.SubMatches(1)) Then
NewBlockContent=Replace(NewBlockContent, Match.Submatches(0),
Vars.item(Match.SubMatches(1)), 1, -1, 1)
End If
Next

ParseVars=NewBlockContent
End Function




'-------------------------------------------------------------------------
' GETFILE
'
' Get template file

'-------------------------------------------------------------------------

Private Function GetFile(Template)
Set FSO = Server.CreateObject("Scripting.FileSystemObject")

If Trim(Template)<>"" Then
If FSO.FileExists(Server.MapPath(Template)) Then
Set File = FSO.OpenTextFile(Server.MapPath(Template))

GetFile=File.ReadAll
Else
If NOT blIgnoreErrors Then Response.Write "<p>---WARNING: Template
file <b>[" & template & "]</b> could not be found!---</p>"
End If
Else
If NOT blIgnoreErrors Then Response.Write "<p>---WARNING: Tried to load
template but no name was specified---</p>"
End If
End Function


'-------------------------------------------------------------------------
' CONSTRUCTTEMPLATE
'
' Recursively get include files from those template files

'-------------------------------------------------------------------------
Private Function ConstructTemplate(Template)
TemplateContent=GetFile(Template)

// If this prop is set to true, ignore included templates
If IgnoreIncludes=False Then
// Replace variable filenames with their values (for dynamic including)
Reg.Pattern = regSearchVariableIncludes
Set Matches=Reg.Execute(TemplateContent)
For Each Match in Matches
TemplateContent=Replace(TemplateContent, Match.SubMatches(0),
Match.SubMatches(1)&Vars.Item(Match.SubMatches(2))&Match.SubMatches(3),
1, -1, 1)
Next

// Recursively rerieve the contents of the included templates, and add
it to the main template.
// strDefaultIncPath comes from the DEFAULTINCLUDEPATH property

Reg.Pattern = regSearchStaticIncludes
Set Matches=Reg.Execute(TemplateContent)
For Each Match in Matches
// Handle the combination of the path and the default include path
If strDefaultIncPath<>"" Then
If Right(strDefaultIncPath, 1)="/" and Left(Match.SubMatches(1),
1)="/" Then
// Both contain a slash, delete one
strTemplateFile = strDefaultIncPath & Mid(Match.SubMatches(1), 1,
Len(Match.SubMatches(1)))
ElseIf Right(strDefaultIncPath, 1)<>"/" and Left(Match.SubMatches(1),
1)<>"/" Then
// None contains a slash, add one
strTemplateFile = strDefaultIncPath & "/" & Match.SubMatches(1)
Else
// One contains a slash, it's ok
strTemplateFile = strDefaultIncPath & Match.SubMatches(1)
End If
Else
strTemplateFile = Match.SubMatches(1)
End If
TemplateContent=Replace(TemplateContent, Match.SubMatches(0),
ConstructTemplate(strTemplateFile), 1, -1, 1)
Next
End If

ConstructTemplate=TemplateContent
End Function


'-------------------------------------------------------------------------
' EMPTYDICTIONARIES
'
' Empties all dictionaries so they can be re-used

'-------------------------------------------------------------------------
Private Sub EmptyDictionaries()
// If IsObject(Vars) Then Vars.RemoveAll
If IsObject(BlocksRAW) Then BlocksRAW.RemoveAll
If IsObject(BlocksParsed) Then BlocksParsed.RemoveAll
End Sub


'-------------------------------------------------------------------------
' COUNTDIMS
'
' Count the dimensions of an array. Its sloppy, but its the only way, and
I dont want to use JScript :)
' NOTE: Currently not used anymore, included it though for possible
future use.

'-------------------------------------------------------------------------
Private Function CountDims(ArrayName)
If IsArray(ArrayName) Then
On Error Resume Next
i=0
Do While Err.Number=0
i=i+1
UBound ArrayName, i // will generate error some time
Loop
On Error GoTo 0 // just being nice
CountDims=i-1
End If
End Function
End Class

%>
 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG