|
From: Ed S. <ed...@ee...> - 2002-06-09 14:51:27
|
I spent half the day yesterday working on XMLGEN, mostly doing cleanup
to make the code work on my TCL installation (8.4a4, Windows 2000) and
more easy to work with.
One fairly major step I took was avoiding any potentially disruptive
changes to core TCL commands (i.e., renaming puts to tclputs) by using
the proc "putx" (which means "put xml") instead of a modified puts ("put
string"). Since this is mostly used internally to XMLGEN/HTMLGEN, I
don't think the change should cause anyone any heartburn. It will
certainly result in less heartburn for users who would otherwise have to
change any code that uses the "puts" command, e.g., for writing out html
to files.
Now I'm working on a WEBUTILS extension that preprocesses plain text
into proto-html with links, formatted spans, and smart quotes:
#<<<<<<<<<<<< LINKSUB >>>>>>>>>>>>>>#
# linksub ?-class <class>? ?-wwwclass <wwwclass>? ?-domains <list>?
?-autowww? subList string
# class = CSS class name for normal links
# wwwclass = CSS class name for links starting with "www."
# domains = list of recognized domains, without leading "."
# subList = keyword/link pairs. "http://" will be added if
# omitted and link is to a known domain from optional
# list -domains <list>
# Modifies string in stringName
#<<<<<<<<<<<< SPANSUB >>>>>>>>>>>>>>#
# spansub stringName subList
# subList = keyword/class pairs.
# Modifies string in stringName
#<<<<<<<<<<<< PUNCTSUB >>>>>>>>>>>>>>#
# punctsub ?-smart? stringName subList
# smart = specify if proc should try using smart quotes
# Modifies string in stringName
Please take a look at the diffs below and reply with any comments before
I do the commit.
Thanks, Ed
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/LICENSE,v
retrieving revision 1.1
diff -r1.1 LICENSE
15c15
< * The name of the contributors may be used to endorse or promote
---
> * The name of the contributors may not be used to endorse or promote
Index: htmlgen.tcl
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/htmlgen.tcl,v
retrieving revision 1.2
diff -r1.2 htmlgen.tcl
18c18
< namespace import ::xmlgen::buffer ::xmlgen::put ::xmlgen::esc
---
> namespace import -force ::xmlgen::buffer ::xmlgen::put ::xmlgen::esc
56a57,58
> # Note: import of 'dir' will overwrite TCL's internal 'dir' command,
> # which is used in TKCON but probably not otherwise
91c93
< puts "<pre>[esc $::errorInfo]</pre>"
---
> putx "<pre>[esc $::errorInfo]</pre>"
93c95
< puts "<pre>cgi script error encountered</pre>"
---
> putx "<pre>cgi script error encountered</pre>"
112c114
< if {"[file tail $argv0]"!=[file tail [info script]]} return
---
> if { ![string match "[file tail $argv0]" [file tail [info script]] ]
} return
115c117
< namespace import ::htmlgen::*
---
> namespace import -force ::htmlgen::*
142,143c144,145
< puts [th style=$CuteStyle Eins]
< puts [th Zwei]
---
> putx [th style=$CuteStyle Eins]
> putx [th Zwei]
185c187
< puts $Page
---
> putx $Page
Index: pkgIndex.tcl
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/pkgIndex.tcl,v
retrieving revision 1.3
diff -r1.3 pkgIndex.tcl
1c1
< # I must admit that I find it much easier to write a pkgIndex.tcl by
---
> # HK: I must admit that I find it much easier to write a pkgIndex.tcl by
2a3
> # EAS: Sounds fine, but tightened up the structure of the code
8d8
<
12,31c12,30
<
< ##### xmlgen #####
< set script [subst -nocommands {
< namespace eval ::xmlgen [list set VERSION $VERSION]
< namespace eval ::xmlgen [list set VERDATE $VERDATE]
< package provide xmlgen $VERSION
< source [file join "$dir" xmlgen.tcl]
< }]
< package ifneeded xmlgen $VERSION $script
<
<
< ##### htmlgen #####
< set script [subst -nocommands {
< namespace eval ::htmlgen [list set VERSION $VERSION]
< namespace eval ::htmlgen [list set VERDATE $VERDATE]
< source [file join "$dir" htmlgen.tcl]
< source [file join "$dir" tab.tcl]
< source [file join "$dir" sidenav.tcl]
< }]
< package ifneeded htmlgen $VERSION $script
---
> # Define the package names and sourced script files
> set packageSetupList {
> xmlgen {xmlgen.tcl}
> htmlgen {htmlgen.tcl tab.tcl sidenav.tcl webutils.tcl}
> webutils {webutils.tcl}
> parse {parse.tcl}
> }
>
> # Now setup the packages
> foreach {i j} $packageSetupList {
> set script [subst -nocommands {
> eval namespace eval ::$i [list set VERSION $VERSION]
> eval namespace eval ::$i [list set VERDATE $VERDATE]
> }]
> foreach {k} $j {
> set script "$script ;source \[file join \"$dir\" $k\]"
> }
> package ifneeded $i $VERSION $script
> }
\ No newline at end of file
Index: sidenav.tcl
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/sidenav.tcl,v
retrieving revision 1.1
diff -r1.1 sidenav.tcl
14d13
< namespace export sidenav
16,17c15,18
< ## default values for configurable attributes of sidenav
< set sidenavDefaultAttrs {
---
> namespace export sidenav
>
> ## default values for configurable attributes of sidenav
> set sidenavDefaultAttrs {
26,27c27
< navByUrl 0
< }
---
> navByUrl 1
32d31
< ##
37c36
< proc ::htmlgen::sidenav::onerow {text level} {
---
> proc onerow {text level} {
44a44,45
>
>
48c49
< proc ::htmlgen::sidenav::digTree {current tree} {
---
> proc digTree {current tree} {
59,60c60,62
< ##
< ## renders a navigation tree along a path given by $current leading
---
>
> ########################################################################
> ## Render a navigation tree along a path given by $current leading
66c68
< ## We descent into subtrees only if $current really selects one of
---
> ## We descend into subtrees only if $current really selects one of
70c72
< proc ::htmlgen::sidenav::renderTree {ID url current tree} {
---
> proc renderTree {ID url current tree} {
121a124
>
134c137,138
< proc ::htmlgen::sidenav::sidenav {pathvar url tree args} {
---
>
> proc sidenav {pathvar url tree args} {
154,166d157
< ## If sourced by another script, its time to return
< if {"-test"!=[lindex $argv 0]} return
< set argv [lrange $argv 1 end]
<
<
<
< ## TEST CODE
< set auto_path [concat /home/kir/work /usr/local/lib $auto_path]
< #puts $auto_path
< package require tcllib
< package require htmlgen
< namespace import htmlgen::*
< namespace import ::htmlgen::sidenav::*
168,180c159,182
<
<
<
< puts "Content-Type: text/html\n"
< ::ncgi::parse
<
< set navtree {
< home Home .
< tcl Tcl {
< kit TclKit .
< w83 Wish83 {
< story Story .
< doc Documentation .
---
> set testScript {
> ## BEGIN TEST SCRIPT
> set auto_path [concat . /home/kir/work /usr/local/lib $auto_path]
> foreach {i} {tcllib htmlgen ncgi} { package require $i }
> namespace import -force htmlgen::*
> namespace import -force ::htmlgen::sidenav::*
>
> # Start of HTML Content
> ::ncgi::parse
>
> set navTree {
> home Home .
> tcl Tcl {
> kit TclKit .
> w83 Wish83 {
> story Story .
> doc Documentation .
> }
> fw FreeWrap .
> }
> perl Perl {
> bad {Perl No Fun} .
> doc {NO DOCS} .
> }
182,208c184,206
< fw FreeWrap .
< }
< perl Perl {
< bad {Perl No Fun} .
< doc {NO DOCS} .
< }
< }
<
< html ! {
< body ! {
< set url [ncgi::urlStub]
< set Path [ncgi::value Path {tcl}]
< sidenav Path $url $navtree nav.bgcolor=\#dddd55
txt.bgcolor=\#dddd00 ! {
< h2 - Some Information about [join $Path /]
< p + {
< The selected path is
< }
< blockquote - [code . Path="$Path"].
< p + {
< Depending on that,
< we could have different content introduced here in several
< ways, e.g.
< }
< ul ! {
< li - use a [code switch on \$Path]
< li - access a content array like [code \$Content(\$Path)]
< li - source a file depending on \$Path
---
>
> html ! {
> body ! {
> set url [ncgi::urlStub]
> set path [ncgi::value path {tcl}]
> sidenav path $url $navTree nav.bgcolor=\#dddd55
txt.bgcolor=\#dddd00 ! {
> h2 - Some Information about [join $path /]
> p + {
> The selected path is
> }
> blockquote - [code . path="$path"].
> p + {
> Depending on that,
> we could have different content introduced here in several
> ways, e.g.
> }
> ul ! {
> li - use a [code switch on \$path]
> li - access a content array like [code \$Content(\$path)]
> li - source a file depending on \$path
> }
> table ! tr ! td height=1000 - " "
> }
210d207
< table ! tr ! td height=1000 - " "
212c209,212
< }
---
> # Finish with regular puts to end with newline
> puts {}
>
> ### END TEST SCRIPT
213a214,222
>
> ### END NAMESPACE
> }
>
> # Execute test script if -test option specified
> if { [string match "-test" [lindex $argv 0]] } {
> ::xmlgen::buffer html $::htmlgen::sidenav::testScript
> set fh [open test.html w]; puts $fh $html; close $fh
> }
\ No newline at end of file
Index: tab.tcl
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/tab.tcl,v
retrieving revision 1.1
diff -r1.1 tab.tcl
88,89c88
< set auto_path [concat /home/kir/work /usr/local/lib $auto_path]
< #puts $auto_path
---
> set auto_path [concat . /home/kir/work /usr/local/lib $auto_path]
92,93c91,92
< namespace import htmlgen::*
< namespace import ::htmlgen::extra::*
---
> namespace import -force htmlgen::*
> namespace import -force ::htmlgen::extra::*
96c95
< puts "Content-Type: text/html\n"
---
> putx "Content-Type: text/html\n"
129c128
< puts [b Ooooops]
---
> putx [b Ooooops]
145c144
< puts [title . a test tab]
---
> putx [title . a test tab]
147c146
< puts $Page
---
> putx $Page
Index: xmlgen.tcl
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/xmlgen.tcl,v
retrieving revision 1.2
diff -r1.2 xmlgen.tcl
50,51c50,54
< rename ::puts ::xmlgen::tclputs
< interp alias {} ::puts {} ::xmlgen::tclputs
---
>
> ## EAS: This is very confusing and didn't work on my system
> ## Left the original TCL puts alone and called our proc "putx" instead
> # rename ::puts ::xmlgen::tclputs
> interp alias {} ::putx {} ::xmlgen::putx
61c64
< proc puts {args} {
---
> proc putx {args} {
63c66
< if {"-nonewline"==[lindex $args $i]} {
---
> if { "-nonewline" == [lindex $args $i] } {
72,73c75,76
< if {[llength $args]-$i!=1} {
< eval tclputs $args
---
> if { [llength $args]-$i != 1 } {
> eval puts $args
88c91
< tclputs -nonewline [join $args]
---
> puts -nonewline [join $args]
100c103
< interp alias {} ::puts {} ::xmlgen::puts
---
> interp alias {} ::putx {} ::xmlgen::putx
102c105,107
< interp alias {} ::puts {} ::xmlgen::tclputs
---
> # EAS: Let's not do the confusing alias to tclputs anymore, because
> # original puts is now left intact
> # interp alias {} ::putx {} ::xmlgen::tclputs
289c294
< if {"[file tail $argv0]"!=[file tail [info script]]} return
---
> if { ![string match "[file tail $argv0]" [file tail [info script]] ]
} return
296c301
< namespace import ::xmlgen::*
---
> namespace import -force ::xmlgen::*
303c308
< puts dddddddddddddddddd
---
> putx dddddddddddddddddd
307c312
< puts dddddddddddddddddd
---
> putx dddddddddddddddddd
310c315
< puts ||$Page||
---
> putx ||$Page||
Index: doc/common.tcl
===================================================================
RCS file: /cvsroot/tclxml/xmlgen/doc/common.tcl,v
retrieving revision 1.1
diff -r1.1 common.tcl
80c80
< lappend l [a href=$url?[cgiset Path $p] $text]
---
> lappend l [a href=$url?[cgiset path $p] $text]
|