chiark / gitweb /
Read user.tmpl after macros.tmpl
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 18:46:53 +0000 (19:46 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 18 May 2008 18:46:53 +0000 (19:46 +0100)
doc/disorder_templates.5.head
doc/disorder_templates.5.tail
lib/macros-builtin.c
lib/macros.h
server/actions.c
server/options.c

index 4170c32966c7ee16bcd44986a03321d1f6157257..5efeef07286f08aad07d141a1080a16513ebf312 100644 (file)
@@ -84,15 +84,31 @@ In the case of a macro you can work around this by passing the value as an
 argument.
 Included files do not have arguments, so in this case you must rewrite the
 inclusion as a macro.
-.SS macros.tmpl
-Before any page is expanded, the CGI will process \fBmacros.tmpl\fR (and
-discard any output).
-This defines a collection of commonly used macros.
 .SS "Search Path"
-Template files a first searched for in \fIpkgconfdir\fR and then in
+All template files are first searched for in \fIpkgconfdir\fR and then in
 \fIpkgdatadir\fR.
+.SS "macros.tmpl and user.tmpl"
+Before any template is expanded, the CGI will process \fBmacros.tmpl\fR and
+discard any output.
+This defines a collection of commonly used macros.
+.PP
+Following this the CGI will process \fBuser.tmpl\fR, again discarding output.
+This can be used to override the common macros without editing the installed
+version of \fBmacros.tmpl\fR, or to define new ones.
+.PP
+It is not an error if \fBuser.tmpl\fR does not exist.
+.SS "Character Encoding"
+The CGI does not (currently) declare any character encoding.
+This could be changed quite easily but in practice is not a pressing necessity.
+.PP
+The recommended approach is to treat the templates as ASCII files and if
+non-ASCII characters are required, use HTML entities to represent them.
+.PP
+For example, to represent the copyright sign, use \fB&copy;\fR or \fB&#xA9;\fR.
+.PP
+If you know the decimal or hex unicode value for a character then you can use
+\fB&#NNN;\fR or \fB&#xHHHH;\fR respectively.
 .SH EXPANSIONS
-This section lists the supported expansions.
 .\" Local Variables:
 .\" mode:nroff
 .\" fill-column:79
index 0c88a6d8c47964b49cf6aa0292cb365e1b5eda2a..e43e86f8a03de10efaf23bb2124197b5e3e79e0e 100644 (file)
 .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 .\" USA
 .\"
-.SH "NOTES"
-.SS "Character Encoding"
-The CGI does not (currently) declare any character encoding.
-This could be changed quite easily but in practice is not a pressing necessity.
-.PP
-The recommended approach is to treat the templates as ASCII files and if
-non-ASCII characters are required, use HTML entities to represent them.
-.PP
-For example, to represent the copyright sign, use \fB&copy;\fR or \fB&#xA9;\fR.
-.PP
-If you know the decimal or hex unicode value for a character then you can use
-\fB&#NNN;\fR or \fB&#xHHHH;\fR respectively.
 .SH "SEE ALSO"
 .BR disorder_actions (5),
 .BR disorder_options (5),
-.BR disorder_config (5) (5),
+.BR disorder_config (5),
 .BR disorder.cgi (8)
 .\" Local Variables:
 .\" mode:nroff
index 24822bbf66d783e5fe1d30b3749a853a67d1dd8d..04ea4900a09d85e37d4835190fe08837cebec1cb 100644 (file)
@@ -71,13 +71,14 @@ int mx_bool_result(struct sink *output, int result) {
 }
 
 /** @brief Search the include path */
-char *mx_find(const char *name) {
+char *mx_find(const char *name, int report) {
   char *path;
   int n;
   
   if(name[0] == '/') {
     if(access(name, O_RDONLY) < 0) {
-      error(errno, "cannot read %s", name);
+      if(report)
+        error(errno, "cannot read %s", name);
       return 0;
     }
     path = xstrdup(name);
@@ -89,7 +90,8 @@ char *mx_find(const char *name) {
         break;
     }
     if(n >= include_path.nvec) {
-      error(0, "cannot find '%s' in search path", name);
+      if(report)
+        error(0, "cannot find '%s' in search path", name);
       return 0;
     }
   }
@@ -123,7 +125,7 @@ static int exp_include(int attribute((unused)) nargs,
   char buffer[4096];
   struct stat sb;
 
-  if(!(path = mx_find(args[0]))) {
+  if(!(path = mx_find(args[0], 1/*report*/))) {
     if(sink_printf(output, "[[cannot find '%s']]", args[0]) < 0)
       return 0;
     return 0;
index 772873c44d5ba68567c435539da99a551ef5fcef..e9b0af5250f1166ea796a6a199196b00b79f189e 100644 (file)
@@ -106,7 +106,7 @@ int mx_register_macro(const char *name,
 
 void mx_register_builtin(void);
 void mx_search_path(const char *s);
-char *mx_find(const char *name);
+char *mx_find(const char *name, int report);
 
 int mx_expand_file(const char *path,
                    struct sink *output,
index 961fdec3e1b536ef21c761100f04e097eb6a0b09..1372733c0463bf175be80850827758821aefa616 100644 (file)
@@ -731,13 +731,15 @@ void dcgi_expand(const char *name, int header) {
   const char *p, *found;
 
   /* Parse macros first */
-  if((found = mx_find("macros.tmpl")))
+  if((found = mx_find("macros.tmpl", 1/*report*/)))
+    mx_expand_file(found, sink_discard(), 0);
+  if((found = mx_find("user.tmpl", 0/*report*/)))
     mx_expand_file(found, sink_discard(), 0);
   /* For unknown actions check that they aren't evil */
   if(!dcgi_valid_action(name))
     fatal(0, "invalid action name '%s'", name);
   byte_xasprintf((char **)&p, "%s.tmpl", name);
-  if(!(found = mx_find(p)))
+  if(!(found = mx_find(p, 0/*report*/)))
     fatal(errno, "cannot find %s", p);
   if(header) {
     if(printf("Content-Type: text/html\n"
index 0453cd7b9268a7dcbb3b336e4d12d75f61a82ff4..68f827157726d74d2c3229764a2a15bc8cd9048d 100644 (file)
@@ -83,7 +83,7 @@ static void option__readfile(const char *name) {
   char **vec, *buffer;
   struct read_options_state cs;
 
-  if(!(cs.name = mx_find(name)))
+  if(!(cs.name = mx_find(name, 1/*report*/)))
     return;
   if(!(fp = fopen(cs.name, "r")))
     fatal(errno, "error opening %s", cs.name);