Fork me on GitHub
#devcards
<
2016-03-28
>
mmeix16:03:13

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.

mmeix16:03:39

the lower part executes the supplied code correctly, but I'm not sure how to display the codein the description

mmeix16:03:43

usage: (codedemo example 120 [:circle {:cx 12 :cy 20 :r 7}])

anmonteiro16:03:23

@mmeix: (str " '''" ~code "'''")

anmonteiro16:03:09

' = your backticks

anmonteiro16:03:26

for slack formatting

mmeix16:03:21

no, that doesn't work, alas ...

anmonteiro16:03:37

@mmeix: you probably want to wrap ~code in a sablono html macro?

anmonteiro16:03:08

depending on what you want to display

anmonteiro16:03:30

or you just want to present the code as a string?

mmeix16:03:59

in the description: the code as a string, and then underneath the executed code

mmeix16:03:50

if I remove the description part, the code gets executed correctly

mmeix16:03:49

so no need for sablono (it_s in a defcard-rg, so I guess this the correct environment

mmeix16:03:26

it's just the building of the description string with the inserted code

anmonteiro16:03:52

(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}]])

anmonteiro16:03:55

seems OK to me?

mmeix16:03:20

ok, let me try this

mmeix16:03:08

it seems, that the usage of backticks in devcard's markdown format for description strings collides somehow with using them in a macro ...

anmonteiro16:03:45

it shouldn't, if they are in a string

mmeix16:03:21

I get a card saying

" 
[:circle {:cx 12, :cy 20, :r 7}]
"  

mmeix16:03:42

will try more - thanks for hints!

anmonteiro16:03:48

isn't that what you wanted?

mmeix16:03:44

this is what I want to accomplish

anmonteiro16:03:01

I think I know what's the problem

mmeix16:03:09

in this case I'm using a couple of functions, which create svg

anmonteiro16:03:21

use (str "'''\n" ~code "\n'''")

anmonteiro16:03:38

probably needs the line breaks

mmeix16:03:51

ok, no high priority, was just a nice idea

anmonteiro17:03:00

doesn't seem right

anmonteiro17:03:09

as in, it should work

mmeix17:03:15

maybe it's the double usage of backticks, maybe they are not eval'd correctly in this case, sort of a corner case

anmonteiro17:03:17

shouldn't be

mmeix17:03:22

a macro calling a macro doesn't have special requirements, or does it?

mmeix17:03:20

(I'm really just starting with macros ...)