From RTSC-Pedia

Jump to: navigation, search
revision tip
—— LANDSCAPE orientation
[printable version]  [offline version]offline version generated on 11-Jun-2009 18:06 UTC

XDCscript - Template-Body

Contents of the template file

Contents

Description

The body of a template contains lines of text that are automatically output when the template object is expanded via genStream() or genFile(). It also contains lines of script that are evaluated prior to generating output. This script code can reference any object in the current environment — with $out, this, and $args bound to parameters of genStream().

Syntax

text`script`text ... \n
A line of text to be output by the template at this point. All script between the `` quotes is replaced with its (textual) value in the current context.
% script ...\n
A single line of script evaluated by the template at this point.
%%{\n
stmt ...\n
stmt ...\n
%%}\n
Multiple lines of script to be evaluated at this point.

Example

The following script and template illustrate many of the capabilities of templates. This example generates a copyright header from a template.

gen.xs
 
 
 
var template = xdc.loadTemplate("copyright.xdt");
template.genStream(java.lang.System.out, this, 
    ["TI", arguments]);
copyright.xdt
 
 
 
 
 
 
 
 
 
 
 
 
%%{
    var NAME = $args[0];
    var CTRB = $args[1];
    var DATE = new Date().getFullYear();
%%}
/*  Copyright `DATE` by `NAME`.
 *  All rights reserved. Property of `NAME`.
 *  Contributions from:
%for (var i = 0; i < CTRB.length; i++) {
 *      `CTRB[i]`
%}
 */

Running this script produces the following output.

xs -f gen.xs bob carol ted alice
 
 
 
 
 
 
 
 
/*  Copyright 2008 by TI.
 *  All rights reserved. Property of TI.
 *  Contributions from:
 *      bob
 *      carol
 *      ted
 *      alice
 */

See also

XDCscript - Template-Object under construction
XDCscript - Template-Object.genFile Generate textual output file from a template
XDCscript - Template-Object.genStream Generate textual output stream from a template

[printable version]  [offline version]offline version generated on 11-Jun-2009 18:06 UTC
Copyright © 2008 The Eclipse Foundation. All Rights Reserved


Views
Personal tools
package reference