Scaffold - Templates

Home

A template is a directory containing structure (files and other directories) that is used by generators to create content in project output path.

Names of the files and directories may contain special ${markers} to indicate variables that should be replaced by values.

Templates may be located anywhere on the file system. A special directory may be set-up to group the templates and its location is saved as a variable - TPATH - at global scope.

The content of the template directory and the content of the files inside it are decided by the generator that is intended to interpret the template. Following guidelines should be implemented to give a sence of consistency:

  • all the content except the directories that start with an underline character ( _ ) should be used as "static" templates, with a one-to-one corespondence with the files in the resulting directory;
  • all generators should support variables in the names of "static" templates using the ${markers} form;
  • all generators should support variables inside "static" file templates with {{markers}} indicating special areas;
  • "dynamic" templates should be placed inside a directory at the top level of the template whose name consists of an underscore and the name of the generator that will interpret the template or the word "dynamic" if more than one generators may/will use it.

Inside {{markers}} a form of customised javaScript is used, as defined in the ECMA-262 standard. We're enhancing the list of features available because of this with :

  • a print() command that outputs text in place of the {{markers}}
  • the variables from the control file (one array for each). Those that are part of the project are available under the PRJ object, while those in the generator have their own GEN object.
If all you want to do is place the value of a variable in the file the alternate {%var_name%} notation is available, that gets replaced with print(var_name);

For example following file:

1 Some lines of
2 text. Insert some numbers:
3 {{ var a = 1; print(a); a = a + 1; print(a); }}
4     
is converted into this script:
1 print( "Some lines of\ntext. Insert some numbers:\n" );
2 var a = 1; print(a); a = a + 1; print(a);
3     
that, in turn, creates this file:
1 Some lines of
2 text. Insert some numbers:
3 12
4     

Related source code documentation:

Home