This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-06
Channels
- # admin-announcements (1)
- # announcements (32)
- # babashka (38)
- # beginners (91)
- # braveandtrue (1)
- # calva (1)
- # cider (9)
- # cljsrn (19)
- # clojure (129)
- # clojure-bay-area (3)
- # clojure-europe (24)
- # clojure-italy (1)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-spec (10)
- # clojure-uk (24)
- # clojurescript (14)
- # community-development (7)
- # conjure (16)
- # cursive (3)
- # datomic (20)
- # defnpodcast (4)
- # emacs (11)
- # figwheel (2)
- # fulcro (5)
- # helix (6)
- # integrant (3)
- # jackdaw (5)
- # java (6)
- # jobs (1)
- # kaocha (13)
- # lsp (8)
- # malli (29)
- # meander (2)
- # off-topic (120)
- # pathom (3)
- # podcasts-discuss (6)
- # portal (6)
- # re-frame (27)
- # reagent (5)
- # releases (4)
- # remote-jobs (6)
- # rewrite-clj (9)
- # shadow-cljs (108)
- # xtdb (5)
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.
5 years old 🙂
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
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 @U04V15CAJ! 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
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
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
@U66G3SGP5 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
@U66G3SGP5 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