[Fencommits] fenserve: demo of page for editing resources through a web form

Benja Fallenstein benja.fallenstein at gmail.com
Thu Mar 22 19:49:07 EET 2007


Thu Mar 22 05:54:05 EET 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * demo of page for editing resources through a web form
diff -rN -u old-fenserve/edit-demo.page new-fenserve/edit-demo.page
--- old-fenserve/edit-demo.page	1970-01-01 02:00:00.000000000 +0200
+++ new-fenserve/edit-demo.page	2007-03-22 19:49:07.000000000 +0200
@@ -0,0 +1,30 @@
+
+import Storm (getBlock, addBlock, fromUTF, toUTF)
+import Control.Monad (liftM)
+import Data.List (intersperse)
+import Data.Maybe (fromMaybe)
+
+handler req = do
+    let path0 = fromMaybe "/testdata/foo" $ lookM req "path"
+        path' = splitPath path0
+
+    if rqMethod req == POST
+        then case lookM req "contents" of
+                Just contents -> do b <- liftM bIRI $ addBlock $ toUTF contents
+                                    putBlock path' b; return ()
+                _ -> return ()
+        else return ()
+
+    e <- getEntry path'; contents <- case e of
+        Right (FileEntry _ r) -> liftM fromUTF $ getBlock (bID r)
+        _ -> return ""
+        
+    return $ mkResult 200 "text/html" $ toUTF $
+        <html>
+        <h1>Edit: <% concat $ intersperse "/" path' %></h1>
+        <form action="" method="POST">
+        <textarea name="contents"><% contents %></textarea>
+        <input name="path" type="hidden" value=path0/>
+        <input type="submit"/>
+        </form>
+        </html>




More information about the Fencommits mailing list