Add macro to ease usage of http parameters

This commit is contained in:
Tom Willemse 2013-05-18 01:07:32 +02:00
parent e3ef726cb9
commit 16ad33e32c

View file

@ -13,6 +13,14 @@
;;; Code: ;;; Code:
(defmacro with-eliss-http-params (params httpcon &rest body)
"Bind parameters PARAMS from HTTPCON and execute BODY."
`(let (,@(mapcar (lambda (p)
`(,p (elnode-http-param ,httpcon ,(symbol-name p))))
params))
,@body))
(put 'with-eliss-http-params 'lisp-indent-function 2)
(defvar eliss-data-directory "~/projects/eliss/projects") (defvar eliss-data-directory "~/projects/eliss/projects")
(defun project-row (project) (defun project-row (project)
@ -205,31 +213,25 @@ certain other properties.
(POST (POST
(let* ((project (match-string 1 (elnode-http-mapping httpcon))) (let* ((project (match-string 1 (elnode-http-mapping httpcon)))
(filename (concat eliss-data-directory "/" project ".org")) (filename (concat eliss-data-directory "/" project ".org"))
(buffer (find-file-noselect filename)) (buffer (find-file-noselect filename)))
(subject (elnode-http-param httpcon "subject")) (with-eliss-http-params (subject tags i-m-human i-r-bot content
(tags (elnode-http-param httpcon "tags")) category name email) httpcon
(i-m-human (elnode-http-param httpcon "i-m-human")) (when (and (equal i-m-human "t") (equal i-r-bot ""))
(i-r-bot (elnode-http-param httpcon "i-r-bot")) (with-current-buffer buffer
(content (elnode-http-param httpcon "content")) (goto-char (point-min))
(category (elnode-http-param httpcon "category")) (unless (org-at-heading-p)
(name (elnode-http-param httpcon "name")) (org-forward-heading-same-level nil))
(email (elnode-http-param httpcon "email"))) (org-insert-todo-heading t)
(when (and (equal i-m-human "t") (equal i-r-bot "")) (insert subject)
(with-current-buffer buffer (let ((text-start (point)))
(goto-char (point-min)) (insert "\n\n " content)
(unless (org-at-heading-p) (fill-region text-start (point)))
(org-forward-heading-same-level nil)) (org-set-tags-to tags)
(org-insert-todo-heading t) (org-set-property "CATEGORY" category)
(insert subject) (org-set-property "ID" (org-id-new project))
(let ((text-start (point))) (org-set-property "AuthorName" name)
(insert "\n\n " content) (org-set-property "AuthorEmail" email)
(fill-region text-start (point))) (save-buffer))))
(org-set-tags-to tags)
(org-set-property "CATEGORY" category)
(org-set-property "ID" (org-id-new project))
(org-set-property "AuthorName" name)
(org-set-property "AuthorEmail" email)
(save-buffer)))
(elnode-send-redirect httpcon (concat "/" project "/")))))) (elnode-send-redirect httpcon (concat "/" project "/"))))))
(defun eliss-new-comment (httpcon) (defun eliss-new-comment (httpcon)
@ -240,28 +242,22 @@ certain other properties.
(issue (match-string 2 (elnode-http-mapping httpcon))) (issue (match-string 2 (elnode-http-mapping httpcon)))
(entry (cdr (org-id-find issue))) (entry (cdr (org-id-find issue)))
(filename (concat eliss-data-directory "/" project ".org")) (filename (concat eliss-data-directory "/" project ".org"))
(buffer (find-file-noselect filename)) (buffer (find-file-noselect filename)))
(subject (elnode-http-param httpcon "subject")) (with-eliss-http-params (subject name email i-m-human i-r-bot
(name (elnode-http-param httpcon "name")) content) httpcon
(email (elnode-http-param httpcon "email")) (when (and (equal i-m-human "t") (equal i-r-bot ""))
(i-m-human (elnode-http-param httpcon "i-m-human")) (with-current-buffer buffer
(i-r-bot (elnode-http-param httpcon "i-r-bot")) (goto-char entry)
(content (elnode-http-param httpcon "content")) (org-end-of-subtree)
(name (elnode-http-param httpcon "name")) (org-insert-heading-after-current)
(email (elnode-http-param httpcon "email"))) (insert subject)
(when (and (equal i-m-human "t") (equal i-r-bot "")) (org-set-property "TODO" "COMMENT")
(with-current-buffer buffer (let ((text-start (point)))
(goto-char entry) (insert "\n\n" content)
(org-end-of-subtree) (fill-region text-start (point)))
(org-insert-heading-after-current) (org-set-property "AuthorName" name)
(insert subject) (org-set-property "AuthorEmail" email)
(org-set-property "TODO" "COMMENT") (save-buffer))))
(let ((text-start (point)))
(insert "\n\n" content)
(fill-region text-start (point)))
(org-set-property "AuthorName" name)
(org-set-property "AuthorEmail" email)
(save-buffer)))
(elnode-send-redirect httpcon (concat "/" project "/" issue "/")))))) (elnode-send-redirect httpcon (concat "/" project "/" issue "/"))))))
(defun eliss-handler (httpcon) (defun eliss-handler (httpcon)