[Fencommits] fenserve: choose view to use on POST depending on whether the line entered was a command

Benja Fallenstein benja.fallenstein at gmail.com
Fri Apr 27 21:09:09 EEST 2007


Fri Apr 27 21:09:03 EEST 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * choose view to use on POST depending on whether the line entered was a command
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs	2007-04-27 21:09:09.000000000 +0300
+++ new-fenserve/notetaker/Main.hs	2007-04-27 21:09:09.000000000 +0300
@@ -20,7 +20,7 @@
 
 data Note = Note String [Note] deriving (Eq,Ord,Read,Show)
 
-form nick = "<form id='myform' action='/log' method='post'>\
+form nick = "<form id='myform' action='/' method='post'>\
             \    Nick: <input name='nick' type='text' size=8 \
                              \value='" ++ nick ++ "'> \
             \    <input name='line' id='myline' type='text' size=60>\
@@ -81,9 +81,9 @@
 renderBody nick body     = printf "<b>%s</b> %s" nick (msg body) where
     msg :: Body -> String
     msg (Add [] l) = printf "<i>adds:</i> %s" l
-    msg (Add p l)  = printf "<i>adds to %s:</i> %s" (renderPath p) l
-    msg (Edit p l) = printf "<i>edits %s:</i> %s" (renderPath p) l
-    msg (Delete p) = printf "<i>deletes %s.</i>" (renderPath p)
+    msg (Add p l)  = printf "<i>adds to '%s':</i> %s" (renderPath p) l
+    msg (Edit p l) = printf "<i>edits '%s':</i> %s" (renderPath p) l
+    msg (Delete p) = printf "<i>deletes '%s'.</i>" (renderPath p)
     
     renderPath = concat . intersperse "." . map (show . (+1))
                
@@ -94,10 +94,10 @@
 main = stdHTTP [ debugFilter
                , h ["log"] GET  $ ok $ \() nick -> renderLog nick
                , h [""]    GET  $ ok $ \() nick -> page nick
-               , h ["log"] POST $ ok $ \() (nick,line) -> do 
-                     time <- getTime
-                     modify (++[Line time nick $ readBody line])
-                     renderLog nick
+               , h ()      POST $ ok $ \() (nick,line) -> do 
+                     time <- getTime; let body = readBody line
+                     modify (++[Line time nick body])
+                     case body of Body _ -> renderLog nick; _ -> page nick
                , h () POST $ ok $ \() () -> respond "Huh."
                ]
 




More information about the Fencommits mailing list