Author: hhubner Date: 2007-10-20 13:22:25 -0400 (Sat, 20 Oct 2007) New Revision: 2242
Modified: branches/bos/bknr/src/packages.lisp branches/bos/bknr/src/utils/utils.lisp branches/bos/bknr/src/web/templates.lisp Log: Template expander needed for new BOS version.
Modified: branches/bos/bknr/src/packages.lisp =================================================================== --- branches/bos/bknr/src/packages.lisp 2007-10-20 09:40:58 UTC (rev 2241) +++ branches/bos/bknr/src/packages.lisp 2007-10-20 17:22:25 UTC (rev 2242) @@ -268,6 +268,7 @@
;; templates #:expand-template + #:expand-variables #:get-template-var #:with-template-vars #:emit-template-node
Modified: branches/bos/bknr/src/utils/utils.lisp =================================================================== --- branches/bos/bknr/src/utils/utils.lisp 2007-10-20 09:40:58 UTC (rev 2241) +++ branches/bos/bknr/src/utils/utils.lisp 2007-10-20 17:22:25 UTC (rev 2242) @@ -514,7 +514,7 @@ (with-open-file (s pathname :element-type '(unsigned-byte 8)) (let ((result (make-array (file-length s) :element-type '(unsigned-byte 8)))) - (read-sequence result s ) + (read-sequence result s) result)))
(defun class-subclasses (class)
Modified: branches/bos/bknr/src/web/templates.lisp =================================================================== --- branches/bos/bknr/src/web/templates.lisp 2007-10-20 09:40:58 UTC (rev 2241) +++ branches/bos/bknr/src/web/templates.lisp 2007-10-20 17:22:25 UTC (rev 2242) @@ -85,7 +85,7 @@ ,(intern (symbol-name var) :keyword))))) ,@body))
-(defun expand-variables (string) +(defun expand-variables (string lookup-variable) (if (find #$ string) (regex-replace-all #?r"$(([*_-\w]+))" string @@ -94,7 +94,7 @@ (let* ((var (make-keyword-from-string (subseq target-string (aref reg-starts 0) (aref reg-ends 0)))) - (val (get-template-var var))) + (val (funcall lookup-variable var))) (cond ((stringp val) val) ((null val) "") @@ -128,7 +128,7 @@
(defun emit-template-node (node) (if (stringp node) - (sax:characters *html-sink* (expand-variables node)) + (sax:characters *html-sink* (expand-variables node #'get-template-var)) (let* ((name (node-name node)) (ns (node-ns node)) (children (node-children node)) @@ -140,12 +140,12 @@ (apply (find-tag-function *template-expander* name ns) (append (loop for (key name) in (remove-if #'(lambda (attr) (scan "^xmlns" (car attr))) attrs) collect (make-keyword-from-string key) - collect (expand-variables name)) + collect (expand-variables name #'get-template-var)) (when children (list :children children))))) (t (sax:start-element *html-sink* nil nil name - (xmls-attributes-to-sax #'expand-variables attrs)) + (xmls-attributes-to-sax (lambda (var) (expand-variables var #'get-template-var)) attrs)) (dolist (child children) (emit-template-node child)) (sax:end-element *html-sink* nil nil name))))))