[Fencommits] fenserve: make more robust by checking always before doing a (make run)
Benja Fallenstein
benja.fallenstein at gmail.com
Sat Apr 28 21:57:33 EEST 2007
Sat Apr 28 21:57:23 EEST 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* make more robust by checking always before doing a (make run)
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs 2007-04-28 21:57:33.000000000 +0300
+++ new-fenserve/notetaker/Main.hs 2007-04-28 21:57:33.000000000 +0300
@@ -34,7 +34,7 @@
\ document.forms[0].elements[1].focus();\
\</script>"
-views n nick = "<p>Views: "++concat (intersperse " | " [view i|i<-[0..2]])
+views n nick = "<p>Views: "++concat (intersperse " | " [view i|i<-[0..length links-1]])
where links = [("main", "/"), ("log", "/log"), ("lastlog", "/lastlog")]
view i | i == n = printf "<b>%s</b>" name
| otherwise = printf "<a href=%s?nick=%s>%s</a>" uri nick name
@@ -42,13 +42,15 @@
page path nick = do
(lines :: [Line]) <- get
- let Note title _ notes =
- getPath path $ foldl (flip execute) (Note "HOME" True []) lines
- respond $ style ++ "<h2>" ++ renderPath path ++ " " ++ title ++ "</h2>"
- ++ renderNotes path nick notes ++ views 0 nick ++ form nick
-
-getPath [] note = note
-getPath (i:is) (Note _ _ cs) = getPath is (cs !! i)
+ case getPath path $ executeAll lines of
+ Just (Note title _ notes) ->
+ respond $ style ++ "<h2>" ++ renderPath path ++ " " ++ title ++ "</h2>"
+ ++ renderNotes path nick notes ++ views 0 nick ++ form nick
+ Nothing -> respond $ "Path not found: " ++ renderPath path
+
+getPath [] note = Just note
+getPath (i:is) (Note _ _ cs) | i >= 0 && i < length cs = getPath is (cs !! i)
+ | otherwise = Nothing
renderNotes p nick notes =
"<ol>" ++ concat [renderNote (p++[i]) (notes !! i)
@@ -80,9 +82,10 @@
| ":unpage " `isPrefixOf` s = readPath' s 8 $ \p "" -> Unpage p
| otherwise = Body s
-execute (Line _ _ (Body _)) = id
-execute (Line _ _ body) =
- case body of
+executeAll = foldl (\n (Line _ _ b) -> execute b n) (Note "HOME" True [])
+
+execute (Body _) = id
+execute body = case body of
Add p l -> on p $ \(Note t o cs) -> [Note t o (cs++[Note l False []])]
Edit p l -> on p $ \(Note _ o cs) -> [Note l o cs]
Move p q -> move p q
@@ -94,12 +97,14 @@
where
on is f note = head $ on' is f note
on' [] f note = f note
- on' (i:is) f (Note t o cs) =
+ on' (i:is) f (Note t o cs) | i < 0 || i >= length cs = [Note t o cs]
+ | otherwise =
[Note t o (take i cs ++ on' is f (cs !! i) ++ drop (i+1) cs)]
- move p q root = (on p $ \(Note _ _ cs) -> [])
- $ (on q $ \(Note t o cs) -> [Note t o (cs++[getPath p root])])
- $ root
+ move p q root = case getPath p root of
+ Nothing -> root
+ Just n -> (on p $ \(Note _ _ cs) -> []) $
+ (on q $ \(Note t o cs) -> [Note t o (cs++[n])]) $ root
getNick m = case lookM m "nick" of Nothing -> "(anon)"; Just "" -> "(anon)"
Just x -> x
More information about the Fencommits
mailing list