Permalink
Browse files

handle indentation

  • Loading branch information...
1 parent 40762c2 commit 45f6d76b7bec2b08d90f3a7abd6e9855e4d2f2fc @mmikulicic committed Mar 29, 2010
Showing with 27 additions and 6 deletions.
  1. +15 −0 example.haml
  2. +1 −0 project.clj
  3. +11 −6 src/haml_macro/core.clj
View
@@ -0,0 +1,15 @@
+#content
+ %span welcome
+ %strong man
+ #introduction
+ intro
+ second
+%table
+ %tr
+ %td First
+ %td Last
+ %tr
+ %td Marko
+ %td Mikulicic
+ficone
+blu
View
@@ -3,4 +3,5 @@
:dependencies [[org.clojure/clojure "1.1.0"]
[org.clojure/clojure-contrib "1.1.0"]
[clarsec "0.0.1-SNAPSHOT"]
+ [org.clojars.liebke/compojure "0.3.1-master"]
])
View
@@ -1,5 +1,6 @@
(ns haml-macro.core
- (:use [eu.dnetlib.clojure clarsec monad]))
+ (:use [eu.dnetlib.clojure clarsec monad])
+ (:require compojure))
(declare tag)
@@ -22,9 +23,10 @@
(def anyChar (not-char \newline))
-(def text (>>== (many anyChar) #(vector :text (apply str %))))
+(defn text [l] (>> (repeated l sspace) (>>== (many anyChar) #(apply str %))))
+(defn textnl [l] (>>== (text l) #(str % "\n")))
-(defn statement [l] (delay (either (tag l) text)))
+(defn statement [l] (delay (either (tag l) (textnl l))))
(def tagPrefix (one-of "%#."))
(def tagChar (either letter digit (one-of "-_") tagPrefix))
@@ -34,13 +36,13 @@
(result (keyword (apply str autoTag (if (not= \% prefix) prefix) rest))))))
(defn make-compojure-tag [t inline body]
- (apply vector (filter not-nil? (apply vector t (second inline) body))))
+ (apply vector (filter not-nil? (apply vector t inline body))))
(defn tag [l]
(let [nl (+ 2 l)]
(let-bind [t tagName
- inline (optional (>> sspace text))
- body (optional (many1 (indented nl (tag nl))))]
+ inline (optional (>> sspace (text 0)))
+ body (optional (many1 (indented nl (statement nl))))]
(result (make-compojure-tag t inline body)))))
@@ -56,3 +58,6 @@
(defn haml-file [file]
(haml-str (slurp file)))
+
+(defn haml-file-html [file]
+ (apply str (map compojure/html (haml-file file))))

0 comments on commit 45f6d76

Please sign in to comment.