changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > werc / changeset: Change app loading to be done in two passes, first source app files, then call init for enabled apps.

changeset 347: 0e9e1fb05d01
parent 341: 410b2c763e82
child 348: bc931d0422f4
author: uriel@engel.se.cat-v.org
date: Thu, 22 Jan 2009 09:22:15 +0100
files: bin/werc.rc
description: 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.
     1.1--- a/bin/werc.rc	Tue Jan 20 09:06:28 2009 +0000
     1.2+++ b/bin/werc.rc	Thu Jan 22 09:22:15 2009 +0100
     1.3@@ -99,13 +99,10 @@
     1.4     if not if(test -f $local_path.txt)
     1.5         handler_body_main=(txt_handler $local_path.txt)
     1.6 
     1.7-    # Apps
     1.8-    if(! ~ $#enabled_apps 0) {
     1.9-        for(a in $enabled_apps) {
    1.10-            . ./apps/$a/app.rc
    1.11+    # Apps, XXX: Maybe we should check that $enabled_apps exist in $werc_apps.
    1.12+    if(! ~ $#enabled_apps 0)
    1.13+        for(a in $enabled_apps)
    1.14             $a^'_init'
    1.15-        }
    1.16-    }
    1.17 
    1.18     if(! ~ $#handler_body_main 0)
    1.19         { } # We are done
    1.20@@ -138,6 +135,7 @@
    1.21 master_template=default_master.tpl
    1.22 res_tail='</body></html>'
    1.23 ll_add handlers_bar_left nav_tree
    1.24+werc_apps=( apps/* )
    1.25 werc_root=`{pwd}
    1.26 for(i in siteTitle siteSubTitle pageTitle extraHeaders)
    1.27     $i = ''
    1.28@@ -154,6 +152,9 @@
    1.29 if(test -f etc/initrc.local)
    1.30     . ./etc/initrc.local
    1.31 
    1.32+for(a in $werc_apps)
    1.33+    . ./$a/app.rc
    1.34+
    1.35 # Parse request URL
    1.36 # NOTE: $REQUEST_URI is not officially in CGI 1.1, but seems to be de-facto
    1.37 req_path=`{echo -n $REQUEST_URI | sed 's/\?.*//; s/'^$forbidden_uri_chars^'//g; s/\.\.*/./g; 1q'}
    1.38@@ -181,13 +182,13 @@
    1.39 if not if(test -d $local_path)
    1.40     perm_redirect $req_path^'/'
    1.41 
    1.42-p=()
    1.43 cd $sitedir
    1.44 if(test -f _werc/config)
    1.45     . _werc/config
    1.46+conf_wd='' # This can be used inside config files to know where we are in the document tree.
    1.47 for(i in ('' $args)) {
    1.48-    p=($"p^/^$i)
    1.49-    req_paths_list=($req_paths_list $p)
    1.50+    config_wd=($"config_wd^/^$i)
    1.51+    req_paths_list=($req_paths_list $config_wd)
    1.52     if(test -d $i) {
    1.53         cd $i
    1.54         if(test -f _werc/config)