-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.lisp
40 lines (31 loc) · 1.13 KB
/
util.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
(in-package :weblocks-cms)
(defun implode (glue-or-pieces &optional (pieces nil pieces-given-p))
(unless pieces-given-p
(return-from implode (implode "" glue-or-pieces)))
(format nil "~{~A~}"
(cdr (loop for i in pieces append
(list glue-or-pieces i)))))
(setf (fdefinition 'join) (fdefinition 'implode))
(defun htmlspecialchars (text)
(arnesi:escape-as-html text))
(defun strip-tags (text)
(labels ((get-node-text (dom)
"Recursive function for getting node text"
(if (dom:text-node-p dom)
(dom:node-value dom)
(join
(loop for i across (dom:child-nodes dom) collect (get-node-text i))))))
(htmlspecialchars
(get-node-text
(chtml:parse text (cxml-dom:make-dom-builder))))))
(defvar *models-package* :weblocks-cms)
(defun keyword->symbol (keyword)
(intern (string-upcase keyword) *models-package*))
(defun safe-parse-integer (number)
(if (not number)
0
(parse-integer number :junk-allowed t)))
(defun explode (delimiter string)
(ppcre:split
(ppcre:quote-meta-chars delimiter)
string))