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,25 +51,28 @@ container div."
(directory-files eliss-data-directory nil
"\\.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.
Set the name and id attributes of the input to NAME, give it the
label LABEL, optionally add a placeholder PLACEHOLDER and
optionally a value DEFAULT."
`(div (@ (class "control-group"))
(label (@ (class "control-label")
(for ,name)) ,label)
(div (@ (class "controls"))
(input (@ (type "text")
(name ,name)
(id ,name)
,(if placeholder
`(placeholder ,placeholder)
nil)
,(if default
`(value ,default)
nil))))))
label LABEL. The property list PLIST can be used to define
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"))
(label (@ (class "control-label")
(for ,name)) ,label)
(div (@ (class "controls"))
(input (@ (type "text")
(name ,name)
(id ,name)
,(when placeholder `(placeholder ,placeholder))
,(when default `(value ,default))))))))
(defun eliss-project-page (httpcon)
"Send a list of issues and an issue-creation form over HTTPCON."
@ -98,14 +101,18 @@ optionally a value DEFAULT."
(legend "New issue")
(div (@ (class "row"))
(div (@ (class "span5"))
,(eliss-control-group "subject" "Subject"
"I wanna say...")
,(eliss-control-group "category" "Category" nil
"bug")
,(eliss-control-group "tags" "Tags" "tag1:tag2")
,(eliss-control-group "name" "Name" "John Doe")
,(eliss-control-group "email" "Email"
"john@example.com")
,(eliss-control-group
"subject" "Subject"
:placeholder "I wanna say...")
,(eliss-control-group "category" "Category"
:default "bug")
,(eliss-control-group "tags" "Tags"
:placeholder "tag1:tag2")
,(eliss-control-group "name" "Name"
:placeholder "John Doe")
,(eliss-control-group
"email" "Email"
:placeholder "john@example.com")
(input (@ (type "hidden")
(name "i-m-human")
(value "t")))
@ -166,12 +173,17 @@ optionally a value DEFAULT."
(div (@ (class "row"))
(div (@ (class "span5"))
,(eliss-control-group
"subject" "Subject" nil
(concat "RE: " title))
,(eliss-control-group "name" "Name"
"John Doe")
"subject" "Subject"
:default (concat "RE: " title)
:required t)
,(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")
(name "i-m-human")
(value "t")))