You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2012/12/31 00:03:03 UTC
svn commit: r1427017 - in /tcl/rivet/trunk: ChangeLog rivet/rivet-tcl/xml.tcl
Author: mxmanghi
Date: Sun Dec 30 23:03:03 2012
New Revision: 1427017
URL: http://svn.apache.org/viewvc?rev=1427017&view=rev
Log:
* rivet/rivet-tcl/xml.tcl: revised command for simple XML string mark up
Modified:
tcl/rivet/trunk/ChangeLog
tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl
Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1427017&r1=1427016&r2=1427017&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Sun Dec 30 23:03:03 2012
@@ -1,3 +1,6 @@
+2012-12-30 Massimo Manghi <mx...@apache.org>
+ * rivet/rivet-tcl/xml.tcl: revised command for simple XML string mark up
+
2012-12-18 Massimo Manghi <mx...@apache.org>
* src/librivet/rivetPkgInit.c: package version taken from preprocessor symbol
RIVET_VERSION so that it's guaranteed mod_rivet.c will get the right library
Modified: tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl?rev=1427017&r1=1427016&r2=1427017&view=diff
==============================================================================
--- tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl (original)
+++ tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl Sun Dec 30 23:03:03 2012
@@ -3,20 +3,18 @@
#
# Example 1:
#
-# ::rivet::xml Test b i -> <b><i>Test</i></b>
+# ::rivet::xml Test b i
+# <== <b><i>Test</i></b>
#
# Example 2:
#
# ::rivet::xml Test [list div class box id testbox] b i
-#
-# -> <div class="box" id="testbox"><b><i>Test</i></b></div>
+# <== <div class="box" id="testbox"><b><i>Test</i></b></div>
#
# Example 3
#
-# set d [list div [list a 1 b 2] b [list c 3 d 4] i [list e 5 f 6]]
-# ::rivet::xml Test {*}$d
-#
-# -> <div a="1" b="2"><b c="3" d="4"><b c="3" d="4"><i e="5" f="6">Test</i></b></div>
+# ::rivet::xml "anything ..." div [list a href "http://..../" alt "alternate message"]
+# <== <div><a href="http://..../" alt="alternate message">anything ...</a></div>
#
# $Id: $
#
@@ -25,27 +23,27 @@ namespace eval ::rivet {
proc xml {textstring args} {
- set xmlout ""
- set tags_stack {}
+ set xmlout ""
+ set tags_stack {}
foreach el $args {
- set tag [lindex $el 0]
- set tags_stack [linsert $tags_stack 0 $tag]
+ set el [lassign $el tag]
+ lappend tags_stack $tag
append xmlout "<$tag"
- if {[llength $el] > 1} {
-
- foreach {attrib attrib_v} [lrange $el 1 end] {
- append xmlout " $attrib=\"$attrib_v\""
- }
-
- }
+ foreach {attrib attrib_v} $el {
+ append xmlout " $attrib=\"$attrib_v\""
+ }
append xmlout ">"
}
- append xmlout "$textstring</[join $tags_stack ></]>"
-
+ if {[::rivet::lempty $tags_stack]} {
+ return $textstring
+ } else {
+ return [append xmlout "$textstring</[join [lreverse $tags_stack] "></"]>"]
+ }
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org