[stringtemplate-interest] group loading is messy
Caleb Lyness
caleb.lyness at ezswitch.net
Mon Nov 27 15:36:02 PST 2006
Nate wrote:
> Why is group loading so messy?
>
Because you are using a square peg for a round hole?
> The worst part is that a .ST group file and a directory containing
> templates are really two different kinds of groups. Eg, I have this
> directory structure...
>
> redskin/template1.st
> redskin/template2.st
> blueskin/template2.st
>
> I want blueskin to extend redskin. The way I ended up doing this is to
> create a text file named "supergroup" which contains the name of the
> super group, which I manually load and call setSuperGroup. Why can't I
> have a .ST file that defines the template group and the directory? This
> way I could define the super group in the .ST file as well as templates
> AND I could have template files in the same directory. Currently I can't
> mix defining templates in a group file and using a directory of templates.
Group file (stg) and template files serve a different purpose.
I have something similar though,
generic/template1.st
generic/template2.st
generic/resgroup1.stg
skin1/template2.st
skin2/template1.st
generic/resgroup1.st
I wrote a wee class which loads the group file in a hierarchically way
and I removed my custom class loader and replaced it with something based
on the one email /you /sent a couple of weeks back (Thanks - its a
simple solution).
I wanted something like this:
skin/template.st -> generic/template.st -> skin/resgroup1.st ->
generic/resgroup1.st
(Actually a little more complex, because I have common templates and
language based templates too,
but it illustrates the example)
So for the first part:
final Vector<File> searchPath = new Vector<File>(4);
....
// Fill in the search path with the thing you want to inherit from in
order. Like you would with the jar classpath
,,,,
templateGroup = new StringTemplateGroup("templates") {
protected StringTemplate
loadTemplateFromBeneathRootDirOrCLASSPATH (String fileName)
{
for (File dir: searchPath) {
String file = new File(dir,fileName).toString();
StringTemplate result =
super.loadTemplateFromBeneathRootDirOrCLASSPATH(file);
if (result != null) {
return result;
}
}
return null;
}
};
templateGroup.setSuperGroup(resourceGroup);
There is nothing stopping you from defining a resource group which knows
how to define the search path
for your templates. That way you don't need to hard code 'em. If you are
complaining about having to manually
join the group templates and template files.
Cheers
Caleb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061128/7e17766a/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3269 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061128/7e17766a/attachment.bin
More information about the stringtemplate-interest
mailing list