You are looking at historical revision 18500 of this page. It may differ significantly from its current revision.
html-utils
Introduction
html-utils is an extension which provides procedures to ease the generation of some frequently used [X]HTML structures.
Author
Procedures
[procedure] (itemize ITEMS #!key LIST-ID LIST-CLASS QUOTE-PROCEDURE)Generates an HTML unordered list of ITEMS. The following attributes may be used:
- LIST-ID: the value for the HTML id attribute for the list.
- LIST-CLASS: the value for the HTML class attribute for the list.
- QUOTE-PROCEDURE: an one-argument procedure to specify the quoting of attributes' values for tags.
Examples
(itemize '(apple watermelon strawberry))
Produces:
"<ul><li>apple</li><li>watermelon</li><li>strawberry</li></ul>"
(itemize '(apple watermelon strawberry) list-id: "my-list" list-class: "lists")
Produces:
"<ul id='my-list' class='lists'><li>apple</li><li>watermelon</li><li>strawberry</li></ul>"[procedure] (enumerate ITEMS #!key LIST-ID LIST-CLASS QUOTE-PROCEDURE)
Generates an HTML ordered list of ITEMS. See itemize.
[procedure] (html-page CONTENTS #!key CSS TITLE (DOCTYPE "") (HEADERS "") CHARSET)Generates an HTML page containing CONTENTS (a string). If contents starts with "<body" (case insensitive), html-page won't use the <body> tag to enclose CONTENS. The following keywords arguments may be used to customize the page:
- HEADERS: a string containing additional headers to be inserted in the section delimited by the <head> tag. Default = "".
- TITLE: the title for the page (to be used in the <title> tag). Default = "".
- CSS: may be either a path to a Cascading Style Sheet file, to be linked from the generated page (the default value is #f, so no CSS is used) or a list of paths to CSS files. If a list of paths is used, the elements which are also lists are read and inlined into the generated page. Example: css: '("css1.css" ("css2.css")). In the example, css1.css would be linked from the generated page (using the link tag) and css2.css would be inlined into the generated page (e.g., html-page would read the css2.css file and inline its contents in the HTML code).
- DOCTYPE: specifies the document type of the generated page. The default value is doctype:html-4.01-strict. The possible values are the ones available from the doctype egg.
- CHARSET: specifies the default charset to be used in the corresponding meta tag of the document. The default value is "iso-8859-1".
Examples
(html-page "hello")
Produces:
"<html><head></head><body>hello</body></html>"
(html-page "hello" title: "hello")
Produces:
"<html><head><title>hello</title></head><body>hello</body></html>"
(use doctype) (html-page "hello" title: "hello" doctype: xhtml-1.0-strict)
Produces:
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html><head><title>hello</title></head><body>hello</body></html>"
(html-page "hello" headers: (<script> type: "text/javascript" src: "my-script.js"))
Produces:
"<html><head><script type='text/javascript' src='my-script.js'></script></head><body>hello</body></html>"[procedure] (combo-box NAME OPTIONS #!key DEFAULT ID FIRST-EMPTY ONCHANGE ONKEYUP DISABLED LENGTH MULTIPLE SELECTEDINDEX SIZE TABINDEX TYPE CLASS)
Generates an HTML combo box using <select> and <option> tags. The keyword parameters ID, ONCHANGE, ONKEYUP, DISABLED, LENGTH, MULTIPLE, SELECTEDINDEX, SIZE, TABINDEX, TYPE and CLASS are passed to the <select> procedure (from html-tags). DEFAULT is the value from the list of options to be selected. If FIRST-EMPTY is #t, the first option of the combo box will be empty.
Example:
(combo-box "test" '(#(1 1) #(2 2) #(3 3)) first-empty: #t default: 2)
Produces:
<pre>"<select name='test' id='test'><option></option><option value='1'>1</option><option value='2' selected>2</option><option value='3'>3</option></select>" </pre>
[procedure] (hidden-input NAME/LIST #!optional VALUE ID)Generates an HTML hidden input field. NAME/LIST can be either a string representing the name attribute of the HTML input tag or an alist mapping names to values to be used by the corresponding input tags. When NAME/LIST is a string, so representing the name of the input tag, the optional values VALUE and ID can be used to be represent the values of their corresponding HTML attributes.
Examples
(hidden-input 'secret-var "secret-val")
Produces:
"<input type='hidden' name='secret-var' id='secret-var' value='secret-val'>"
(hidden-input '((secret-var1 . "secret-val1") (secret-var2 . "secret-val2")))
Produces:
"<input type='hidden' id='secret-var1' name='secret-var1' value='secret-val1'><input type='hidden' id='secret-var2' name='secret-var2' value='secret-val2'>"[procedure] (text-input name . args)
Generates an input text box. args are keyword arguments to be passed to <input> (from html-tags).
Examples
(text-input "foo" value: "bar")
Produces:
"<input type='text' name='foo' id='foo' value='bar'>"[procedure] (password-input name . args)
The same as text-input, but for password inputs.
[procedure] (submit-input . args)Generates a submit widget. args are keyword arguments to be passed to <input> (from html-tags).
(submit-input value: "Send!")
Produces:
"<input type='submit' value='Send!'>"[procedure] (tabularize ITEMS #!key TABLE-ID TABLE-CLASS QUOTE-PROCEDURE EVEN-ROW-CLASS ODD-ROW-CLASS HEADER)
Generates an HTML table from ITEMS (a list of lists). The following keyword parameters may be used:
- TABLE-ID: the value for the HTML id attribute for the table.
- TABLE-CLASS: the value for the HTML class attribute for the table.
- QUOTE-PROCEDURE: an one-argument procedure to specify the quoting of attributes' values for tags.
- EVEN-ROW-CLASS: the value for the HTML class attribute for even rows of the the table.
- ODD-ROW-CLASS: the value for the HTML class attribute for odd rows of the the table.
- HEADER: a list of column names to be used as the table header (enclosed by the th tag).
Examples
(tabularize '((1 2 3) (4 5 6)))
Produces:
"<table><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr></table>"
(tabularize '((1 2 3) (4 5 6)) table-id: "test" even-row-class: "yellow" odd-row-class: "blue")
Produces:
"<table id='test'><tr class='yellow'><td>1</td><td>2</td><td>3</td></tr><tr class='blue'><td>4</td><td>5</td><td>6</td></tr></table>"
License
BSD
Requirements
Version history
- 0.5
- Added the password-input procedure and the header keyword parameter for tabularize
- 0.4
- Added text-input and submit-input
- 0.1
- Initial release