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:
(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")
(defun project-row (project)
@ -205,31 +213,25 @@ certain other properties.
(POST
(let* ((project (match-string 1 (elnode-http-mapping httpcon)))
(filename (concat eliss-data-directory "/" project ".org"))
(buffer (find-file-noselect filename))
(subject (elnode-http-param httpcon "subject"))
(tags (elnode-http-param httpcon "tags"))
(i-m-human (elnode-http-param httpcon "i-m-human"))
(i-r-bot (elnode-http-param httpcon "i-r-bot"))
(content (elnode-http-param httpcon "content"))
(category (elnode-http-param httpcon "category"))
(name (elnode-http-param httpcon "name"))
(email (elnode-http-param httpcon "email")))
(when (and (equal i-m-human "t") (equal i-r-bot ""))
(with-current-buffer buffer
(goto-char (point-min))
(unless (org-at-heading-p)
(org-forward-heading-same-level nil))
(org-insert-todo-heading t)
(insert subject)
(let ((text-start (point)))
(insert "\n\n " content)
(fill-region text-start (point)))
(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)))
(buffer (find-file-noselect filename)))
(with-eliss-http-params (subject tags i-m-human i-r-bot content
category name email) httpcon
(when (and (equal i-m-human "t") (equal i-r-bot ""))
(with-current-buffer buffer
(goto-char (point-min))
(unless (org-at-heading-p)
(org-forward-heading-same-level nil))
(org-insert-todo-heading t)
(insert subject)
(let ((text-start (point)))
(insert "\n\n " content)
(fill-region text-start (point)))
(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 "/"))))))
(defun eliss-new-comment (httpcon)
@ -240,28 +242,22 @@ certain other properties.
(issue (match-string 2 (elnode-http-mapping httpcon)))
(entry (cdr (org-id-find issue)))
(filename (concat eliss-data-directory "/" project ".org"))
(buffer (find-file-noselect filename))
(subject (elnode-http-param httpcon "subject"))
(name (elnode-http-param httpcon "name"))
(email (elnode-http-param httpcon "email"))
(i-m-human (elnode-http-param httpcon "i-m-human"))
(i-r-bot (elnode-http-param httpcon "i-r-bot"))
(content (elnode-http-param httpcon "content"))
(name (elnode-http-param httpcon "name"))
(email (elnode-http-param httpcon "email")))
(when (and (equal i-m-human "t") (equal i-r-bot ""))
(with-current-buffer buffer
(goto-char entry)
(org-end-of-subtree)
(org-insert-heading-after-current)
(insert subject)
(org-set-property "TODO" "COMMENT")
(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)))
(buffer (find-file-noselect filename)))
(with-eliss-http-params (subject name email i-m-human i-r-bot
content) httpcon
(when (and (equal i-m-human "t") (equal i-r-bot ""))
(with-current-buffer buffer
(goto-char entry)
(org-end-of-subtree)
(org-insert-heading-after-current)
(insert subject)
(org-set-property "TODO" "COMMENT")
(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 "/"))))))
(defun eliss-handler (httpcon)