forked from kennytilton/qooxlisp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utilities.lisp
60 lines (49 loc) · 1.87 KB
/
utilities.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(in-package :cqx)
(defun k-word (s)
(when s (if (consp s) (mapcar 'k-word s)
(intern (string-upcase s) :keyword))))
(defmacro whtml (&body body)
`(catch 'excl::printer-error
(net.html.generator:html ,@body)))
(defun req-val (req tag)
(net.aserve:request-query-value tag req))
(defmacro with-plain-text-response ((req ent) &body body)
`(prog1 nil
(net.aserve:with-http-response (,req ,ent :content-type "text/plain")
(net.aserve:with-http-body (,req ,ent)
(let* ((ws (net.aserve:websession-from-req ,req)))
(declare (ignorable ws ns))
,@body)))))
(defmacro with-html-response ((req ent) &body body)
`(prog1 nil
(net.aserve:with-http-response (,req ,ent :content-type "text/html")
(net.aserve:with-http-body (,req ,ent)
(let ((ws (net.aserve:websession-from-req ,req)))
(declare (ignorable ws))
,@body)))))
(defmacro with-js-response ((req ent) &body body)
`(prog1 nil
(net.aserve:with-http-response (,req ,ent :content-type "text/javascript")
(net.aserve:with-http-body (,req ,ent)
(let ((ws (net.aserve:websession-from-req ,req)))
(declare (ignorable ws))
,@body)))))
(defmacro with-json-response ((req ent) &body body)
`(prog1 nil
(net.aserve:with-http-response (,req ,ent :content-type "application/json")
(net.aserve:with-http-body (,req ,ent)
(let ((ws (net.aserve:websession-from-req ,req)))
(declare (ignorable ws))
,@body)))))
(defmacro ml$ (&rest x)
(let ((s (gensym)))
`(with-output-to-string (,s)
(net.html.generator:html-stream ,s
,@x))))
(defun js-prep (&rest lists)
(format nil "(~{~a~})"
(loop for list in lists
collecting (format nil "(~{~(~a~)~^ {~a}~})" list))))
(defun json$ (x) (json:encode-json-to-string x))
#+test
(json$ (list (cons :one 1)))