Beginning of static backend.

This commit is contained in:
Brit Butler 2011-04-17 17:48:38 -04:00
parent d04bbb3bc0
commit ce344d703e
5 changed files with 101 additions and 0 deletions

12
coleslaw-static.asd Normal file
View file

@ -0,0 +1,12 @@
(defsystem :coleslaw-static
:name "coleslaw-static"
:description "Flexible Lisp Blogware, Static backend"
:version "0.0.1"
:maintainer "Brit Butler <redline6561@gmail.com>"
:author "Brit Butler <redline6561@gmail.com>"
:licence "LLGPL"
:depends-on (:coleslaw :zs3 :trivial-timers)
:components ((:module static
:components ((:file "coleslaw")
(:file "posts"
:depends-on ("coleslaw"))))))

19
static/coleslaw.lisp Normal file
View file

@ -0,0 +1,19 @@
(in-package :coleslaw)
(defun static-init ()
(setf *storage* (make-hash-table))
(loop for table in '(:authors :comments :posts :indices :credentials)
do (unless (gethash table *storage*)
(setf (gethash table *storage*) (make-hash-table)))))
(defmethod start-coleslaw (&rest options)
)
(defmethod stop-coleslaw (&rest options)
)
(defmethod get-credentials (name)
(gethash name (gethash :credentials *storage*)))
(defmethod set-credentials (name credentials)
(setf (gethash name (gethash :credentials *storage*)) credentials))

2
static/comments.lisp Normal file
View file

@ -0,0 +1,2 @@
(in-package :coleslaw)

13
static/indices.lisp Normal file
View file

@ -0,0 +1,13 @@
(in-package :coleslaw)
(defmethod find-index (id)
(gethash id (gethash :indices *storage*)))
(defmethod add-index (index id)
(setf (find-index id) index))
(defmethod remove-index (id)
(setf (find-index id) nil))
(defmethod render-index (index)
)

55
static/posts.lisp Normal file
View file

@ -0,0 +1,55 @@
(in-package :coleslaw)
;; TODO
;; How are we handling next/prev + ids?
;; Implement find-by-date.
;; Consider having find-by-range collect all the hash-values in :posts
;; and return the range of that list rather than the posts matching start->end.
;; Consider storing tags as a list.
(defmethod make-post :before (title tags date content &key id &allow-other-keys)
(when id
(let ((index (gethash :posts-index *storage* 0)))
(unless (<= id index)
(setf (gethash :posts-index *storage*) (1+ id))))))
(defmethod make-post (title tags date content &key id)
(make-instance 'post :id (or id (gethash :posts-index *storage* 0))
:title title
:tags tags
:date date
:content content))
(defmethod add-post ((post post) id)
(setf (gethash id (gethash :posts *storage*)) post))
(defmethod remove-post (id)
(setf (gethash id (gethash :posts *storage*)) nil))
(defmethod render-post (id)
(flet ((fn (name)
(find-symbol name (theme-package))))
(let* ((post (find-post id))
(result (funcall (fn "POST")
(list :title (post-title post)
:tags (post-tags post)
:date (post-date post)
:content (post-content post)
:prev (post-prev post)
:next (post-next post)))))
result)))
(defmethod find-post (id)
(gethash id (gethash :posts *storage*)))
(defmethod find-by-tag (tag)
(let ((results nil))
(loop for post being the hash-values in (gethash :posts *storage*)
do (when (search tag (post-tags post))
(push post results)))
results))
(defmethod find-by-range (start end)
(loop for i from start upto end
collecting (find-post id) into results
finally (return (remove nil results))))