Code Monkey home page Code Monkey logo

wisdom-mustache-template-engine's People

Contributors

cescoffier avatar jenf11 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wisdom-mustache-template-engine's Issues

Template inheritance issue

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

Absolute path for partials are not working

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.