Use a property list for optional input settings

This commit is contained in:
Tom Willemse 2013-05-18 00:39:49 +02:00
parent 5a76a27674
commit f598009d82

View file

@ -51,12 +51,19 @@ container div."
(directory-files eliss-data-directory nil (directory-files eliss-data-directory nil
"\\.org$")))))) "\\.org$"))))))
(defun eliss-control-group (name label &optional placeholder default) (defun eliss-control-group (name label &rest plist)
"Return an often-used common HTML structure. "Return an often-used common HTML structure.
Set the name and id attributes of the input to NAME, give it the Set the name and id attributes of the input to NAME, give it the
label LABEL, optionally add a placeholder PLACEHOLDER and label LABEL. The property list PLIST can be used to define
optionally a value DEFAULT." certain other properties.
- `:default' may specify a default value to appear in the input.
- `:placeholder' may specify a placeholder for the input, which
appears if no value has been given."
(let ((default (plist-get plist :default))
(placeholder (plist-get plist :placeholder)))
`(div (@ (class "control-group")) `(div (@ (class "control-group"))
(label (@ (class "control-label") (label (@ (class "control-label")
(for ,name)) ,label) (for ,name)) ,label)
@ -64,12 +71,8 @@ optionally a value DEFAULT."
(input (@ (type "text") (input (@ (type "text")
(name ,name) (name ,name)
(id ,name) (id ,name)
,(if placeholder ,(when placeholder `(placeholder ,placeholder))
`(placeholder ,placeholder) ,(when default `(value ,default))))))))
nil)
,(if default
`(value ,default)
nil))))))
(defun eliss-project-page (httpcon) (defun eliss-project-page (httpcon)
"Send a list of issues and an issue-creation form over HTTPCON." "Send a list of issues and an issue-creation form over HTTPCON."
@ -98,14 +101,18 @@ optionally a value DEFAULT."
(legend "New issue") (legend "New issue")
(div (@ (class "row")) (div (@ (class "row"))
(div (@ (class "span5")) (div (@ (class "span5"))
,(eliss-control-group "subject" "Subject" ,(eliss-control-group
"I wanna say...") "subject" "Subject"
,(eliss-control-group "category" "Category" nil :placeholder "I wanna say...")
"bug") ,(eliss-control-group "category" "Category"
,(eliss-control-group "tags" "Tags" "tag1:tag2") :default "bug")
,(eliss-control-group "name" "Name" "John Doe") ,(eliss-control-group "tags" "Tags"
,(eliss-control-group "email" "Email" :placeholder "tag1:tag2")
"john@example.com") ,(eliss-control-group "name" "Name"
:placeholder "John Doe")
,(eliss-control-group
"email" "Email"
:placeholder "john@example.com")
(input (@ (type "hidden") (input (@ (type "hidden")
(name "i-m-human") (name "i-m-human")
(value "t"))) (value "t")))
@ -166,12 +173,17 @@ optionally a value DEFAULT."
(div (@ (class "row")) (div (@ (class "row"))
(div (@ (class "span5")) (div (@ (class "span5"))
,(eliss-control-group ,(eliss-control-group
"subject" "Subject" nil "subject" "Subject"
(concat "RE: " title)) :default (concat "RE: " title)
,(eliss-control-group "name" "Name" :required t)
"John Doe")
,(eliss-control-group ,(eliss-control-group
"email" "Email" "john@example.com") "name" "Name"
:placeholder "John Doe"
:required t)
,(eliss-control-group
"email" "Email"
:placeholder "john@example.com"
:required t)
(input (@ (type "hidden") (input (@ (type "hidden")
(name "i-m-human") (name "i-m-human")
(value "t"))) (value "t")))