rum

jf 2024-09-30T14:34:08.603949Z

I’m trying to figure out how to create attributes that start with certain special characters: • a colon like one might for https://alpinejs.dev/directives/bind#shorthand-syntax (`<div :class="open ? '' : 'hidden'"> … </div>`). [:div {::class "…"}] wouldnt work, because the double-colon does auto-resolution • an @ (similarly also because of alpine.js): (`[:div {:@mouseenter="hello"} ...]` does not work, and the attribute gets dropped) How do I generate these attributes with rum?

Niki 2024-10-01T09:27:42.306869Z

If it works, it’s valid :)

jf 2024-10-01T09:29:03.540549Z

sure. I'm just hoping this "fix" does not go away!

jf 2024-10-01T10:00:26.062109Z

from my quick reading of https://github.com/tonsky/rum/blob/1e1fb15c65b80c4962288fbbbab0610e0daa3250/src/rum/server_render.clj#L318, it would appear that this fix should be fine. If render-attr! is what is used to render an attribute, the actual "attribute" that gets generated is something passed through https://github.com/tonsky/rum/blob/1e1fb15c65b80c4962288fbbbab0610e0daa3250/src/rum/server_render.clj#L189-L193, which ends up calling name on it. So if you use a string as the attribute name already, it's preserved.

jf 2024-10-01T12:58:25.262409Z

oh hey @tonsky, I just realized you're http://github.com/tonsky... Thank you for replying; I will take this as the string form being valid then. Note though that I have filed https://github.com/tonsky/rum/issues/265; even if specifying an attribute as a string is ok, it should at least be noted in the README as well.

jf 2024-09-30T15:25:02.055079Z

hm, on a hunch, I decided to just use a string instead of a keyword for the attribute name, and that seems to work. I don't see it in the README though, so... is this a valid fix? [:div {":class" "open ? '' : 'hidden'" "@mouseenter" "hello"} ...]

👍 1