Tcl Library Source Code

Artifact [e9e66b2dd4]
Login

Artifact e9e66b2dd47a2c21ef60cf86eb06d8939030551a:

Attachment "1076403.patch" to ticket [1076403fff] added by anonymous 2014-03-25 12:47:59. (unpublished)
diff -uprN ./orig/html.man ./new/html.man
--- ./orig/html.man	2014-03-24 20:24:41.000000000 +0200
+++ ./new/html.man	2014-03-25 14:12:54.008115512 +0200
@@ -471,6 +471,14 @@ The following id's are defined:
 
 [list_end]
 
+[call [cmd ::html::wrapTag] [arg tag] [opt arg text] [opt arg args]]
+
+This procedure is a helper that can be used to wrap a text in a pair of
+open/close tags.
+The optional args can be used to provide attributes to the tag.
+The result is a string with the open tag along with the optional attributes,
+the optional text, and the closed tag.
+
 [vset CATEGORY html]
 [include ../doctools2base/include/feedback.inc]
 [manpage_end]
diff -uprN ./orig/html.tcl ./new/html.tcl
--- ./orig/html.tcl	2014-03-24 20:24:41.000000000 +0200
+++ ./new/html.tcl	2014-03-25 14:07:21.084119051 +0200
@@ -1504,3 +1504,26 @@ proc ::html::js-clear {} {
     catch { unset page(js) }
     return
 }
+
+# ::html::wrapTag
+#   Takes an optional text and wraps it in a tag pair, along with optional attributes for the tag
+#
+# Arguments:
+#   tag      The HTML tag name 
+#   text     Optional text to insert between open/close tag
+#   args     List of optional attributes and values to use for the tag
+#
+# Results:
+#   String with the text wrapped in the open/close tag
+
+proc ::html::wrapTag {tag {text ""} args} {
+    ::set html ""
+    ::set params ""
+    ::foreach {i j} $args {
+        append params "$i=\"[quoteFormValue $j]\" "
+    }
+    append html [openTag $tag [string trimright $params]]
+    append html $text
+    append html [closeTag]
+    return $html
+}
diff -uprN ./orig/html.test ./new/html.test
--- ./orig/html.test	2014-03-24 20:24:41.000000000 +0200
+++ ./new/html.test	2014-03-25 13:58:50.216124482 +0200
@@ -943,4 +943,27 @@ test html-tktafe4366e2e-38.3 {html::doct
 } -result {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">}
 
 # -------------------------------------------------------------------------
+
+test html-tkt1076403-39.0 {html::wrapTag, not enough args} -body {
+    html::wrapTag
+} -returnCodes error -result {wrong # args: should be "html::wrapTag tag ?text? ?arg ...?"}
+
+test html-tkt1076403-39.1 {html::wrapTag} -body {
+    html::wrapTag p
+} -result {<p></p>}
+
+test html-tkt1076403-39.2 {html::wrapTag} -body {
+    html::wrapTag p "test"
+} -result {<p>test</p>}
+
+test html-tkt1076403-39.3 {html::wrapTag} -body {
+    html::wrapTag p "test" align left
+} -result {<p align="left">test</p>}
+
+test html-tkt1076403-39.4 {html::wrapTag} -body {
+    html::wrapTag pre "test" align left width 20
+} -result {<pre align="left" width="20">test</pre>}
+
+# -------------------------------------------------------------------------
+
 testsuiteCleanup