Browse files

more clj-html oriented generation of tag names

  • Loading branch information...
1 parent 84187d5 commit d123c1be5accbccb33e5c71562af90c45f5d1aea @mmikulicic committed Mar 29, 2010
Showing with 10 additions and 13 deletions.
  1. +10 −13 src/haml_macro/core.clj
@@ -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 %))))

0 comments on commit d123c1b

Please sign in to comment.