wiklets

Brian Theado - A wiklet is tclet reaped from a wiki page.

Here is some code that can be added to wikit (lib/app-wikit/start.tcl). It causes page requests like https://wiki.tcl-lang.org/nnn.tcl to reap the preformatted Tcl code from page nnn (a la wiki-reaper). It returns with Content-type=application/x-tcl. If the Tcl/Tk Tclet Plugin is installed (which on windows for Firefox is simple thanks to jeff hobbs--see Obtaining the TCL Plugin), then the code will automatically be executed in the plugin.

KJN The idea suggested here by Brian has been generalised to a patched version of Wikit that reaps only the blocks of source code that belong to a Wiklet, and also adds code to the Wiki page that will execute the Wiklet. See Wiklet Server for details.

I tested this code out on my local machine with tclhttpd and a current snapshot of the Tcler's wiki database and it worked.

# Quick intercept of NNN.tcl page requests.  This is kind of a hack and
# was modelled after the quick intercept of NNN.txt page requests.
catch {
    # Extract preformatted text from the given wiki text
    proc extractTclSourceCode wikiText {
        set stream [Wikit::Format::TextToStream $wikiText]
        set pre {}
        while {[llength $stream] > 0} {
            if {[lindex $stream 0] == "Q"} {
                append pre [lindex $stream 3]\n
                    set stream [lrange $stream 4 end]
                    } else {
                    set stream [lrange $stream 2 end]
                    }
                }
        return $pre
        }
        
    if {$env(REQUEST_METHOD) eq "GET" &&
        [regexp {/(\d+)\.tcl$} $env(REQUEST_URI) - page]} {
        mk::file open xdb $wikidb -readonly
        puts "Content-type: application/x-tcl\n"
        puts "# Title:\t[mk::get xdb.pages!$page name]"
        puts "# Date:\t[clock format [mk::get xdb.pages!$page date] \
            -gmt 1 -format {%e %b %Y %H:%M:%S GMT}]"
        puts "# Site:\t[mk::get xdb.pages!$page who]"
        puts ""
        package require Wikit::Format
        
        # Some programs try to set their title which the plugin doesn't allow 
        puts {proc wm args {}}
        puts -nonewline [extractTclSourceCode [mk::get xdb.pages!$page page]]
        exit
    }
}

I expect that a subset of the pages listed on wish-reaper will work as a wiklet.

Here are some examples I tried:

Worked

Didn't work

  • Rush Hour - 12376 - The menu command is not available in the plugin
  • Word Jumble - 10354 - Call to [file readable] not allowed in plugin
  • Another asteroids - 12601 - Menu command again
  • Car racing in Tcl - 4364 - No error with this one, just that the keybindings had no effect and it couldn't be played