Skip to content

Commit

Permalink
Add ability to execute code in blog entries
Browse files Browse the repository at this point in the history
  • Loading branch information
vii committed Jan 14, 2014
1 parent e4f47d8 commit dfc0b92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/blog/entry.lisp
Expand Up @@ -44,7 +44,7 @@
(title "Untitled")
time
expiry-time
paragraphs
body-function
score
score-update-time)

Expand Down Expand Up @@ -111,8 +111,7 @@

(my-defun entry story-ml ()
(<div :class "blog-entry-story"
(loop for p in (my paragraphs)
do (<p (output-raw-ml p)))))
(funcall (my body-function))))

(my-defun entry comments ()
(datastore-retrieve-indexed 'comment 'entry-index-name (my index-name)))
Expand Down Expand Up @@ -193,10 +192,24 @@
(setf (entry-channel-entry channel) me))))

(my-defun entry read-paragraphs-from-buffer (buffer)
(setf (my paragraphs)
(split-into-paragraphs
(match-replace-all buffer
("${static-base}" (byte-vector-cat (blog-static-base-url (my blog)) (my name)))))))
(cond ((if-match-bind ((* (space)) "(progn") buffer)
(setf (my body-function)
(compile (gensym (my name))
`(lambda ()
(with-ml-output
,(let ((*package* (find-package '#:tpd2.blog-user))) (read-from-string (force-string buffer)))
)))
))
(t
(let ((paragraphs
(split-into-paragraphs
(match-replace-all buffer
("${static-base}" (byte-vector-cat (blog-static-base-url (my blog)) (my name)))))))
(setf (my body-function)
(lambda ()
(with-ml-output
(loop for p in paragraphs
do (<p (output-raw-ml p))))))))))

(defun parse-time (str)
(match-bind
Expand Down
4 changes: 4 additions & 0 deletions src/packages.lisp
Expand Up @@ -430,6 +430,10 @@
(:nicknames #:tpd2.blog)
(:use #:cl #:tpd2.webapp #:tpd2.ml #:tpd2.ml.html #:tpd2.lib #:tpd2.datastore))

(defpackage #:teepeedee2.blog-user
(:nicknames #:tpd2.blog-user)
(:use #:cl #:tpd2.webapp #:tpd2.ml #:tpd2.ml.html #:tpd2.lib))

(defpackage #:teepeedee2.survey
(:nicknames #:tpd2.survey)
(:use #:cl #:tpd2.webapp #:tpd2.ml #:tpd2.ml.html #:tpd2.lib #:tpd2.datastore))
Expand Down

0 comments on commit dfc0b92

Please sign in to comment.