Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented jsown-server for jsown-based chillaxing.

  • Loading branch information...
commit 86d2b30993b04349859552fecca02497abcf892c 1 parent 15e1e27
@zkat authored
Showing with 65 additions and 1 deletion.
  1. +25 −1 README.md
  2. +11 −0 chillax.jsown.asd
  3. +29 −0 src/jsown.lisp
View
26 README.md
@@ -51,6 +51,7 @@ Chillax includes several systems:
* chillax.core.asd - Core API and protocols for servers, databases, documents, and
design-docs.
* chillax.yason.asd - Implementation of the server protocol using Yason's JSON parser.
+* chillax.jsown.asd - Implementation of the server protocol using JSOWN's JSON parser.
* chillax.utils.asd - Some handy utilities.
* chillax.view-server.asd - The Chillax view server. This only depends on chillax.utils.
@@ -420,6 +421,29 @@ Self-explanatory readers:
* :parse-object-key-fun - Function to process object keys with. (default: #'cl:identity)
+*[standard class]* `jsown-server`
+
+ JSOWN-SERVERs use JSOWN's JSON parser/encoder to automatically translate content going to/coming
+ from the associated CouchDB server.
+
+ JSOWN-SERVER is a subclass of STANDARD-SERVER, and the same initargs apply.
+
+
+*[function]* `call-with-key-container`
+
+ This function is part of the chillax.jsown package.
+
+ Calls FUNCTION, which require zero arguments, in a context where CONTAINER will be used for
+ jsown:parse-with-container.
+
+
+*[macro]* `with-key-container`
+
+ This macro is part of the chillax.jsown package.
+
+ Convenience macro for call-with-key-container.
+
+
## Database Protocol
*[generic function]* `database-server database`
@@ -431,7 +455,7 @@ Self-explanatory readers:
Returns the URL-encoded name of the database, a string. Note that CouchDB accepts certain
characters in database names -only- if they are URL-encoded (such as #\/). It is up to individual
- implementations of DATABASE-NAME to implement this encoding."
+ implementations of DATABASE-NAME to implement this encoding.
### Included protocol implementation
View
11 chillax.jsown.asd
@@ -0,0 +1,11 @@
+(asdf:defsystem chillax.jsown
+ :description "CouchDB abstraction layer - Implementation of protocols using JSOWN."
+ :maintainer "Josh Marchán <sykopomp@sykosomatic.org>"
+ :author "Josh Marchán <sykopomp@sykosomatic.org>"
+ :licence "MIT"
+ :depends-on (chillax.core jsown)
+ :serial t
+ :components
+ ((:module src
+ :components
+ ((:file "jsown")))))
View
29 src/jsown.lisp
@@ -0,0 +1,29 @@
+(defpackage #:chillax.jsown
+ (:use :cl :chillax.core)
+ (:export :jsown-server :call-with-key-container :with-key-container))
+(in-package :chillax.jsown)
+
+(defclass jsown-server (standard-server)
+ ()
+ (:documentation
+ "JSOWN-SERVERs use JSOWN's JSON parser/encoder to automatically translate content going to/coming
+ from the associated CouchDB server."))
+
+(defmethod data->json ((server jsown-server) data &key)
+ (jsown:to-json data))
+
+(defvar *key-container* nil)
+(defun call-with-key-container (function container)
+ "Calls FUNCTION, which require zero arguments, in a context where CONTAINER will be used for
+jsown:parse-with-container."
+ (let ((*key-container* container))
+ (funcall function)))
+(defmacro with-key-container ((container) &body body)
+ "Convenience macro for call-with-key-container."
+ `(call-with-key-container (lambda () ,@body) ,container))
+
+(defmethod json->data ((server jsown-server) json &key)
+ (if *key-container*
+ (jsown:parse-with-container json *key-container*)
+ (jsown:parse json)))
+
Please sign in to comment.
Something went wrong with that request. Please try again.