From f598009d82c90ed11fb36b58308e4df0420afe51 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 18 May 2013 00:39:49 +0200 Subject: Use a property list for optional input settings --- eliss.el | 70 +++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/eliss.el b/eliss.el index 1b8e526..9ed2eb9 100644 --- a/eliss.el +++ b/eliss.el @@ -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 + "name" "Name" + :placeholder "John Doe" + :required t) ,(eliss-control-group - "email" "Email" "john@example.com") + "email" "Email" + :placeholder "john@example.com" + :required t) (input (@ (type "hidden") (name "i-m-human") (value "t"))) -- cgit v1.2.3-54-g00ecf