I was running into problems with it in our multi-artifact monorepo at times and I just sort of got tired of working around it. I also wasn’t 100% sure I was doing it correctly, conditionally, for use with GraalVM-native so I figured I should just remove the “at times”/uncertainty and be done with it. Lots of next.jdbc
users seem to want the snake/kebab conversions anyway (and it’s not like next.jdbc
doesn’t already depend on other libs — I’m a bit surprised the java.data
dependency/code doesn’t cause GraalVM-native issues…?).
New Selmer release! 🎉. Selmer is a powerful templating engine for Clojure and is now written in 100% pure Clojure with no external dependencies.
https://github.com/yogthos/Selmer
1.12.38 - made JSON dependency pluggable, remove hard dependency on cheshire
1.12.36 - improved default pretty printing of the context map using debug tag
- allow whitespace in filter: {{ foo | default:bar }}
1.12.35 - made json-html dependency optional, removed commons-codec dependency
Thanks @yogthos for the awesome library and being open to receive these enhancements.
Selmer (1.12.35) is now part of #babashka (version 0.3.8, bb will bump to Selmer 1.12.38 soon).
Main thing missing from Selmer compared to python’s Jinja 2 (which has similar syntax) is whitespace control. If you put tags like {% if %}
on their own line, you’ll get an empty line in the output. and you cannot say {%- if -%}
. It makes writing some whitespace sensitive markup like YAML really hard. You basically need to keep the if, else, endif to the same line which can be a real mess.
Maybe you can post an issue about this?
5 years old 🙂
@yogthos ?
Ah it seems he’s open to the contribution so what are people waiting for :)
Hehe, I think the change is pretty large, as it fundamentally changes the processing, because you might have to remove content before the tag based on the tag itself
Has anyone tried?
Haven’t seen it 🙂
On the second thought, it doesn’t change the render, it changes the template parse, as you can already cut the appropriate whitespace when you parse the template
I made a change to allowing whitespace in filters yesterday. It was doable. Don’t know about this change, but seems like a nice challenge
Thank you so much @borkdude! Great release!
and yeah white space control is a bit of a rabbit hole, the trickiest part is that you have to be able to look ahead to the end of the line to see if it's just space, and the reader doesn't support unbounded look ahead
so you'd have to make a version of a reader that's able to scan to see if the next non space character is a new line
@yogthos isn't this just about ignoring all whitespace between tags? I think this can be done using a flag? when you encounter the "signal" to ignore whitepace, you set the flag, then the reader ignores all blank TextNodes, until it finds the next "signal" to ignore whitespace?
oh I guess there are a few different cases here, one I was thinking of is if you have a tag on an empty line, and you want to remove that line after
space inside the tag is easier to control
you mean it like this right?
{% if foo} <inside tag> \n\n {{dude}} <inside tag> \n\n{% endif}
from the issue I was interpreting it like that: people would like to spread the expression over multiple lines, while not rendering multiple lines
but it would be good to double check
oh I guess yeah that could be another use case 🙂
There’s basically 2 cases:
{% tag -%}
is easy you basically start droping whitespace after the tag until you find something that is not a tag
The other case is {%- tag %}
which you can solve if you maintain the index of the last non-whitespace character you’ve encountered, then when you hit a tag like that you can simply set the length on the StringBuilder back to that index before you proceed with .setLength
ah is that how it works
@roklenarcic I have a branch which is very close to this, I think
That;s how I would approach it at least
but I discussed this syntax with yogthos and it didn't feel compose-able to me. we bounced around some ideas and came up with e.g.
{% tag(trim) %}
, a bit like [:tag {:trim true} ...]
in hiccup
but I guess we can meet people where they are coming from jinja etc
@roklenarcic Feel free to try out this branch: https://github.com/borkdude/Selmer/tree/whitespace-control
You should think carefully if your variant enables everything that you get when you have 3 different variants available:
{%- tag %
} , {% tag -%}
and {%- tag -%}
I assume your solution is only 1 of these 3
I was mostly working on this from the angle of "is it possible", I wasn't actually interested in any specific solution