'''What is it?''' I don't know about you, but I find that the most tedious and error-prone part of building a web site of any size is keeping all the links pointing the right way. Thus, I wrote WBuilder to help partially automate the process. ---- '''What does it do?''' The idea is that WBuilder makes it trivial to build a web site with a simple hierachical structure. Just create whatever folders you want, and populate them with *.wb files. Each such file contains some commands for WBuilder itself, and then an incomplete HTML page. WBuilder turns each *.wb file into a real HTML web page, and crosslinks them all automatically. And that is all. ---- '''Detailed Operation''' Each *.wb file becomes a normal HTML file (*.html). WBuilder does this by gluing some (hard-coded) stuff onto the top and bottom of the file. (If nothing else, this means you don't have to type in the 5-mile-long DOCTYPE declaration!) As coded, the headers added include an XHTML-strict DOCTYPE, and a reference to a stylesheet Root.css in the current folder. (But you could change that if you wanted.) Also puts the time of processing, the version of WBuilder, and some links to the W3C validator(s) on the bottom of the page. (Again, you could change if it you wanted.) In addition to this, every single page is given "breadcrumbs" - links that point to every page visited to get to this point. (Due to the strictly hierachical structure, there is only 1 possible path to each page.) On top of that, in every folder a file called Root.html is generated, which links to every file in the current folder, and the Root.html file in every subfolder (if any). (Last but not least, I have just finished a total rewrite of WBuilder to make it ''incremental''. That is, now it only generates ''altered'' pages, in a similar way to the "make" program recompiling C files...) ---- '''Source Code''' The source code consists of 6 seperate files. The one you'll probably want to edit is libWrite.tcl (this is where the hard-coded HTML stuff is). Note that the code contains a slight amount of weirdness because it's designed to be run by [FreeWrap]! Top of File: libWrite.tcl proc WriteHead {Handle Title Scripts} \ { puts $Handle {} puts $Handle {} puts $Handle {} puts $Handle " Orphi.net: $Title" puts $Handle { } foreach Script $Scripts {puts $Handle " "} puts $Handle {} puts $Handle {} puts $Handle {} puts $Handle "

$Title

" puts $Handle {} } proc WriteBreadcrumbs {Handle Title Crumbs} \ { puts $Handle {} puts $Handle {} } proc WriteLinks {Handle Links} \ { puts $Handle {} puts $Handle {} } proc WriteTail {Handle} \ { global Version set DateTime [clock format [clock seconds] -format "%I:%M %p (%Z) on %a %d-%b-%Y"] puts $Handle {
} puts $Handle {} puts $Handle {

} puts $Handle "Built by WBuilder $Version at $DateTime." puts $Handle {

} puts $Handle {} puts $Handle {

} puts $Handle {} puts $Handle {Valid XHTML 1.0 Strict} puts $Handle {} puts $Handle {} puts $Handle {Valid CSS} puts $Handle {} puts $Handle {

} puts $Handle {} puts $Handle {} puts $Handle {} } Bottom of File: libWrite.tcl Top of File: libFile.tcl proc FContents {filename} \ { set IN [open $filename r] set Out [read -nonewline $IN] close $IN return $Out } proc FEmpty {filename} \ { set OUT [open $filename w] close $OUT } proc FWrite {filename data} \ { set OUT [open $filename w] puts $OUT $data close $OUT } Bottom of File: libFile.tcl Top of File: libProcess.tcl proc Process {filename} \ { puts "->Process: $filename" set IN [open "$filename.wb" r] set Title "(No Title)" set Scripts [list] while {![eof $IN]} \ { set Line [gets $IN] if {$Line=="#"} {break} set Line [split $Line ":"] set Key [lindex $Line 0] set Val [lindex $Line 1] if {$Key=="Title"} {set Title $Val} if {$Key=="Script"} {lappend Scripts $Val} } FWrite "$filename.title.tmp" $Title FWrite "$filename.scripts.tmp" $Scripts FWrite "$filename.data.tmp" [read $IN] close $IN } Bottom of File: libProcess.tcl Top of File: '''libBuild.tcl''' proc Build {filename} \ { set RootMode "no" if {[file tail $filename] == "Root"} {set RootMode "yes"} puts "->Build: $filename (Root Mode = $RootMode)" set Dir [file dirname $filename] set Title [FContents "$filename.title.tmp"] set Scripts [FContents "$filename.scripts.tmp"] set Crumbs [FContents [file join $Dir "Crumbs.tmp"]] if {!$RootMode} {lappend Crumbs [list "Root.html" [FContents [file join $Dir "Root.title.tmp"]]]} set OUT [open $filename.html w] WriteHead $OUT $Title $Scripts WriteBreadcrumbs $OUT $Title $Crumbs if {$RootMode} {WriteLinks $OUT [CollectLinks $Dir]} puts $OUT [FContents "$filename.data.tmp"] WriteTail $OUT close $OUT } proc CollectLinks {dirname} \ { puts "--->CollectLinks: $dirname" set Out [list] set Subs [glob -nocomplain -types d -directory $dirname -tails *] set Subs [lsort -ascii $Subs] foreach Sub $Subs \ { set File [file join $Sub "Root.html"] set Title [FContents [file join $dirname $Sub "Root.title.tmp"]] lappend Out [list $File $Title] } set Files [glob -nocomplain -types f -directory $dirname -tails *.wb] set Files [lsort -ascii $Files] foreach File $Files \ { if {$File=="Root.wb"} {continue} set Root [file rootname $File] set F "$Root.html" set T [FContents [file join $dirname "$Root.title.tmp"]] lappend Out [list $F $T] } return $Out } proc MakeCrumbs {dirname} \ { puts "->MakeCrumbs: $dirname" set Parent [file dirname $dirname] set Crumbs [FContents [file join $Parent "Crumbs.tmp"]] lappend Crumbs [list "Root.html" [FContents [file join $Parent "Root.title.tmp"]]] set Out [list] foreach Crumb $Crumbs \ { set File [lindex $Crumb 0] set Title [lindex $Crumb 1] set File [file join ".." $File] lappend Out [list $File $Title] } FWrite [file join $dirname "Crumbs.tmp"] $Out } Bottom of File: '''libBuild.tcl''' ---- '''Credits:''' Created by [The Mathematical Orchid]. ---- [Category Internet]