Hey Stefan,

I wrote something much like this for the Om-Bootstrap doc site at om-bootstrap.herokuapp.com. I ended up putting all code examples into their own files, then slurping those up. The fun thing about the code below is that each example is executable, and actually runs on the om-bootstrap site.

Here's the Om code:

https://github.com/racehub/om-bootstrap/blob/develop/docs/src/cljs/om_bootstrap/docs/example.cljs

Then, I slurp up the code snippets from their respective files with a "slurp-example" macro:

https://github.com/racehub/om-bootstrap/blob/develop/docs/src/clj/om_bootstrap/macros.clj#L5

This lets me define examples like this:

https://github.com/racehub/om-bootstrap/blob/develop/docs/src/cljs/om_bootstrap/docs/components.cljs#L42

using the relative path under "dev/snippets". Here's the code that defines that linked example:

https://github.com/racehub/om-bootstrap/blob/develop/dev/snippets/button/types.cljs

Stefan Kamphausen <mailto:ska2...@gmail.com>
January 4, 2015 at 8:57 AM
Hi,


Currently, I am trying to write a presentation using ring and reveal.js. For the code samples, I'd like to write "real" clojure code, i.e. no strings or the like.

Then, I want to turn that into a suitable hiccup vector which will create the correct reveal.js/highlight.js syntax.

I wrote a trvial macro:

(defmacro example [& body]
  `[:pre
    [:code ~(apply str body)]])

The problem is, that it looses all formatting, because the Clojure reader already had its fun with the code. So,

(example
 "A string literal"
 (defn a-function [x y]
   ;; concat x and y as strings
   (str x y)))

macro-expands to

[:pre [:code "A string literal(defn a-function [x y] (str x y))"]]

which is pretty useless.

I already thought about using &form but this too has been read already.


Any ideas?


Kind regards,
stefan
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com <mailto:clojure+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
Sam Ritchie (@sritchie)
Paddleguru Co-Founder
703.863.8561
www.paddleguru.com <http://www.paddleguru.com/>
Twitter <http://twitter.com/paddleguru>// Facebook <http://facebook.com/paddleguru>

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to