Change app loading to be done in two passes, first source app files, then call init for enabled apps.

This makes it possible to call app functions at config time.
Provide $conf_wd variable at config time, which can in turn be used by apps to determine where in the tree we are at config/setup time.
This commit is contained in:
Uriel 2009-01-22 09:22:15 +01:00
parent f2bfe0d665
commit efac1136d0

View file

@ -99,13 +99,10 @@ fn setup_handlers {
if not if(test -f $local_path.txt) if not if(test -f $local_path.txt)
handler_body_main=(txt_handler $local_path.txt) handler_body_main=(txt_handler $local_path.txt)
# Apps # Apps, XXX: Maybe we should check that $enabled_apps exist in $werc_apps.
if(! ~ $#enabled_apps 0) { if(! ~ $#enabled_apps 0)
for(a in $enabled_apps) { for(a in $enabled_apps)
. ./apps/$a/app.rc
$a^'_init' $a^'_init'
}
}
if(! ~ $#handler_body_main 0) if(! ~ $#handler_body_main 0)
{ } # We are done { } # We are done
@ -138,6 +135,7 @@ headers=lib/headers.tpl
master_template=default_master.tpl master_template=default_master.tpl
res_tail='</body></html>' res_tail='</body></html>'
ll_add handlers_bar_left nav_tree ll_add handlers_bar_left nav_tree
werc_apps=( apps/* )
werc_root=`{pwd} werc_root=`{pwd}
for(i in siteTitle siteSubTitle pageTitle extraHeaders) for(i in siteTitle siteSubTitle pageTitle extraHeaders)
$i = '' $i = ''
@ -154,6 +152,9 @@ current_date_time=`{date}
if(test -f etc/initrc.local) if(test -f etc/initrc.local)
. ./etc/initrc.local . ./etc/initrc.local
for(a in $werc_apps)
. ./$a/app.rc
# Parse request URL # Parse request URL
# NOTE: $REQUEST_URI is not officially in CGI 1.1, but seems to be de-facto # NOTE: $REQUEST_URI is not officially in CGI 1.1, but seems to be de-facto
req_path=`{echo -n $REQUEST_URI | sed 's/\?.*//; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'} req_path=`{echo -n $REQUEST_URI | sed 's/\?.*//; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'}
@ -181,13 +182,13 @@ if(~ $local_path */) {
if not if(test -d $local_path) if not if(test -d $local_path)
perm_redirect $req_path^'/' perm_redirect $req_path^'/'
p=()
cd $sitedir cd $sitedir
if(test -f _werc/config) if(test -f _werc/config)
. _werc/config . _werc/config
conf_wd='' # This can be used inside config files to know where we are in the document tree.
for(i in ('' $args)) { for(i in ('' $args)) {
p=($"p^/^$i) config_wd=($"config_wd^/^$i)
req_paths_list=($req_paths_list $p) req_paths_list=($req_paths_list $config_wd)
if(test -d $i) { if(test -d $i) {
cd $i cd $i
if(test -f _werc/config) if(test -f _werc/config)