Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defect or User Error? No output for Dynamic Names #305

Closed
Hamilton-dfp opened this issue Jun 26, 2024 · 10 comments
Closed

Defect or User Error? No output for Dynamic Names #305

Hamilton-dfp opened this issue Jun 26, 2024 · 10 comments
Assignees

Comments

@Hamilton-dfp
Copy link

Hamilton-dfp commented Jun 26, 2024

Hi, the specification seems to have at least one typo regarding Dynamic Names, so I don't know if the problem I am facing is confusion about the specification, a defect in mustache.java, or if I am just plain wrong.

Code to Reproduce:

src/main/java:

public static void main(String[] args) {
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache m = mf.compile("pd-test.mustache");

        StringWriter writer = new StringWriter();

        m.execute(writer, Map.of("name", "dn"));

        System.out.println(writer);
    }

src/main/resources:

pd-test.mustache:

Do dynamic names work?

Answer: {{*name}}

dn.template:

Templates Do!

dn.mustache:

Mustache Do!

Expected Output:

Do dynamic names work?

Answer: Mustache Do!

or

Do dynamic names work?

Answer: Templates Do!

Depending on whether the named template should end in .template or .mustache (Specification example says .template, but that seems weird so I tried .mustache just to be safe, see Additional Notes below).

Actual Results:

Do dynamic names work?

Answer: 

Note that the dynamically named template is not loaded, regardless of extension.

Additional Notes

At a glance the specification suggests the proper syntax for dynamic names is {{>*name}}, however the actual wording says Dynamic Names consists of an asterisk, followed by a dotted name. This wording suggests that the greater than sign is not intended to be part of the syntax.

When using {{>*name}} in mustache.java I get the following error:

Exception in thread "main" com.github.mustachejava.MustacheNotFoundException: Template *name.mustache not found

Note that this error is why I tried using dn.mustache in addition to dn.template, plus the fact that it feels weird that the specification would introduce a whole new extension just for this one use case.

When I use {{*name}} as the wording of the specification suggests, mustache.java does not throw an error, but no content is included in the output.

Thanks for taking a look!

@spullara
Copy link
Owner

This was optional for the specification, and no one has ever asked me for it before. It probably isn't a huge burden to implement it, let me take a stab at it. For reference, this is the official "spec":

https://github.com/mustache/spec/blob/master/specs/~dynamic-names.yml

@Hamilton-dfp
Copy link
Author

That would be great.

I'll admit my use case requires a level of dynamism then what I would typically think mustache is suited for. However, mustache is easiest for me to execute on right now, and this feature is all that's missing to make this manageable.

Thank you for the official spec. It perfectly sums up the solutions I am hoping to avoid.

@spullara
Copy link
Owner

I have the change in a branch and will merge it shortly assuming no issues come up.

@spullara
Copy link
Owner

It is merged but it would great for you to test it if possible or propose a test case in a PR - right now it is passing the spec tests.

@spullara spullara self-assigned this Jun 27, 2024
Hamilton-dfp added a commit to Hamilton-dfp/mustache.java that referenced this issue Jun 27, 2024
@Hamilton-dfp
Copy link
Author

Thank you so much! Works just fine on my end.

Submitting a simple test for now:
#307

Getting ready to start some pretty gnarly use cases next. If I find anything that does not work I will submit more tests.

Thanks again!

@spullara
Copy link
Owner

Closing. If there is a bug that you find please open a new more specific issue. Thanks for helping make mustache.java more complete.

@Hamilton-dfp
Copy link
Author

@spullara

I've been using this feature pretty heavily and have not had any issues.

Could I request a release of 0.9.14 into maven central?

@spullara
Copy link
Owner

spullara commented Jul 7, 2024 via email

@spullara
Copy link
Owner

spullara commented Jul 7, 2024

0.9.14 was released but might take a bit to distribute from sonatype.

@Hamilton-dfp
Copy link
Author

Confirmed that it is available. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants