[PATCH 1/2] bin/handlers: roll up repeated code

From: Strake <strake888_AT_gmail.com>
Date: Wed, 3 Jul 2013 07:26:16 -0500

---
 bin/handlers.rc | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/bin/handlers.rc b/bin/handlers.rc
index cca6495..2055ed4 100644
--- a/bin/handlers.rc
+++ b/bin/handlers.rc
_AT_@ -54,6 +54,10 @@ fn man_handler {
     echo '</pre>'
 }
+fn 1_handler {
+    man_handler $*
+}
+
 fn dir_listing_handler {
     d=`{basename -d $1}
     if(~ $#d 0)
_AT_@ -65,19 +69,12 @@ fn dir_listing_handler {
 }
 fn setup_handlers {
-    if(test -f $local_path.md) {
-        local_file=$local_path.md
-        handler_body_main=(md_handler $local_file)
-    }
-    if not if(test -f $local_path.1) {
-        local_file=$local_path.1
-        handler_body_main=(man_handler $local_file)
-    }
-    if not if(test -f $local_path.tpl) {
-        local_file=$local_path.tpl
-        handler_body_main=(tpl_handler $local_file)
+    local_file=()
+    for(suffix in md 1 tpl) if(test -f $local_path.$suffix) {
+        local_file=$local_path.$suffix
+        handler_body_main=($suffix^_handler $local_file)
     }
-    if not if(test -f tpl^$req_path^.tpl)
+    if(~ $#local_file 0 && test -f tpl^$req_path^.tpl)
         handler_body_main=(tpl_handler tpl^$req_path^.tpl)
     if(! ~ $#handler_body_main 0)
         { } # We are done
-- 
1.7.11.1
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Thu Jul 04 2013 - 05:48:02 CEST