- Timestamp:
- 02/05/2008 04:15:19 AM (18 years ago)
- branch-nick:
- tags
- revision id:
- dsowen@fugue88.ws-20080205041519-08a87o61m5kakcbs
- File:
-
- 1 edited
-
main/tags.lisp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
main/tags.lisp
r1 r2 1 1 (defpackage #:dso-tags 2 (:use #:cl)) 2 (:use #:cl) 3 (:export #:expand-tag #:render-tag #:render #:do-body)) 3 4 4 5 (in-package #:dso-tags) … … 10 11 11 12 13 (defgeneric expand-tag (tag body &key &allow-other-keys) 14 (:method (tag body &key))) 15 12 16 (defgeneric render-tag (tag body &key &allow-other-keys) 13 "Renders the tag named TAG with the given BODY and keyword-arguments as 14 attributes.") 17 (:documentation 18 "Renders the tag named TAG with the given BODY and keyword-arguments as 19 attributes.")) 15 20 16 (defmethod render ((tag list)) 17 (destructuring-bind (name &rest b) tag 21 22 23 (defun break-tag (tree) 24 (destructuring-bind (name &rest b) tree 18 25 (let (args) 19 26 (do () ((not (keywordp (first b)))) 20 27 (push (pop b) args) 21 28 (push (pop b) args)) 22 (apply 'render-tag name b (nreverse args))))) 23 24 (defmethod render ((text string)) 25 (format t "~A" text)) 29 (values name b (nreverse args))))) 26 30 27 31 (defun do-body (body) 28 (dolist (item body) 29 (render item))) 32 (do ((item #1=(pop body) #1#)) 33 ((null item)) 34 (etypecase item 35 (string 36 (format t "~A" item)) 37 (list 38 (multiple-value-bind (tag-name tag-body tag-attrs) (break-tag item) 39 (let ((expanded (apply 'expand-tag tag-name tag-body tag-attrs))) 40 (if expanded 41 (setf body (nconc expanded body)) 42 (apply 'render-tag tag-name tag-body tag-attrs)))))))) 30 43 31 44 … … 45 58 (defmethod render-tag (tag body &rest args &key &allow-other-keys) 46 59 (render-simple-tag tag body args)) 47 48 (defmethod render-tag ((tag (eql 'when)) body &key cond)49 (when (eval cond)50 (do-body body)))51 52 (defmethod render-tag ((tag (eql 'page)) body &key title)53 (do-body54 `((html55 ,@(when title `((head (title ,title))))56 (body ,@body)))))
Note: See TracChangeset
for help on using the changeset viewer.
