[stringtemplate-interest] STGroupXML - to configure templates in raw formats

Terence Parr parrt at cs.usfca.edu
Sun Dec 4 15:48:52 PST 2011


Hi Collin, This is an interesting approach. I think I'm going to make something very quickly that simply allows people to pull in templates without the headers.

Ter
On Sep 17, 2011, at 6:36 AM, Collin Fagan wrote:

> 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
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20111204/ede01807/attachment.html 


More information about the stringtemplate-interest mailing list