[Bese-devel] <:css macro

Evrim ULU evrim at core.gen.tr
Sat Jan 20 14:02:28 UTC 2007


Hi,

I've written a small css macro for ucw+, i wonder if anybody has already
done the same thing. There is one inside parenscript but it does not
allow cascading. I may merge it to _dev if requested.

(in-package :it.bese.ucw)

(defvar *current-selected* nil)
(deftag-macro <:css (selectors &allow-other-attributes others &body body)
  `(let ((*current-selected* (if *current-selected*
                 (reduce #'(lambda (acc item)
                         (nconc acc                           
                            (mapcar #'(lambda (current)
                                (js::string-join (list current item) " "))
                                *current-selected*)))
                     (list ,@(ensure-list selectors))
                     :initial-value nil)
                 (list ,@(ensure-list selectors)))))
     (<:ai
      (format nil "~A {~%~A};~%~%"
          (js::string-join *current-selected* ", ")
          (reduce #'(lambda (acc item)
              (if (keywordp item)
                  (concatenate 'string acc " " (string-downcase (string
item)) ":")
                  (concatenate 'string acc " " item ";" ~%)))
              (list , at others)
              :initial-value nil)))
     , at body))

;; Test
;; (<:css ("div.abc" "div.def")
;;        :def "gef"
;;        :color "#000"
;;        (<:css ("a:hover" "a:active" "a:link")
;;           :abc "def"))

;; div.abc, div.def {
;;  def: gef;
;;  color: #000;
;; };

;; div.abc a:hover, div.def a:hover, div.abc a:active, div.def a:active,
div.abc a:link, div.def a:link {
;;  abc: def;
;; };


thanks.
evrim.




More information about the bese-devel mailing list