PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/src/jsown.lisp

http://github.com/sykopomp/chillax
Lisp | 29 lines | 24 code | 5 blank | 0 comment | 1 complexity | cb78455ea1c51446a0c79e39893975e2 MD5 | raw file
 1(defpackage #:chillax.jsown
 2  (:use :cl :chillax.core)
 3  (:export :jsown-server :call-with-key-container :with-key-container))
 4(in-package :chillax.jsown)
 5
 6(defclass jsown-server (standard-server)
 7  ()
 8  (:documentation
 9   "JSOWN-SERVERs use JSOWN's JSON parser/encoder to automatically translate content going to/coming
10   from the associated CouchDB server."))
11
12(defmethod data->json ((server jsown-server) data &key)
13  (jsown:to-json data))
14
15(defvar *key-container* nil)
16(defun call-with-key-container (function container)
17  "Calls FUNCTION, which require zero arguments, in a context where CONTAINER will be used for
18jsown:parse-with-container."
19  (let ((*key-container* container))
20    (funcall function)))
21(defmacro with-key-container ((container) &body body)
22  "Convenience macro for call-with-key-container."
23  `(call-with-key-container (lambda () ,@body) ,container))
24
25(defmethod json->data ((server jsown-server) json &key)
26  (if *key-container*
27      (jsown:parse-with-container json *key-container*)
28      (jsown:parse json)))
29