Skip to content

A simple utilitary library to provide *real* dynamic includes in Classic ASP.

License

Notifications You must be signed in to change notification settings

the-linck/ASP-Dynamic-Include

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

VBScript Dynamic Includes

A simple utilitary library to provide real dynamic includes in Classic ASP.

There are not many relevent new resources to be added in this project, so certainly it won't be updated frequenly - except in case of errors or problems.

How to use

Just do a classic server-side include to add DynamicInclude.asp on your project and call the methods provided by this library to load files dynamically.

Hint: obviously it's faster to use standard includes when posssible than calling everything by this library.

Provided Methods

There are two methods for executing files, inspired in PHP's way of including files:

  • Include(string File)
    Tries to include a file on current script. If no errors occur file is included, else just fails quietly.
  • Require(string File)
    Tries to include a file on current script. If no errors occur file is included, else ends script execution with an error message.

Control Flags

This variables are provided to control the behavior of the including process:

  • string DynamicInclude_PreviousPath
    Path of the last included file, used for recursive file importing.
    May be used along with DynamicInclude_CurrentPath to change how recursive imports will behave.
  • string DynamicInclude_CurrentPath
    Path of current file to include, used for recursive file importing.
    May be used along with DynamicInclude_PreviousPath to change how recursive imports will behave.
  • boolean DynamicInclude_TrimHtml
    If HTML text should be trimmed while parsing.
  • boolean DynamicInclude_TrimNewlines
    If duplicated new lines hould be removed from parsed text.

More control flags may be added in the future. Flags meant only for internal use are not listed for obvious reasons.

Parsing proccess

The inclusion is made reading and parsing the files, converting all plain-text blocks to sequences of Response.Write commands. Short ASP output tags (<%=) in are expanded to Response.Write commands.

During the those steps, all ASP tags (<% and >%) are removed from the code.
At the end of this proccess, all text is conveted to plain VBScript output with valid code.

Warning: Everything will be executed on the global namespace. A flag to control this behavior may be added in the future.

Warning: Do not import/require files the have VBScript Class declarations inside control flow statements (if/else/case) or loops. Conditional class declaration isn't supported by Classic ASP.

This library is not meant to be used in pure VBScript projects, because such complex parsing isn't even needed for plain .vbs files.

Additional Methods

The following methods are also provided with the library, because they are internaly used by Include and Require:

  • ExecuteFile( string File, FileSystemObject System)
    Imports and executes File in the global namespace, dealing with paths for recursive calls.
  • string ParseFile( string File)
    Reads File as ASP code.
  • string ReadFile( string File)
    Reads File as plain text.

Deprecated methods

This extra methods were removed from main code file (DynamicInclude.asp) because were not really needed for the library functionality or even were bad for performance.

Those methods are:

  • boolean FileDoExist( string File, FileSystemObject System)
    Checks if File does exist in System. Useful to avoid extra FileSystemObject allocation.
    Deprecated due to unnecessary increase of call stack
  • boolean FileExists( string File)
    Checks if File exist.
    Deprecated because it was not used
  • string FileName( string File)
    Gets the name of the file.
    Deprecated due to unnecessary increase of call stack
  • string FilePath( string File)
    Gets the path of a file.
    Deprecated due to unnecessary increase of call stack
  • FileSystemObject FileSystem( )
    Syntax sugar.
    Deprecated because it was completely unnecessary
  • string MapPath( string File)
    Gets the absolute equivalent of Path.
    Deprecated due to unnecessary increase of call stack

About

A simple utilitary library to provide *real* dynamic includes in Classic ASP.

Resources

License

Stars

Watchers

Forks

Packages

No packages published