Fork me on GitHub
#biff
<
2023-11-22
>
Olav Fosse01:11:51

Submitted first biff pr 🎉

Jacob O'Bryant01:11:57

nice! I'll take a look sometime this week

👍 2
macrobartfast05:11:12

I'm using ApexCharts inside of Biff after converting them to hiccup. The chart values are supplied by js. I could include the js from a file with the values baked in but I need to fetch them on the fly from the db. How do I create a function that returns a [:script ...] tag with the modified js? https://flowbite.com/docs/plugins/charts/

Jacob O'Bryant05:11:06

in general what I tend to do for this kind of stuff is I serialize the data to json and store it on an element attribute, then have the js read it from the attribute. so for the rendering part you'd have something like [div#chart {:data-chart-contents (cheshire/generate-string ...)}]

Jacob O'Bryant05:11:05

with hyperscript you can also do something like :_ "init call renderChart(this)", then define a renderChart js function that looks up the data-chart-contents attribute on the element that gets passed in

macrobartfast05:11:01

ok. grokking. like molasses.

macrobartfast05:11:58

btw, had started down string-interpolation-hell with

(defn dynajs [x]
  [:script (str "alert('Hello, " x " world!');")])

;; (dynajs "cruel")
but of course the single quotes behaved badly on the page.

Jacob O'Bryant05:11:58

ha yeah, that's why I like just putting the json on an attribute, no need to deal with escaping anything yourself

macrobartfast07:11:05

That worked perfectly.