Cosmo (000004)

Cosmo is a "safe templates" engine that is used by Sputnik but which can also be used for many other purposes.

You can get the trunk copy of Cosmo from SVN.

Cosmo provides three functions that you would want to use.

The first one is cosmo.fill which takes two parameters: a string and a table. The string can be in any format and cosmo only looks for two kind of patterns in it:

$var_name

and

$fn_name\[[ a subtemplate ]\]

Note that in the latter case, [=[...]=], [==[...]==], etc. can be used instead of [\[...]\].

If Cosmo encounters something that looks like $var_name it will simply look up the value in the template and substitute it. E.g.:

cosmo.fill( $x+$y = $sum ,

           { x   = 1,
             y   = 2,
             sum = "?" } )

will return

 1+2 = ?  

If cosmo.fill finds something like $fn_name[\[...]\], it will look up the fn_name field in the table but will assume this field to be a function.

Powered by Sputnik | XHTML 1.1