Version 11 of WBuilder

Updated 2006-09-07 20:29:27

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 {<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">}
   puts $Handle {<html>}
   puts $Handle {<head>}
   puts $Handle "  <title>Orphi.net: $Title</title>"
   puts $Handle {  <link rel="stylesheet" type="text/css" href="Root.css"/>}

   foreach Script $Scripts {puts $Handle "  <script language=\"JavaScript\" href=\"$Script\"></script>"}

   puts $Handle {</head>}
   puts $Handle {<body>}
   puts $Handle {}
   puts $Handle "<h1>$Title</h1>"
   puts $Handle {}
 }

 proc WriteBreadcrumbs {Handle Title Crumbs} \
 {
   puts $Handle {<p class="breadcrumbs">}
   puts $Handle {You are here:}

   foreach Crumb $Crumbs {puts $Handle "<a href=\"[lindex $Crumb 0]\">[lindex $Crumb 1]</a> &rarr;"}

   puts $Handle "<strong>$Title</strong>"
   puts $Handle {</p>}
   puts $Handle {}
 }

 proc WriteLinks {Handle Links} \
 {
   puts $Handle {<p class="links">}

   foreach Link $Links {puts $Handle "&lang;<a href=\"[lindex $Link 0]\">[lindex $Link 1]</a>&rang;"}

   puts $Handle {</p>}
   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 {<hr/>}
   puts $Handle {}
   puts $Handle {<p class="build">}
   puts $Handle "Built by WBuilder $Version at $DateTime."
   puts $Handle {</p>}
   puts $Handle {}
   puts $Handle {<p>}
   puts $Handle {<a href="http://validator.w3.org/check?uri=referer">}
   puts $Handle {<img src="http://www.w3.org/Icons/valid-xhtml10" width="88" height="31" alt="Valid XHTML 1.0 Strict"/>}
   puts $Handle {</a>}
   puts $Handle {<a href="http://jigsaw.w3.org/css-validator/check/referer">}
   puts $Handle {<img src="http://jigsaw.w3.org/css-validator/images/vcss" width="88" height="31" alt="Valid CSS"/>}
   puts $Handle {</a>}
   puts $Handle {</p>}
   puts $Handle {}
   puts $Handle {</body>}
   puts $Handle {</html>}
 }

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


Credits:

Created by The Mathematical Orchid.


Category Internet