Extract some functions

To make the `scrumelo-backlog-page' function a little simpler some
small functions were extracted from it, this makes the overall code
look a little nicer since it doesn't cross the 80th column.

Some CDN files were added as well, there are not used yet.
This commit is contained in:
Tom Willemse 2013-05-20 14:16:33 +02:00
parent ded34a194c
commit 6a1d1398a2

View file

@ -18,6 +18,68 @@
(defvar scrumelo-project-file "~/projects/scrumelo/aeos.org" (defvar scrumelo-project-file "~/projects/scrumelo/aeos.org"
"The file containing the scrum backlog.") "The file containing the scrum backlog.")
(defvar scrumelo-bootstrap-css-location
"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css"
"The location of the twitter bootstrap CSS file.")
(defvar scrumelo-bootstrap-js-location
"http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"
"The location of the twitter bootstrap JS file.")
(defvar scrumelo-font-awesome-css-location
"http://netdna.bootstrapcdn.com/font-awesome/3.1.1/css/font-awesome.min.css"
"The location of the font awesome CSS file.")
(defvar scrumelo-jquery-js-location
"http://code.jquery.com/jquery-2.0.0.min.js"
"The location of the jQuery JS file.")
(defun scrumelo--css (href)
"Return a link pointing to HREF."
`(link (@ (href ,href) (rel "stylesheet") (type "text/css"))))
(defun scrumelo--css-list ()
"Return a list of all required CSS files."
(list (scrumelo--css scrumelo-bootstrap-css-location)
(scrumelo--css scrumelo-font-awesome-css-location)))
(defun scrumelo--js (src)
"Return a script sourcing SRC."
`(script (@ (src ,src) (language "JavaScript")
(type "text/javascript")) ""))
(defun scrumelo--js-list ()
"Return a list of all required JS files."
(list (scrumelo--js scrumelo-bootstrap-js-location)
(scrumelo--js scrumelo-jquery-js-location)))
(defun scrumelo--story ()
"Return a description of the current org heading as a scrum story."
(format "As a %s, I %s to %s" (org-entry-get (point) "Role")
(org-entry-get (point) "Necessity")
(nth 4 (org-heading-components))))
(defun scrumelo--story-row ()
"Return a table row for the current org headline."
`(tr (td ,(org-entry-get (point) "TODO"))
(td ,(scrumelo--story))))
(defun scrumelo--maybe-story-row ()
"If looking at a top level heading, return a table row for it."
(when (= (car (org-heading-components)) 1)
(scrumelo--story-row)))
(defun scrumelo--inner-story-table (buffer)
"Return the inner part of the story table for BUFFER."
(with-current-buffer buffer
(delq nil (org-map-entries
'scrumelo--maybe-story-row nil nil 'comment))))
(defun scrumelo--story-table (buffer)
"Return the story table for BUFFER."
`(table (@ (class "table table-striped"))
,@(scrumelo--inner-story-table buffer)))
(defun scrumelo-backlog-page (httpcon) (defun scrumelo-backlog-page (httpcon)
"Send the backlog overview over HTTPCON." "Send the backlog overview over HTTPCON."
(let ((buffer (find-file-noselect scrumelo-project-file))) (let ((buffer (find-file-noselect scrumelo-project-file)))
@ -28,21 +90,11 @@
"<!DOCTYPE html>\n" "<!DOCTYPE html>\n"
(sxml-to-xml (sxml-to-xml
`(html (head (title "Scrumelo") `(html (head (title "Scrumelo")
(link (@ (href "http://ryuslash.org/bootstrap2/css/bootstrap.min.css") ,@(scrumelo--css-list)
(type "text/css") (rel "stylesheet")))) ,@(scrumelo--js-list))
(body (body
(div (@ (class "container")) (div (@ (class "container"))
(table (@ (class "table")) ,(scrumelo--story-table buffer)))))))))
,@(with-current-buffer buffer
(delq nil
(org-map-entries
(lambda ()
(when (= (car (org-heading-components)) 1)
`(tr (td ,(org-entry-get (point) "TODO"))
(td ,(format "As a %s, I %s to %s"
(org-entry-get (point) "Role")
(org-entry-get (point) "Necessity")
(nth 4 (org-heading-components))))))) nil nil 'comment))))))))))))
(defun scrumelo-handler (httpcon) (defun scrumelo-handler (httpcon)
"Send the right requests in HTTPCON to the right functions." "Send the right requests in HTTPCON to the right functions."