-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add example of lambda with template and @section
to docs
#275
Comments
For others: https://jstach.io/jstachio/io.jstach.jstache/io/jstach/jstache/JStacheLambda.html I guess the big problem is that the documentation just builds on previous examples. I assume you saw this in the Javadoc? :
@JStacheLambda(template="<span class="{{>@section}}">{{>@section}}<span>")
public boolean isEven(int index) {
return index % 2 == 0;
} From the Mustache Manual:
That is why the javadoc says:
However there is a workaround for most use cases and that is what Example based on Mustache Manual
In JStachio you would accomplish the above with @JStache(template="{{#wrapped}}{{name}} is awesome.{{/wrapped}}")
record Model(String name) {
@JStacheLambda(template="<b>{{> @section }}</b>")
public Object wrapped(Object model) {
// We do not care about the stack for this so ignore the model parameter
return model;
}
}
At some point I was planning on making Such that you can do
So you can think of the section template implicitly bound to the empty string ( As for the spelling ... I have been meaning to turn spell check back on but I get so many false positives in Eclipse. How is VSCode on that front since you use it IIRC? |
So the paragraph I quoted was detached from its example? Or maybe just didn't refer to its example? It's still confusing (for me anyway). Aside: I kind of hate the "ignore the model parameter" part. It can't just be a void method with no parameters? There must be other lambdas where you don't care about the input model? Maybe the restriction that makes lambdas with no parameters illegal is unnecessary? I don't have any spelling extensions enabled in VSCode. I expect they exist but I haven't tried them, sorry. |
Yes it is a terrible verbiage filled paragraph of me internally gloating over a unique workaround. As you can tell I have a difficult time being pithy 😄.
Yes indeed. I got lazy on this. We can file another issue and I will make that possible but I had hesitation on that work as I think Power Filters are the future. Ignoring the That is to say lambdas in JStachio and JMustache are way too overloaded and can do too many things and your comments confirm my suspicion that Power Filters are the right way of transform something on the top of the stack (well first part of pipe). I'm going to ping @jgonggrijp just to show a use case of how overloading lambdas can confuse albeit possibly from my poor explanation. |
Also there is a full code example in the Javadoc on the template parameter: https://jstach.io/jstachio/io.jstach.jstache/io/jstach/jstache/JStacheLambda.html#template() I admit its discoverability is poor. Perhaps I will repeat it on the class description as well. |
There is a cryptic paragraph in the Javadocs for
@JStacheLambda
:Sounds interesting but makes no sense to me without a full example (Java and template).
(Also note spelling mistake on "declarative".)
The text was updated successfully, but these errors were encountered: