Fork me on GitHub
#announcements
<
2021-05-06
>
borkdude19:05:58

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).

🎉 67
babashka 29
roklenarcic07:05:19

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.

borkdude07:05:48

Maybe you can post an issue about this?

roklenarcic07:05:50

5 years old 🙂

borkdude07:05:12

Ah it seems he’s open to the contribution so what are people waiting for :)

roklenarcic07:05:05

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

borkdude07:05:19

Has anyone tried?

roklenarcic07:05:10

Haven’t seen it 🙂

roklenarcic07:05:54

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

borkdude07:05:16

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

Karol Wójcik09:05:38

Thank you so much @U04V15CAJ! Great release!

yogthos12:05:09

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

yogthos12:05:40

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

borkdude13:05:56

@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?

yogthos13:05:53

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

yogthos13:05:20

space inside the tag is easier to control

borkdude13:05:19

you mean it like this right? {% if foo} <inside tag> \n\n {{dude}} <inside tag> \n\n{% endif}

borkdude13:05:46

from the issue I was interpreting it like that: people would like to spread the expression over multiple lines, while not rendering multiple lines

borkdude13:05:57

but it would be good to double check

yogthos14:05:44

oh I guess yeah that could be another use case 🙂

roklenarcic18:05:34

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

roklenarcic18:05:55

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

borkdude18:05:30

ah is that how it works

borkdude18:05:43

@U66G3SGP5 I have a branch which is very close to this, I think

roklenarcic18:05:00

That;s how I would approach it at least

borkdude18:05:54

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

borkdude18:05:55

but I guess we can meet people where they are coming from jinja etc

roklenarcic18:05:52

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

borkdude18:05:36

I was mostly working on this from the angle of "is it possible", I wasn't actually interested in any specific solution