modules/html/html.man | 76 +++++++++++++++-
modules/html/html.tcl | 55 +++++++++---
modules/html/html.test | 224 +++++++++++++++++++++++++++++++++++-----------
modules/html/pkgIndex.tcl | 2 +-
4 files changed, 287 insertions(+), 70 deletions(-)
diff --git a/modules/html/html.man b/modules/html/html.man
index 705a8a2..f18cf4b 100644
--- a/modules/html/html.man
+++ b/modules/html/html.man
@@ -1,5 +1,6 @@
[comment {-*- tcl -*- doctools manpage}]
-[manpage_begin html n 1.4]
+[vset HTML_VERSION 1.4.4]
+[manpage_begin html n [vset HTML_VERSION]]
[see_also htmlparse]
[see_also ncgi]
[keywords checkbox]
@@ -12,7 +13,7 @@
[titledesc {Procedures to generate HTML structures}]
[category {CGI programming}]
[require Tcl 8.2]
-[require html [opt 1.4]]
+[require html [opt [vset HTML_VERSION]]]
[description]
[para]
@@ -62,7 +63,7 @@ the elements.
[call [cmd ::html::checkValue] [arg name] [opt [arg value]]]
-Generate the "name=[arg name] value=[arg value] for a [term checkbox] form
+Generate the "name=[arg name] value=[arg value]" for a [term checkbox] form
element. If the CGI variable [arg name] has the value [arg value],
then SELECTED is added to the return value. [arg value] defaults to
"1".
@@ -245,6 +246,51 @@ value list that is used for the name= and value= parameters for the
[term meta] tag. The [term meta] tag is included in the result of
[cmd ::html::head].
+[call [cmd ::html::css] [arg href]]
+
+[emph {Side effect only}]. Call this before [cmd ::html::head] to
+define a [term link] tag for a linked CSS document. The [arg href]
+value is a HTTP URL to a CSS document. The [term link] tag is included
+in the result of [cmd ::html::head].
+
+[para]
+
+Multiple calls of this command are allowed, enabling the use of
+multiple CSS document references. In other words, the arguments
+of multiple calls are accumulated, and do not overwrite each other.
+
+[call [cmd ::html::css-clear]]
+
+[emph {Side effect only}]. Call this before [cmd ::html::head] to
+clear all links to CSS documents.
+[para]
+
+Multiple calls of this command are allowed, doing nothing after the
+first of a sequence with no intervening [cmd ::html::css].
+
+[call [cmd ::html::js] [arg href]]
+
+[emph {Side effect only}]. Call this before [cmd ::html::head] to
+define a [term script] tag for a linked JavaScript document. The
+[arg href] is a HTTP URL to a JavaScript document. The [term script]
+tag is included in the result of [cmd ::html::head].
+
+[para]
+
+Multiple calls of this command are allowed, enabling the use of
+multiple JavaScript document references. In other words, the arguments
+of multiple calls are accumulated, and do not overwrite each other.
+
+
+[call [cmd ::html::js-clear]]
+
+[emph {Side effect only}]. Call this before [cmd ::html::head] to
+clear all links to JavaScript documents.
+[para]
+
+Multiple calls of this command are allowed, doing nothing after the
+first of a sequence with no intervening [cmd ::html::js].
+
[call [cmd ::html::minorList] [arg list] [opt [arg ordered]]]
Generate an ordered or unordered list of links. The [arg list] is a
@@ -306,7 +352,7 @@ is a Tcl-style label, value list.
[call [cmd ::html::radioValue] [arg {name value}]]
-Generate the "name=[arg name] value=[arg value] for a [term radio] form
+Generate the "name=[arg name] value=[arg value]" for a [term radio] form
element. If the CGI variable [arg name] has the value [arg value],
then SELECTED is added to the return value.
@@ -401,6 +447,28 @@ structure. Rather than evaluating the body, it returns the subst'ed
[arg body]. Each iteration of the loop causes another string to be
concatenated to the result value.
+[call [cmd ::html::doctype] [arg id]]
+
+This procedure can be used to build the standard DOCTYPE
+declaration string. It will return the standard declaration
+string for the id, or throw an error if the id is not known.
+The following id's are defined:
+
+[list_begin enumerated]
+[enum] HTML32
+[enum] HTML40
+[enum] HTML40T
+[enum] HTML40F
+[enum] HTML401
+[enum] HTML401T
+[enum] HTML401F
+[enum] XHTML10S
+[enum] XHTML10T
+[enum] XHTML10F
+[enum] XHTML11
+[enum] XHTMLB
+[list_end]
+
[list_end]
[vset CATEGORY html]
diff --git a/modules/html/html.tcl b/modules/html/html.tcl
index 77e517e..3c0c443 100644
--- a/modules/html/html.tcl
+++ b/modules/html/html.tcl
@@ -15,7 +15,7 @@
package require Tcl 8.2
package require ncgi
-package provide html 1.4
+package provide html 1.4.4
namespace eval ::html {
@@ -510,7 +510,7 @@ proc ::html::refresh {content {url {}}} {
::if {[string length $url]} {
append html "; url=$url"
}
- append html "\">\n"
+ append html "\">"
lappend page(meta) $html
return ""
}
@@ -912,7 +912,7 @@ proc ::html::selectPlain {name param choices {current {}}} {
# The html fragment
proc ::html::textarea {name {param {}} {current {}}} {
- ::set value [ncgi::value $name $current]
+ ::set value [quoteFormValue [ncgi::value $name $current]]
return "<[string trimright \
"textarea name=\"$name\"\
[tagParam textarea $param]"]>$value\n"
@@ -1405,7 +1405,7 @@ proc ::html::html_entities {s} {
# The text with
in place of line-endings.
proc ::html::nl2br {s} {
- return [string map [list \n\r
\n
\r
] $s]
+ return [string map [list \n\r
\r\n
\n
\r
] $s]
}
# ::html::doctype
@@ -1419,9 +1419,10 @@ proc ::html::nl2br {s} {
proc ::html::doctype {arg} {
variable doctypes
- set code [string toupper $arg]
- if {![info exists doctypes($code)]} {
- return -code error "Unknown doctype \"$arg\""
+ ::set code [string toupper $arg]
+ ::if {![info exists doctypes($code)]} {
+ return -code error -errorcode {HTML DOCTYPE BAD} \
+ "Unknown doctype \"$arg\""
}
return $doctypes($code)
}
@@ -1451,12 +1452,26 @@ namespace eval ::html {
# href The location of the css file to include the filename and path
#
# Results:
-# HTML for the section
+# None.
proc ::html::css {href} {
variable page
- set page(css) \
- "\n"
+ lappend page(css) ""
+ return
+}
+
+# ::html::css-clear
+# Drop all text/css references.
+#
+# Arguments:
+# None.
+#
+# Results:
+# None.
+
+proc ::html::css-clear {} {
+ variable page
+ catch { unset page(css) }
return
}
@@ -1467,11 +1482,25 @@ proc ::html::css {href} {
# href The location of the javascript file to include the filename and path
#
# Results:
-# HTML for the section
+# None.
proc ::html::js {href} {
variable page
- set page(js) \
- "\n"
+ lappend page(js) ""
+ return
+}
+
+# ::html::js-clear
+# Drop all text/javascript references.
+#
+# Arguments:
+# None.
+#
+# Results:
+# None.
+
+proc ::html::js-clear {} {
+ variable page
+ catch { unset page(js) }
return
}
diff --git a/modules/html/html.test b/modules/html/html.test
index 7a03c54..6646fb6 100644
--- a/modules/html/html.test
+++ b/modules/html/html.test
@@ -17,8 +17,8 @@ source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
-testsNeedTcl 8.2
-testsNeedTcltest 1.0
+testsNeedTcl 8.4
+testsNeedTcltest 2.0
testing {
useLocal html.tcl html
@@ -26,45 +26,46 @@ testing {
# -------------------------------------------------------------------------
-test html-1.1 {html::init} {
+test html-1.1 {html::init} -body {
html::init
- list [array exists html::defaults] \
- [array size html::defaults] \
- [info exists html::page]
-} {1 0 0}
+ list \
+ [array exists html::defaults] \
+ [array size html::defaults] \
+ [info exists html::page]
+} -result {1 0 0}
-test html-1.2 {html::init} {
+test html-1.2 {html::init} -body {
html::init {
font.face arial
body.bgcolor white
body.text black
}
lsort [array names html::defaults]
-} {body.bgcolor body.text font.face}
+} -result {body.bgcolor body.text font.face}
-test html-1.3 {html::init} {
- catch {html::init wrong num args}
-} 1
+test html-1.3 {html::init, too many args} -body {
+ html::init wrong num args
+} -returnCodes error -result {wrong # args: should be "html::init ?nvlist?"}
-test html-1.4 {html::init} {
- catch {html::init {wrong num args}}
-} 1
+test html-1.4 {html::init, bad arg, odd-length list} -body {
+ html::init {wrong num args}
+} -returnCodes error -result {list must have an even number of elements}
-test html-2.1 {html::head} {
- catch {html::head}
-} 1
+test html-2.1 {html::head, not enough args} -body {
+ html::head
+} -returnCodes error -result {wrong # args: should be "html::head title"}
-test html-2.2 {html::head} {
+test html-2.2 {html::head} -body {
html::head "The Title"
-} "