<${switch} Statement  

The ${import} statement

Being able to expand a template is nice, but you will soon reach the point where you would like to compose the output from pieces that each have their own, limited areas of responsibility. For example, a generated source code file might be composed from a generic preamble, a class declaration, and several nested elements. Each of these elements could reside in its own template.

Here is an example of a class file template:


package ${class.package};

public class ${class.name} extends ${class.superclass.fullname} {
${foreach(ctor:class.ctors) #indent+=4}

${foreach(method:class.methods) #indent+=4}

This is an example of a source code file preamble template. It includes terp expressions that cause an accurate copyright statement and other build information to be included:


// Copyright (c) 2008-${now['%tY']} by Codemesh, Inc.
// This file was generated on ${now} by ${generator.user}.
// It is part of the  ${product.version} release. 

The constructor template relies on the fact that the ctor and class objects are defined. The class.tpl template provides definitions for both variables.


(  ) {
    // the constructor contents 

There's a certain amount of pseudo-code in these examples, but you probably get a pretty good idea of how you can use, and reuse, templates by importing them into parent templates.

Copyright 2006-2016 by Codemesh, Inc., ALL RIGHTS RESERVED

codemesh.com home expressions templates ant about us contact us download