Skip to content

Commit

Permalink
more clj-html oriented generation of tag names
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Mikulicic committed Mar 29, 2010
1 parent 84187d5 commit d123c1b
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/haml_macro/core.clj
Expand Up @@ -3,24 +3,21 @@

(def newlinep (one-of "\n"))

(def anyChar (not-char \newline))

(defn prefixed [ch p]
(>> (is-char ch) p))

(def tagName (prefixed \% baseIdentifier))
(def idName (prefixed \# baseIdentifier))
(def className (prefixed \. baseIdentifier))
(def anyChar (not-char \newline))

(def tagPrefix (one-of "%#."))
(def tagChar (either letter digit (one-of "-_") tagPrefix))
(def tagName (let-bind [prefix tagPrefix
rest (many1 tagChar)]
(let [autoTag (if (not= \% prefix) "%div")]
(result (keyword (apply str autoTag prefix rest))))))

(def tag (let-bind [t (optional tagName)
i (optional idName)
c (many className)
(def tag (let-bind [t tagName
b (optional (>> space text))]
(let [cc (if (empty? c) nil c)
tn (if (nil? t) "div" t)]
(if (every? nil? [t i cc])
fail
(result [:tag tn i c b])))))
(result [:tag t (second b)])))

(def text (>>== (many anyChar) #(vector :text (apply str %))))

Expand Down

0 comments on commit d123c1b

Please sign in to comment.