[stringtemplate-interest] ST4: Directory STGroups, common templates, relative template names?
Barrie Treloar
baerrach at gmail.com
Tue Apr 19 19:17:26 PDT 2011
I've built my ST3 process around not having a single group file
(*.stg) but using a directory instead.
I've ported this wholesale into ST4 and have a couple of questions.
I'm finding that when a template needs to invoke another template then
the template name must be specified as a relative path from the Group.
e.g.
<STGroup.dir>/
- mytemplate.st
- common/HelloWorld.st
- common/Hello.st
- common/World.st
In:
* mytemplate.st -> <common/HelloWorld()>
* common/HelloWorld -> <common/Hello()> and <common/World()>
This makes sense when I look at the code, but I had naively expected
that in common/HelloWorld to be able to reference <Hello()> and
<World()>
Having relative paths is making my templates a bit uglier than I
thought when I started separating out the files into multiple
directories, but that is better than having 60+ templates living in
the one directory.
It gets a bit more worse when you have multiple directories.
Does anyone have advice for me?
Should I move to using a *.stg file instead? I've not used a *.stg
file before, but since I can import templates from a directory, ala
import "test" // import a directory of templates
(http://www.antlr.org/wiki/display/ST4/Group+file+syntax)
Perhaps that will do what I want...
Can I import "*" somehow?
Should directory based groups have similar functionality some how?
(As an aside, if you make a typo [in either the filename or
templatename] then ST will not be able to find your template and will
give you an error because the template does not exist. From what I
can tell you can not also define other template names within the
template file either. In java terminology the *.st must match the
name of the single public template within the file and no
package/private templates may also live inside that file
Is this expected behaviour?)
Cheers
More information about the stringtemplate-interest
mailing list