/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. (defclass jsown-server (standard-server)
  6. ()
  7. (:documentation
  8. "JSOWN-SERVERs use JSOWN's JSON parser/encoder to automatically translate content going to/coming
  9. from the associated CouchDB server."))
  10. (defmethod data->json ((server jsown-server) data &key)
  11. (jsown:to-json data))
  12. (defvar *key-container* nil)
  13. (defun call-with-key-container (function container)
  14. "Calls FUNCTION, which require zero arguments, in a context where CONTAINER will be used for
  15. jsown:parse-with-container."
  16. (let ((*key-container* container))
  17. (funcall function)))
  18. (defmacro with-key-container ((container) &body body)
  19. "Convenience macro for call-with-key-container."
  20. `(call-with-key-container (lambda () ,@body) ,container))
  21. (defmethod json->data ((server jsown-server) json &key)
  22. (if *key-container*
  23. (jsown:parse-with-container json *key-container*)
  24. (jsown:parse json)))