From RTSC-Pedia

Jump to: navigation, search
revision tip
—— LANDSCAPE orientation
[printable version]  [offline version]offline version generated on 04-Aug-2010 21:08 UTC

XDCscript - xdc.loadTemplate

Create a template object from a template file

Contents

Synopsis

 
var templateObject = xdc.loadTemplate(templatePathName);

Parameters

templatePathName 
string file name of the template to be loaded; e.g., "my/template/pkg/foo.xdt" The template file is located via xdc.findFile().

Description

xdc.loadTemplate() loads a template file and returns a template object that can then be used to generate output either to a file or an output stream. This object has two methods that "expand" the template into either an existing output stream or into a new file.

  • tplt.genFile(fileName, thisObj, args, clobber)
    Generates output to fileName, which is created if necessary. Unless clobber is true, an existing file is overwritten only when its content has truly changed.
  • tplt.genStream(outStream, thisObj, args)
    Generates output to outStream, an instance of class java.io.PrintStream. All three parameters are passed to the underlying template generation function.

Return Value

xdc.loadTemplate returns a template object or throws an exception if the package can not be found or a syntax error occurs within the template file itself.

Example

Suppose the file header.xdt is a template for a C header that has an include guard based on the first argument of the argument array passed to the genFile method. The following code fragment will generate a file named "foo.h with an include guard based on the string "foo".

foo.xs
 
 
var template = xdc.loadTemplate("header.xdt");
template.genFile("foo.h", this, ["foo"]);
header.xdt
 
 
 
 
 
 
 
 
 
 
%%{
    var NAME = $args[0];
%%}
/*  
 *  ======== `NAME`.h =========
 */ 
#ifndef `NAME`_include
#define `NAME`_include 1
 
#endif /* `NAME`_include */

See also

XDCscript - Template-Body Contents of the template file
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 04-Aug-2010 21:08 UTC
Copyright © 2008 The Eclipse Foundation. All Rights Reserved


Views
Personal tools
package reference