Permalink
Browse files

implement loops and other ways to use a haml block inside a clojure s…

…ubexpression

 - (for [x [1 2 3 4]])
    %p Wow:
      = x
  • Loading branch information...
mmikulicic committed Apr 12, 2010
1 parent 30f76d5 commit bb837be0125b1c2eaeaa982debc25ba3102047d9
Showing with 19 additions and 2 deletions.
  1. +10 −0 README.md
  2. +9 −2 src/haml_macro/core.clj
View
@@ -11,6 +11,16 @@ USAGE:
(:use compojure)
(:use haml-macro))
+ (defroutes main-routes
+ (GET "/hello/:first/:last" []
+ (haml "index"))
+
+ (def app
+ (wrap-reload #'main-routes '(authfile.gui)))
+
+ (run-jetty app {:port 4000}))
+
+
(defroutes greeter
(GET "/hello/:first/:last" (haml "example")))
View
@@ -1,7 +1,7 @@
(ns haml-macro.core
(:use [eu.dnetlib.clojure clarsec monad]))
-(declare tag)
+(declare tag clojureStatement)
;; general helpers
@@ -53,7 +53,7 @@
code (many1 anyChar)]
(result (read (java.io.PushbackReader. (java.io.StringReader. (apply str code)))))))
-(defn statement [l] (delay (either expression (tag l) (textnl l))))
+(defn statement [l] (delay (either expression (clojureStatement l) (tag l) (textnl l))))
(def tagPrefix (one-of "%#."))
(def tagChar (either letter digit (one-of "-_") tagPrefix))
@@ -107,6 +107,13 @@
rest (optional (tagBody l))]
(result (make-compojure-tag t attrs inline rest))))
+(defn clojureStatement [l]
+ (let-bind [_ (string "-")
+ _ (many sspace)
+ code (many1 anyChar)
+ rest (optional (tagBody l))]
+ (result (concat (read (java.io.PushbackReader. (java.io.StringReader. (apply str code)))) rest))))
+
(defn statements [l] (followedBy (sepBy1 (statement l) newlinep) (optional newlinep)))

0 comments on commit bb837be

Please sign in to comment.