[Fencommits] fenserve: refactor by splitting potion?... and potion/... into two functions

Benja Fallenstein benja.fallenstein at gmail.com
Fri May 25 19:22:20 EEST 2007


Fri May 25 19:22:13 EEST 2007  Benja Fallenstein <benja.fallenstein at gmail.com>
  * refactor by splitting potion?... and potion/... into two functions
diff -rN -u old-fenserve/fendata/Main.hs new-fenserve/fendata/Main.hs
--- old-fenserve/fendata/Main.hs	2007-05-25 19:22:20.000000000 +0300
+++ new-fenserve/fendata/Main.hs	2007-05-25 19:22:20.000000000 +0300
@@ -102,25 +102,29 @@
         Right (s, state') -> do put state'; respond (s, html $ link s "link")
         Left e -> respond $ ("", "Internal server error: " ++ show e)
 
-potionGet exp args name s =
-        ( if expandable then makePage s rendered expandLink body else
-              makePage s "Custom page" "" $
-              tag "div" [("style", "border: 1px solid black; \
-                          \margin-bottom: 1em; padding: 1em; \
-                          \padding-bottom: 0; font-weight: bold")]
-                  (rendered +++ saveLinks) +++ body
-        , s) where
+potionPage exp args name s = (makePage s title expandLink body, s) where
+    title = let ?state=s; ?link=False; ?name=name in renderExp exp id string
+    env = Map.fromList $ zip [0..length args-1] args
     body = if (isComplete exp)
            then (HTML $ head $ evalStateT (runExp env exp) s)
            else toHTML "(Incomplete expression.)"
-    rendered = let ?state=s; ?link=not expandable; ?name=name in renderExp exp id string
-    env = Map.fromList $ zip [0..length args-1] args
-    expanded = expand s exp; expandable = isJust expanded
+    expanded = expand s exp
     expandLink = (para $ link (?root++"potion?exp="++escape' (show e)++"&name="++n) "[edit page]")
              +++ if exp `elem` stateSidebarPages s then HTML "" else
                  (para $ formP (?root++"addToSidebar") (hidden "exp" (show exp)
                                             +++ button "[add to sidebar]"))
         where Just (e,n) = expanded
+
+potionGet exp args name s = (makePage s "Custom page" "" $
+              tag "div" [("style", "border: 1px solid black; \
+                          \margin-bottom: 1em; padding: 1em; \
+                          \padding-bottom: 0; font-weight: bold")]
+                  (rendered +++ saveLinks) +++ body, s) where
+    body = if (isComplete exp)
+           then (HTML $ head $ evalStateT (runExp env exp) s)
+           else toHTML "(Incomplete expression.)"
+    rendered = let ?state=s; ?link=True; ?name=name in renderExp exp id string
+    env = Map.fromList $ zip [0..length args-1] args
     saveLinks = formP "addpotion" $ (+++hidden "exp" (show exp)) $
                 (+++link ("makefun?exp="++escape' (show exp)) "[Save as...]") $
                 flip (maybe $ HTML "") name $ \name' ->
@@ -265,7 +269,7 @@
                , h ["potion"] GET $ ok $ \() -> run $ 
                    \req s -> let ?root = "" in potionGet (read $ fromJust $ lookM req "exp") (readArgs req) (lookM req "name") s
                , h (Prefix ["potion"]) GET $ ok $ \(fun:args) -> run $ 
-                   \req s -> let ?root = concat (take (1 + length args) $ repeat "../") in potionGet (Call fun (map (Just . Str) $ args)) args (lookM req "name") s
+                   \req s -> let ?root = concat (take (1 + length args) $ repeat "../") in potionPage (Call fun (map (Just . Str) $ args)) args (lookM req "name") s
                , h ["edit"] GET $ ok $ \() -> run $ \req ->
                      edit (read $ fromJust $ lookM req "exp",
                            read $ fromJust $ lookM req "old",




More information about the Fencommits mailing list