I'm trying to write a macro to demonstrate svg-code in a defcard-rg
. Being a macro noob I have a problem: how to insert the cord into the description-string.
the lower part executes the supplied code correctly, but I'm not sure how to display the code
in the description
usage: (codedemo example 120 [:circle {:cx 12 :cy 20 :r 7}])
@mmeix: (str " '''" ~code "'''")
ah ...
trying
'
= your backticks
ok
tricky
for slack formatting
no, that doesn't work, alas ...
@mmeix: you probably want to wrap ~code
in a sablono html
macro?
depending on what you want to display
or you just want to present the code as a string?
in the description: the code as a string, and then underneath the executed code
if I remove the description part, the code gets executed correctly
so no need for sablono (it_s in a defcard-rg
, so I guess this the correct environment
it's just the building of the description string with the inserted code
(defmacro code-demo
[cardname svg-height code]
`(defcard-rg ~cardname
(str "'''" ~code "'''")
[:svg {:width "100%" :height ~svg-height}
~code]))
(macroexpand '(code-demo example 120 [:circle {:cx 12 :cy 20 :r 7}]))
;; =>
(cellophane.dom-test/defcard-rg example
(clojure.core/str "'''" [:circle {:cx 12, :cy 20, :r 7}] "'''")
[:svg {:width "100%", :height 120} [:circle {:cx 12, :cy 20, :r 7}]])
seems OK to me?
ok, let me try this
it seems, that the usage of backticks in devcard
's markdown format for description strings collides somehow with using them in a macro ...
it shouldn't, if they are in a string
I get a card saying
"
[:circle {:cx 12, :cy 20, :r 7}] "
will try more - thanks for hints!
isn't that what you wanted?
no
this is what I want to accomplish
I think I know what's the problem
in this case I'm using a couple of functions, which create svg
use (str "'''\n" ~code "\n'''")
trying
probably needs the line breaks
alas, no
ok, no high priority, was just a nice idea
:simple_smile:
doesn't seem right
as in, it should work
maybe it's the double usage of backticks, maybe they are not eval'd correctly in this case, sort of a corner case
shouldn't be
a macro calling a macro doesn't have special requirements, or does it?
(I'm really just starting with macros ...)
not really
ok