summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-03-11 21:36:25 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2011-03-11 21:36:25 +0100
commit3a1e10c6610946ba0ff21276c16d8637146c3542 (patch)
tree310f54c489e5d4037f89454eebf56c0f83bce6c3
parent243b6063cc5a88f50a7db14f69f946220e54b7bb (diff)
Fill in a couple of template variables.
-rw-r--r--mulkcms-hunchentoot.lisp2
-rw-r--r--mulkcms.lisp83
-rw-r--r--templates/article.html12
3 files changed, 75 insertions, 22 deletions
diff --git a/mulkcms-hunchentoot.lisp b/mulkcms-hunchentoot.lisp
index 3200110..3a554a7 100644
--- a/mulkcms-hunchentoot.lisp
+++ b/mulkcms-hunchentoot.lisp
@@ -29,6 +29,8 @@
(defun start-server ()
(setq hunchentoot:*hunchentoot-default-external-format*
(flexi-streams:make-external-format :utf-8))
+ (setq hunchentoot:*default-content-type*
+ "text/html; charset=utf-8")
(setup-handlers)
(hunchentoot:start (make-instance 'hunchentoot:acceptor
:port *server-port*
diff --git a/mulkcms.lisp b/mulkcms.lisp
index 306232e..d305fbf 100644
--- a/mulkcms.lisp
+++ b/mulkcms.lisp
@@ -13,6 +13,39 @@
*template-formatters*)))
+(defun find-canonical-article-alias (article)
+ (query "SELECT alias FROM article_aliases WHERE article = $1 LIMIT 1"
+ article
+ :single))
+
+(defun link-to (action &key comment-id article-id (absolute nil))
+ ;; Taken from Mulkblog.
+ (with-output-to-string (out)
+ (format out "~A" (if absolute *base-uri* ""))
+ (symbol-macrolet ((article-base (find-canonical-article-alias article-id)))
+ (multiple-value-call
+ #'(lambda (&rest args) (apply #'format out args))
+ (ecase action
+ (:index "")
+ (:full-index "/?full")
+ (:view-atom-feed (values "/feed"))
+ (:view-comment-feed (cond (article-id (values "/~A?comment-feed" article-base))
+ (t "/comment-feed")))
+ (:view (cond (comment-id (values "/~A#comment-~D" article-base comment-id))
+ (article-id (values "/~A" article-base))
+ (t "/")))
+ ((:edit :preview) (values "/~A?preview" article-base))
+ (:post-comment (values "/~A" article-base))
+ (:trackback (values "/~A?trackback" article-base))
+ (:view-atom-entry (values "/~A?atom" article-base))
+ (:save (values "/~A?save" article-base))
+ (:moderation-page "/moderate")
+ (:css "/journal.css")
+ (:prettify.css "/prettify/prettify.css")
+ (:prettify.js "/prettify/prettify.js")
+ (:prettify-lisp.js "/prettify/lang-lisp.js")
+ (:pingback "/rpc"))))))
+
(defun call-with-db (thunk)
(call-with-connection *database-connection-spec* thunk))
@@ -47,19 +80,29 @@
(destructuring-bind (rid article date title content author format status
global-id &rest args)
revision-data
- (declare (ignore args rid))
+ (declare (ignore args rid format author))
(list :publishing-date date
:title title
:body content
- ;;FIXME
- :link ""
+ :article-id article
+ :global-id global-id
+ :status status
+ :link (link-to :view :article-id article)
:commentary (if commentary-p (list :comments comments) nil)
- :edit-link ""
+ :comment-submission (when commentary-p
+ (list :fields (list (list :field-id "name"
+ :field-label "Name"))
+ :body-label "Message"
+ :submit-button-label "Submit"
+ :title "Submit a comment"
+ :notes "<p>NOTE: Do something.</p>"
+ :action (link-to :post-comment :article-id article)))
+ :edit-link (link-to :edit :article-id article)
:edit-button-label "Edit"
- :comment-feed ""
+ :comment-feed (link-to :view-comment-feed :article-id article)
:comment-feed-label "Comment feed"
:comments-label "Comments"
- :comments-link ""
+ :comments-link (link-to :view :article-id article)
:comments-heading "Comments")))
(defun format-comment-content (text)
@@ -193,15 +236,23 @@
(destructuring-bind (crid comment date content author format status
article-revision &rest args)
comment-revision-data
- (declare (ignore args crid article-revision status format comment))
- (list :publishing-date date
- :body (format-comment-content content)
- :author author
- ;;FIXME
- :link ""
- :edit-link ""
- :edit-button-label "Edit"
- :generic-commenter-name "Someone")))
+ (declare (ignore args crid status format))
+ (destructuring-bind (author-name author-website)
+ (query "SELECT name, website FROM users WHERE id = $1" author :row)
+ (let ((article (query "SELECT article FROM article_revisions WHERE id = $1"
+ article-revision
+ :single!)))
+ (list :publishing-date date
+ :body (format-comment-content content)
+ :author author-name
+ ;;FIXME
+ :author-link (if (and author-website (not (equal author-website "")))
+ author-website
+ nil)
+ :link (link-to :view :article-id article :comment-id comment)
+ :edit-link ""
+ :edit-button-label "Edit"
+ :generic-commenter-name "Someone")))))
(defprepared find-journal-articles
"SELECT article
@@ -303,7 +354,7 @@
WHERE articles.id = $1"
article
:single!))
- (article-params (find-article-params article characteristics))
+ (article-params (find-article-params article characteristics t))
(page-skeleton (template "page_skeleton"))
(page-template (template page-template-name))
(template-params (list :title (getf article-params :title)
diff --git a/templates/article.html b/templates/article.html
index e56ab7d..61cc9de 100644
--- a/templates/article.html
+++ b/templates/article.html
@@ -22,7 +22,7 @@
action="{edit-link|html-attr-value}"
method="get">
<div style="display: inline;">
- <input name="id" type="hidden" value="106" />
+ <input name="edit" type="hidden" />
<input type="submit" value="{edit-button-label|html-attr-value}" />
</div>
</form>
@@ -42,7 +42,7 @@
<div class="comment">
<div class="comment-header">
{publishing-date|html-human-date}
- <a rel="nofollow" {.section link}href="{@|html-attr-value}"{.end}>{.section author}{@|html}{.or}{generic-commenter-name|html}{.end}</a>:
+ <a rel="nofollow" {.section author-link}href="{@|html-attr-value}"{.end}>{.section author}{@|html}{.or}{generic-commenter-name|html}{.end}</a>:
</div>
<div class="comment-body">
{body}
@@ -56,7 +56,7 @@
<form action="{action|html-attr-value}" accept-charset="UTF-8"
enctype="application/x-www-form-urlencoded" method="post">
<div style="display: none">
- <input name="id" type="hidden" value="98" />
+ <input name="id" type="hidden" value="{article-id|html-attr-value}" />
<input name="action" type="hidden" value="post-comment" />
</div>
<div class="comment-form-table">
@@ -64,11 +64,11 @@
<div class="comment-form-row">
<div class="comment-form-label">
<label style="vertical-align: top"
- for="{field-id|html-attr-value}">{field-label|html}:</label>
+ for="comment-form-input-{field-id|html-attr-value}">{field-label|html}:</label>
</div>
<div class="comment-form-input">
- <input id="{field-id|html-attr-value}"
- name="{field-name|html-attr-value}" type="text" />
+ <input id="comment-form-input-{field-id|html-attr-value}"
+ name="{field-id|html-attr-value}" type="text" />
</div>
</div>
{.end}