aboutsummaryrefslogtreecommitdiff
path: root/json-template.lisp
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-03-19 13:02:59 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-03-19 13:02:59 +0100
commitd036fade731faf57f45acb2fe0129ef0e8207342 (patch)
tree45401a626668d225313233e47be4b8fd8d21b4bb /json-template.lisp
parent8a862ae2f15d1432898ff38ec1c6be5e0eeaab1d (diff)
Add class TEMPLATE for improved encapsulation.
Diffstat (limited to 'json-template.lisp')
-rw-r--r--json-template.lisp25
1 files changed, 17 insertions, 8 deletions
diff --git a/json-template.lisp b/json-template.lisp
index ab7b04d..0abd91b 100644
--- a/json-template.lisp
+++ b/json-template.lisp
@@ -24,6 +24,10 @@
(in-package #:json-template)
+(defclass template ()
+ ((things :initarg :things :accessor template-things)))
+
+
(defun tokenize-template-string (string)
(loop with in-command-p = nil
with skip-newline-p = nil
@@ -48,7 +52,8 @@
until (null terminator)))
(defun parse-template-string (string)
- (parse-raw-tokens (tokenize-template-string string)))
+ (make-instance 'template
+ :things (parse-raw-tokens (tokenize-template-string string))))
(defun parse-directive (string)
(let* ((space1 (position #\Space string))
@@ -165,7 +170,7 @@
(lookup-in-stack contexts)))
-(defun expand-template-to-stream (template contexts stream)
+(defun expand-things-to-stream (template contexts stream)
(dolist (thing template)
(ecase (first thing)
(:text
@@ -182,9 +187,9 @@
(:section
(destructuring-bind (section branch alternative) (cdr thing)
(let ((value (lookup-context contexts section)))
- (expand-template-to-stream (if value branch alternative)
- (cons value contexts)
- stream))))
+ (expand-things-to-stream (if value branch alternative)
+ (cons value contexts)
+ stream))))
(:repeated-section
(destructuring-bind (section branch alternative separator) (cdr thing)
(let ((value (lookup-context contexts section)))
@@ -193,9 +198,13 @@
(map nil
(lambda (ctx)
(unless first-loop
- (expand-template-to-stream separator contexts stream))
- (expand-template-to-stream branch (cons ctx contexts) stream)
+ (expand-things-to-stream separator contexts stream))
+ (expand-things-to-stream branch (cons ctx contexts) stream)
(setq first-loop nil))
value))
- (expand-template-to-stream alternative contexts stream))))))))
+ (expand-things-to-stream alternative contexts stream))))))))
+
+
+(defun expand-template-to-stream (template contexts stream)
+ (expand-things-to-stream (template-things template) contexts stream))