jWebTools is an open-source, pure Tcl extension with tools and utilities for constructing simple or elaborate websites. The building blocks in jWebTools provide a basis for producing almost any kind of web page. Authors have the option to write pages in object-oriented or conventional Tcl syntax, either way both static and dynamic content are supported. jWebTools is aimed primarily at experienced Tcl programmers with good knowledge of html, css, javascript, client-server practices and administration.
The jWebTools project contains a number of components (few or no internal dependencies) that can be applied in general Tcl programming. CmdArg is particularly useful, providing a command line interface to any proc or method. See list of jWebTools features below for all options.
For details see website and fossil repo. Documentation is available online as well as in PDF format (cf., archive documentation directory or fossil repo).
Web elements are represented by TclOO classes. For example, the <html> tag is rendered by the Html class. Similarly, the Body class emits the <body> tag with attributes and contents of <body>.
A web page is created by subclassing Html. Alternatively in a namespace using Tag::* namespace procedures. jWebTools provides the ::Tag namespace which defines procs that return "ready to use" element objects. For example, Tag::Html: (note the trailing colon) when invoked returns an Html object.
Using the object-oriented approach:
package require jwebtools oo::class create MyPage { superclass Html constructor {} { next -head [my mkHead] -body [my mkBody] \ outfile mypage.html } method mkHead {} { Head new -Es [subst { [Title new "My Great Page"] [Link new -href /css/mypage.css -type /text/css] ... }] } method mkBody {} { Body new -Es [subst { [Div new ...] ... }] } } # Render output (mypage.html) [MyPage new] write
Same, using namespace notation:
package require jwebtools namespace eval MyPage { namespace import ::Tag::* proc construct {} { variable html [Html: -head [mkHead] -body [mkBody] \ outfile mypage.html] } proc render {} { variable html construct $html write } proc mkHead {} { Head: -Es [subst { [Title: "My Great Page"] [Link: -href /css/mypage.css -type /text/css] ... }] } proc mkBody {} { Body: -Es [subst { [Div: ...] ... }] } } # Render output (mypage.html) MyPage::render
The *.tcl files in the Examples directory of the fossil repo show complete class and namespace versions of the same web page. The Demo directory README gives step-by-step instructions for rendering html output and using the jWebTools web server to view the page in a browser.