[stringtemplate-interest] STGroupXML - to configure templates in raw formats
Collin Fagan
collin.fagan at gmail.com
Sat Sep 17 06:36:06 PDT 2011
Hi All,
There has been some expressed desire to have a template be just a .html file
(or any other plain file for that matter) and not have to surround every
template with "TEMPLATE_NAME() ::= <<>>". To facilitate this use case I've
created some proof of concept code that uses XML to specify a group of
thease "raw template files".
Here is an example of the XML behind an STGroupXML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<group>
<template name="method">
<arg>name</arg>
<arg>body</arg>
<arg>cleanup</arg>
<location>templates/method.txt</location>
</template>
<template name="useMethod">
<location>templates/useMethod.txt</location>
</template>
</group>
Method.txt contains the following text:
void <name>() {
<body>
<cleanup>
}
Notice there is no template def at the beginning.
Also the useMethod template similarly has no template definition at the top.
<method("getName","return firstName","")>
Like int other groups these templates can call each other.
The code create an STGroupXML object if very similar to other STGroups.
STGroupXML group = new STGroupXML(new File("test.xml"));
ST template = group.getInstanceOf("useMethod");
System.out.println(template.render());
I think this would be one way to allow files to be of any extension and
allow HTML editors to work better whit ST templates.
I will be cleaning up the code and checking into strum soon.
What do people think?
Collin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110917/799e1cb8/attachment.html
More information about the stringtemplate-interest
mailing list