Update of "TH1-Hooks"
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Artifact ID: | 584aac19e14de40976a715a4ab13d563cf47a246 |
---|---|
Page Name: | TH1-Hooks |
Date: | 2015-02-09 02:46:37 |
Original User: | mario |
Mimetype: | text/x-markdown |
Parent: | 9bb8878d9238afe2dc13515ce8f030a32b658b13 (diff) |
Next | c1f97dfec07d2d75739326b758d7a6ae7b7c81b0 |
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. Extensions callbacks must reside in the th1-setup setting.
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_hook
is always invoked first.- Fossils built-in pages thereafter, if no
break
was used orTH_ERROR
caused. webpage_notify
runs last, whencontinue
,return
orTH_OK
were returned from the_hook
callback.
Vars
- The vars
$::web_args
and$::web_flags
are seldomly useful here, as they and just inheritfossil server/ui/cgi
startup 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:
/changelog
will output a NEWS-style timeline/changelog./cat/filename
ought 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-list
instead outputs local paths for each filename to/raw/fn?name=uuid
.