Code generation
Saturday, February 3rd, 2007Three weeks ago I finally started working on the Fuel CMS project after an intense (?!) 7 month laziness. So evidently I started by building my code generator application.
FuelGenerator is built in Perl and at the moment connects only to MySql databases to retrieve information for the current database such as table information (columns and indexes), the information is stored in custom data classes that later on are serialized (JSON) and sent to the template file.
FuelGenerator is a pluggable template system and uses the PHP5 CLI or the erb (Ruby) interpreter. Basically the serialized information is sent to a file called “include file”. The “include file” will deserialize the JSON structure and
include the actual template file in which we have references to the deserialized structure.
Example:
1 2 3 4 | $table = json_decode('{TABLE}'); $parameters = json_decode('{PARAMETERS}'); {CONTENT} |
{TABLE} represents the definition for the current table and is identified with the JSON info structure for it.
{PARAMETERS} is the JSON structure for the additional template parameters.
{CONTENT} is the content for the template.
All these values are replaced at runtime and then excuted with the specified interpreter, after the execution the generated content is saved into a a file.
I will place a copy of this application for download as soon as I finish the POD (Plain Old Documentation) for the Perl files.