wisdom-framework / wisdom-mustache-template-engine Goto Github PK
View Code? Open in Web Editor NEWProvides Mustache templates support to Wisdom applications
License: Apache License 2.0
Provides Mustache templates support to Wisdom applications
License: Apache License 2.0
Hi,
I'm trying to use the Mustache template inheritance in Wisdom.
I have an issue when the "super" template is in another directory than the "child".
For example create a base.mst.html
template in src/main/resources/templates
with this content:
<html>
<head>
<title>{{$title}}{{/title}}</title>
</head>
<body>
<h1>{{$content}}{{/content}}</h1>
</body>
</html>
And another welcome.mst.html
template in src/main/resources/templates/home
with this content:
{{<../base}}
{{$title}}Welcome page{{/title}}
{{$content}}
{{welcome}}
{{/content}}
{{/../base}}
I have the following error:
com.github.mustachejava.MustacheException: Template 'home/../base' not found
at org.wisdom.framework.mustache.ExtendedMustacheFactory.getReader(ExtendedMustacheFactory.java:97) ~[na:na]
at com.github.mustachejava.MustacheParser.compile(MustacheParser.java:27) ~[na:na]
at com.github.mustachejava.DefaultMustacheFactory.compilePartial(DefaultMustacheFactory.java:276) ~[na:na]
at com.github.mustachejava.codes.ExtendCode.init(ExtendCode.java:71) ~[na:na]
at com.github.mustachejava.codes.DefaultCode.init(DefaultCode.java:118) ~[na:na]
at com.github.mustachejava.codes.DefaultMustache.init(DefaultMustache.java:64) ~[na:na]
at com.github.mustachejava.DefaultMustacheFactory.compile(DefaultMustacheFactory.java:224) ~[na:na]
at com.github.mustachejava.DefaultMustacheFactory.compile(DefaultMustacheFactory.java:218) ~[na:na]
at org.wisdom.framework.mustache.MustacheTemplate.compile(MustacheTemplate.java:83) ~[na:na]
If I'm not wrong, the syntax for referring to the super template {{<../base}}
is ok but I'm not 100% sure.
I've tested the inheritance when the "super" and the "child" are in the same directory, and it's working perfectly.
Did I do something wrong, or is it a limitation or a bug ?
BTW: I've tested with Wisdom 0.6.4 and today master of the wisdom-mustache-template-engine project. Also, I'm on Windows 7 / Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Thanks for your help
WBR // David
Hi,
Giving absolute path {{> /layout/formPage.mst.html}}
is not working.
Indeed, the resolvePartialPath
of DefaultMustacheFactory takes into account absolute path but the getReader
in ExtendedMustacheFactory does not.
Adding the following code make it work:
@Override
public Reader getReader(String name) {
// On windows the path containing '..' are not stripped from the path, so we ensure they are.
String simplified = name;
if (name.contains("..")) {
simplified = Files.simplifyPath(name);
}
// Take into account absolute path
if ( simplified.startsWith( "/" ) && simplified.length()>1 )
{
simplified = simplified.substring( 1, simplified.length() );
}
for (Template t : collector.getTemplates()) {
MustacheTemplate template = (MustacheTemplate) t;
if (template.name().equals(simplified)) {
try {
return IOUtils.toBufferedReader(new StringReader(IOUtils.toString(template.getURL())));
} catch (IOException e) {
throw new MustacheException("Cannot read the template " + name, e);
}
}
}
throw new MustacheException("Template \'" + name + "\' not found");
}
WBR
JB
A 0.9.0 version is available.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.