-
-
Save priyadarshan/c1496e318d343fde043b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; http://kinokoru.jp/archives/840 | |
(defmacro css (name elems) | |
`(with-open-file | |
(*standard-output* ,(string-downcase name) :direction :output :if-exists :supersede) | |
,@(loop for (elem attrs) in elems | |
collect | |
`(format t "~a {~%" ,elem) | |
append | |
(mapcar (lambda (attr) | |
(destructuring-bind (name val) | |
attr | |
`(format t "~2T~(~a~): ~a~%" ',name ,val))) | |
attrs) | |
collect | |
`(format t "}~2%")) | |
t)) | |
;; (macroexpand-1 | |
;; '(css | |
;; test.css | |
;; ((".hoge" | |
;; ((background "#F00") | |
;; (border-radius "5px"))) | |
;; ("#fuga" | |
;; ((background "#009") | |
;; (color "#FFF")))))) | |
;; => | |
;; (WITH-OPEN-FILE | |
;; (*STANDARD-OUTPUT* "test.css" :DIRECTION :OUTPUT :IF-EXISTS :SUPERSEDE) | |
;; (FORMAT T "~a {~%" ".hoge") | |
;; (FORMAT T "~2T~(~a~): ~a~%" 'BACKGROUND "#F00") | |
;; (FORMAT T "~2T~(~a~): ~a~%" 'BORDER-RADIUS "5px") | |
;; (FORMAT T "}~2%") | |
;; (FORMAT T "~a {~%" "#fuga") | |
;; (FORMAT T "~2T~(~a~): ~a~%" 'BACKGROUND "#009") | |
;; (FORMAT T "~2T~(~a~): ~a~%" 'COLOR "#FFF") | |
;; (FORMAT T "}~2%") | |
;; T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment