CGI Framework
Specialized Tag Interpreters

Basics

Docs

Components

Templates

Tools

Demos


SourceForge.net Logo

Brasil
   

Specialized Tag Interpreters

We told it's possible (and easy) to subclass TTagInterpreter to obtain a special purpose descendant to solve specific classes of problems commonly found on CGI programing.

Actually, the current CGI Framework version offers 2 TTagInterpreter direct descendants: TPBTagInterpreter and TDbTagInterpreter.

TPBTagInterpreter

TPBTagInterpreter supply 2 basic services: file inclusion and variable handling. All the tags TPBTagInterpreter process are in the "PB" namespace. TPBTagInterpreter does not publish NameSpace property but you can change it programatically in run-time.

I believe an example is the best way to show how TPBTagInterpreter works:

File: index.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<pb:var name="pageTitle" value="CGI Framework - Home Page"/>
<pb:include filename="head.html"/>
  <body>
<pb:include filename="top.html"/>
    <!-- Page contents goes here...-->
<pb:include filename="botton.html"/>
  </body>
</html>

File: head.html

<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  <title><pb:var name="pagetitle"/></title>
  <meta name="genterator" content="CGI Framework">
  <meta name="author" content="Ivan C Cruz">
  <link rel="stylesheet" type="text/css" href="cgiframework.css">
</head>

The example include 2 html templates to be glued together and result on a (almost) complete html page. You will find two different "PB" tags there: "include" and "var". Both are simple tags, and according to PageBuilder rules, they must have the finishing slash.

When TPBTagInterpreter process a "var" tag it looks for the attributes "name" and "value". "name" is a mandatory attribute. "var" tags with both "name" and "value" causes the name and value be stored in a internal variables pool, no text replacement is made. When "var" tag has only a name, its value is recovered from the variable pool and replace the tag on the resulting html code.

Tag "include" is used many times in the "index.html" file. For each "include", a file is scanned on the directory pointed by the "IncludeDir" property and its contents replace the "include" tag. Just "head.html" is shown above but the others "include"s will behave the same.

Before making the replacement, TPBTagInterpreter recursively call the "parent" PageBuilder "GetContentFromStream" method to process all tag in the file about to be included. In that way, the "var" tag present in "head.html" gets processed and the value "CGI Framework - Home Page" defined in "index.html" took place inside the "title" tag.

The final html code will looks like that:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  <title>CGI Framework - Home Page</title>
  <meta name="genterator" content="CGI Framework">
  <meta name="author" content="Ivan C Cruz">
  <link rel="stylesheet" type="text/css" href="cgiframework.css">
</head>
  <body>
   ...
    <!-- Page contents goes here...-->
   ...
  </body>
</html>

Of course TPBTagInterpreter is capable of "understand" many other tags and tag options. But they will be detailed in another section.

 


Copyleft (2002) Ivan C. Cruz
Site contents may be reproduced in all or in part since you provide a clear statement citing that site as your source.

That site was built and tested with Mozilla. If some components looks misalligned or not properly rendered, it may be your browser fault. In that case, please, consider an upgrade.