samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
834 stars 128 forks source link

Allows to understand tree structure from the Visitor interface #119

Open Dedrakot opened 4 years ago

Dedrakot commented 4 years ago

I need to create a tree structure of the future template model before request it. Visitor interface almost suits this purpose, but I need to know when I should return back to the parent node.

It will be great if it can be useful to someone else. If you think it's not, just close the pull request.

Additional notes: I can add returnFromInvertedSection method or remove name argument from returnFromSection.

agentgt commented 9 months ago

@Dedrakot are you still using JMustache and Visitor interface?

I'm curious how many are still using it because there are issues with it including as you noted knowing if you returned.

I'm going to tag a few others that I found by looking through old issues/prs that wanted / using the visitor pattern: @pmenhart @meirf @sandwwraith @samskivert

The problem with the Visitor pattern is that inevitable people really just want the tree and or its easier to navigate a tree (in this case AST).

This is because the Visitor pattern does not make it clear or easy to navigate in a different order.

Also Mustache has changed a lot over the years. There are tons of ambiguity when it comes to "dotted" keys, blocks (inheritance), parents, lambda sections etc. And I promise this will get worse as new features such as "filters" get added to the spec.

For example even if we add returnFromSection which on the surface seems like a reasonable request it will not work correctly or the way one expects when dealing with parents and blocks.

Example:

root.mustache:

{{< parent }}{{$a}}a{{/a}}{{/parent}}
{{$a}}b{{/a}}

parent.mustache:

{{$a}}c{{/a}}

If we traverse the nodes which $a should come first and how do we know if the $a comes from the parent partial, inside the partial call?

So you can see you need more than just returnFromSection but returnFromParentTemplate and returnFromParentBlock etc.

That is not to say the feature isn't useful for collecting key names its just that is about all its useful for at the moment.

The only thing I could see of use is if someone has a fairly flat model and wants to have some sort of UI that does completion or kind of validates which is I believe what @pmenhart is using the feature for.

So I want to see how people are using this because IMO if JMustache ever has a 2.0 I would love to remove it as one of the defining characteristics of JMustache over say Mustache.java is that it is fairly small.

sandwwraith commented 9 months ago

FTR, I don't use it anymore and don't even remember commenting some feature, sorry :)