File: parray_table.tcl

package info (click to toggle)
libapache2-mod-rivet 2.3.3-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,156 kB
  • ctags: 1,093
  • sloc: xml: 7,696; tcl: 6,939; ansic: 5,682; sh: 4,862; makefile: 199; sql: 91; lisp: 78
file content (40 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
##
## -- parray_table <arrayName> ?pattern? ?html-attibutes?
##
##	tablearray prints an array data in HTML table
##	This is good when a table is enough to print consistently
##	related data. 
##
##	arrayName - Name of the array to display
##	pattern   - Wildcard pattern of variables. An empty string 
##		        is tantamout a "*" and prints the whole array
##	html-attributes - 
##              list attribute-value pairs to be given
##              to the <table> element tag
##
## $Id: parray_table.tcl 1523202 2013-09-14 10:07:25Z mxmanghi $
##
##

namespace eval ::rivet {

    proc parray_table {arrayName {pattern "*"} {htmlAttributes ""}} {
        upvar 1 $arrayName array
        if {![array exists array]} {
            return -code error "\"$arrayName\" isn't an array"
        }
        puts -nonewline stdout "<table"
	    foreach {attr attrval} $htmlAttributes {
	        puts -nonewline " $attr=\"$attrval\""
	    }

	    puts "><thead><tr><th colspan=\"2\">$arrayName</th></tr></thead>"
        puts stdout "<tbody>"
        foreach name [lsort [array names array $pattern]] {
            puts stdout [format "<tr><td>%s</td><td>%s</td></tr>" [::rivet::escape_sgml_chars $name]    \
                                                                  [::rivet::escape_sgml_chars $array($name)]]
        }
        puts stdout "</tbody></table>"
    }

}