Update of "TH1-Hooks"
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
| Artifact ID: | a37c1ef707258b0fd40f35a5d707e936cd7f41e3 |
|---|---|
| Page Name: | TH1-Hooks |
| Date: | 2015-02-09 02:48:55 |
| Original User: | mario |
| Mimetype: | text/x-markdown |
| Parent: | c1f97dfec07d2d75739326b758d7a6ae7b7c81b0 (diff) |
| Next | 77009d3170c0ba311d8c2649a55e54090133837f |
Since Fossil 1.30 it's possible to extend both the CLI and web interface with new functionality / or gimmicks. Use --with-th1-hooks for compilation and the th1-hooks repo setting. Extension callbacks must reside in the th1-setup setting field .
Web hooks
Simply craft a webpage_hook function.
proc webpage_hook {} {
puts $::web_name;
continue;
}
The global var $::web_name is populated with the currently requested pagename. It can be one of the built-in functions (wiki, index, home, artifact, etc) or a new custom name. It should preferrably only engage for custom URL paths of course.
An accompanying webpage_notify can be defined, which would be called after page processing.
proc webpage_notify {} {
# Everything went well
}
Order
webpage_hookis always invoked first.- Fossils built-in pages thereafter, if no
breakwas used orTH_ERRORcaused. webpage_notifyruns last, whencontinue,returnorTH_OKwere returned from the_hookcallback.
Vars
- The vars
$::web_argsand$::web_flagsare seldomly useful here, as they and just inheritfossil server/ui/cgistartup args. - Use
set name [getParameter name ""]instead to get URL params. (The first path info argument to after URL command name will be applied, or a?name=param looked up.)
CLI command hooks
The same process applies to command_hook (called first) and command_notify (called after internal command processing). The variable names $::cmd_name, $::cmd_args, $::$cmd_flags are in particular useful to implement new and custom fossil mycmd stuff.
Examples in hooks.th1
The hooks.th1 feature setup script currently defines three web hooks:
/changelogwill output a NEWS-style timeline/changelog./cat/filenameought to output the latest checkin with the given filename. It's intended as simpler alternative to/raw/fn?name=uuid. It doesn't work yet due toCONTENT()being inavailable in TH1 queries for security reasons./uri-listinstead outputs local paths for each filename to/raw/fn?name=uuid.
To apply them for testing, use:
fossil setting th1-setup "$(cat *.th1)"
(Or copy it in per Admin UI > Settings. Note that fossil ui/server needs to be restarted, because the th1-setup code is only evaluated once.)