summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-05-18 01:07:32 +0200
committerGravatar Tom Willemse2013-05-18 01:07:32 +0200
commit16ad33e32cce99fca14928f82aa481bfc371e45c (patch)
tree3f67072cfce35f2aa78e950cd315313a81038a3b
parente3ef726cb9afc0ed1c8e8c5702cc56f21c9fec20 (diff)
downloadeliss-16ad33e32cce99fca14928f82aa481bfc371e45c.tar.gz
eliss-16ad33e32cce99fca14928f82aa481bfc371e45c.zip
Add macro to ease usage of http parameters
-rw-r--r--eliss.el90
1 files changed, 43 insertions, 47 deletions
diff --git a/eliss.el b/eliss.el
index e50104a..faa898f 100644
--- a/eliss.el
+++ b/eliss.el
@@ -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)