Devcards aims to provide a visual REPL experience for ClojureScript
mmeix 2016-03-28T16:24:13.000073Z

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.

mmeix 2016-03-28T16:25:39.000075Z

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

mmeix 2016-03-28T16:27:43.000076Z

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

anmonteiro 2016-03-28T16:28:23.000077Z

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

mmeix 2016-03-28T16:28:41.000079Z

ah ...

mmeix 2016-03-28T16:28:48.000080Z


anmonteiro 2016-03-28T16:29:09.000082Z

' = your backticks

mmeix 2016-03-28T16:29:16.000083Z


mmeix 2016-03-28T16:29:24.000084Z


anmonteiro 2016-03-28T16:29:26.000085Z

for slack formatting

mmeix 2016-03-28T16:34:21.000086Z

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

anmonteiro 2016-03-28T16:35:37.000087Z

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

anmonteiro 2016-03-28T16:36:08.000088Z

depending on what you want to display

anmonteiro 2016-03-28T16:36:30.000089Z

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

mmeix 2016-03-28T16:36:59.000090Z

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

mmeix 2016-03-28T16:37:50.000091Z

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

mmeix 2016-03-28T16:38:49.000092Z

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

mmeix 2016-03-28T16:39:26.000093Z

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

anmonteiro 2016-03-28T16:40:52.000094Z

(defmacro code-demo
  [cardname svg-height code]
  `(defcard-rg ~cardname
     (str "'''" ~code "'''")
    [:svg {:width "100%" :height ~svg-height}

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

anmonteiro 2016-03-28T16:40:55.000095Z

seems OK to me?

mmeix 2016-03-28T16:41:20.000096Z

ok, let me try this

mmeix 2016-03-28T16:51:08.000098Z

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

anmonteiro 2016-03-28T16:51:45.000100Z

it shouldn't, if they are in a string

mmeix 2016-03-28T16:52:21.000101Z

I get a card saying

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

mmeix 2016-03-28T16:53:42.000104Z

will try more - thanks for hints!

anmonteiro 2016-03-28T16:53:48.000105Z

isn't that what you wanted?

mmeix 2016-03-28T16:54:13.000106Z


mmeix 2016-03-28T16:55:44.000108Z

this is what I want to accomplish

anmonteiro 2016-03-28T16:56:01.000109Z

I think I know what's the problem

mmeix 2016-03-28T16:56:09.000111Z

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

anmonteiro 2016-03-28T16:56:21.000112Z

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

mmeix 2016-03-28T16:56:37.000113Z


anmonteiro 2016-03-28T16:56:38.000114Z

probably needs the line breaks

mmeix 2016-03-28T16:58:56.000115Z

alas, no

mmeix 2016-03-28T16:59:51.000116Z

ok, no high priority, was just a nice idea

mmeix 2016-03-28T16:59:54.000117Z


anmonteiro 2016-03-28T17:00:00.000118Z

doesn't seem right

anmonteiro 2016-03-28T17:00:09.000119Z

as in, it should work

mmeix 2016-03-28T17:01:15.000120Z

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

anmonteiro 2016-03-28T17:02:17.000121Z

shouldn't be

mmeix 2016-03-28T17:02:22.000122Z

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

mmeix 2016-03-28T17:03:20.000123Z

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

anmonteiro 2016-03-28T17:03:39.000124Z

not really

mmeix 2016-03-28T17:03:42.000125Z