diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-02 15:33:15 +0100 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-03-02 15:33:15 +0100 |
commit | 12f3796c273ae5e0486d4168949f2ffd1767ba39 (patch) | |
tree | 755721d52c8aa3f30f6759fb59f1bb0244938d41 | |
parent | e20d123922ead7c2f0614da519dd5841310fe87a (diff) |
Permit @ as a variable as well as a section specifier.
-rw-r--r-- | json-template.lisp | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/json-template.lisp b/json-template.lisp index 237d627..59f2aed 100644 --- a/json-template.lisp +++ b/json-template.lisp @@ -124,6 +124,11 @@ (with-output-to-string (out) (expand-template-to-stream template context out))) +(defun getcontext (context key) + (if (string= key "@") + context + (getf context (intern (string-upcase (string key)) '#:keyword) nil))) + (defun expand-template-to-stream (template context stream) (dolist (thing template) (ecase (first thing) @@ -131,10 +136,7 @@ (write-string (second thing) stream)) (:variable (destructuring-bind (variable filter) (cdr thing) - (let ((value (getf context - (intern (string-upcase variable) - '#:keyword) - nil))) + (let ((value (getcontext context variable))) (format stream "~A" (if filter (funcall (cdr (assoc filter *template-filters*)) @@ -142,16 +144,13 @@ value))))) (:section (destructuring-bind (section branch alternative) (cdr thing) - (let ((value (getf context (intern (string-upcase section) '#:keyword) nil))) + (let ((value (getcontext context section))) (expand-template-to-stream (if value branch alternative) value stream)))) (:repeated-section (destructuring-bind (section branch alternative) (cdr thing) - (let ((value (if (string= section "@") - context - (getf context (intern (string-upcase section) '#:keyword) - nil)))) + (let ((value (getcontext context section))) (if value (mapc (lambda (ctx) (expand-template-to-stream branch ctx stream)) |