css.lisp (957B)
1 (defpackage :rw.css 2 (:use :cl) 3 (:export :css 4 :style)) 5 6 (in-package :rw.css) 7 8 (defun style (form) 9 (loop 10 for (k v) on form by #'cddr 11 for i from 0 12 when v 13 do (flet ((out (x) 14 (typecase x 15 (symbol (format t "~(~a~)" x)) 16 (t (format t "~a" x))))) 17 (when (plusp i) 18 (write-char #\;)) 19 (out k) 20 (write-char #\:) 21 (out v)))) 22 23 ;;(style '(:one 1 :two 2 :three nil :four :hello)) 24 25 (defun css (form) 26 (dolist (x form) 27 (let ((style (with-output-to-string (*standard-output*) (style (cdr x))))) 28 (when style 29 (flet ((out (x) 30 (typecase x 31 (symbol (format t "~(~a~)" x)) 32 (t (format t "~a" x))))) 33 (out (car x)) 34 (write-char #\{) 35 (write-string style) 36 (write-char #\})))))) 37 38 ;;(css '((:pre :one 1 :two 2 :three nil :four :hello)))