[Fencommits] fenserve: tweak appearance and html

Tuukka Hastrup Tuukka.Hastrup at iki.fi
Sun May 6 04:33:47 EEST 2007


Sun May  6 04:31:55 EEST 2007  Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
  * tweak appearance and html
diff -rN -u old-fenserve/notetaker/Main.hs new-fenserve/notetaker/Main.hs
--- old-fenserve/notetaker/Main.hs	2007-05-06 04:33:46.000000000 +0300
+++ new-fenserve/notetaker/Main.hs	2007-05-06 04:33:47.000000000 +0300
@@ -24,9 +24,14 @@
 
 data Note = Note String Bool [Line] [Note] deriving (Eq,Ord,Read,Show)
 
-style = "<style type='text/css'>li, p.logline { margin-bottom: 0.3em; margin-top: 0.3em }\n.loglink, .children { color: #aaa; font-size: small }\n.loglink a { color: #aaa }</style>"
+style = "\n<style type='text/css'>li, p.logline { margin-bottom: 0.3em; margin-top: 0.3em }\n.children { font-style: italic }\n.loglink, .children { color: #aaa; font-size: small }\n.loglink a { color: #aaa }</style>"
 
-form nick = "<p><form id='myform' action='/?nick="++nick++"' method='post'>\
+header title = printf "<html><head><title>%s</title>%s\n</head>\n<body>"
+                   title style
+
+footer = "\n</body></html>"
+
+form nick = "\n<p><form id='myform' action='/?nick="++nick++"' method='post'>\
             \    Nick: <input name='nick' type='text' size=8 \
                              \value='" ++ nick ++ "'> \
             \    <input name='line' id='myline' type='text' size=60>\
@@ -36,7 +41,7 @@
             \    document.forms[0].elements[1].focus();\
             \</script>"
 
-views n nick = "<p>Views: "++concat (intersperse " | " [view i|i<-[0..length links-1]])
+views n nick = "\n<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
@@ -47,8 +52,10 @@
     let r = executeAll lines; p = getPage path r; v = if p == [] then 0 else -1
     case getPath p r of
       Just (Note title _ _ notes) ->
-        respond $ style ++ "<h2>" ++ renderPath p ++ " " ++ title ++ "</h2>"
-               ++ renderNotes p nick notes ++ views v nick ++ form nick
+        let title' = renderPath p ++ " " ++ title in
+        respond $ header title' ++ "<h2>" ++ title' ++ "</h2>"
+               ++ views v nick ++ renderNotes p nick notes
+               ++ views v nick ++ form nick ++ footer
       Nothing -> respond $ "Path not found: " ++ renderPath path
 
 -- get the path of the closest ancestor that is its own page
@@ -60,18 +67,18 @@
                                | otherwise = Nothing
                     
 renderNotes p nick notes = 
-    "<ol>" ++ concat [renderNote (p++[i]) (notes !! i) 
-                     | i <- [0..length notes - 1]] ++ "</ol>" where
+    "\n<ol>" ++ concat [renderNote (p++[i]) (notes !! i)
+                     | i <- [0..length notes - 1]] ++ "\n</ol>" where
     
     link [] _ = ""
     link [Line t _ _] _ = " <span class='loglink'>(<a href='/log#"++show t++"'>log</a>)</span>"
     link _ p = " <span class='loglink'>(<a href='/log/"++renderPath p++"'>log</a>)</span>"
     
-    renderNote p (Note title False ls cs) = "<li>" ++ title ++ link ls p ++ renderNotes p nick cs
+    renderNote p (Note title False ls cs) = "\n<li>" ++ title ++ link ls p ++ renderNotes p nick cs
     renderNote p (Note title True ls cs) =
-         "<li>" ++ title ++ " <span class='children'>(<a href='/item/"
-      ++ renderPath p ++ "?nick=" ++ nick ++ "'><i>"
-      ++ countable (length cs) "child" "ren" ++ "</i></a>, "
+         "\n<li>" ++ title ++ " <span class='children'>(<a href='/item/"
+      ++ renderPath p ++ "?nick=" ++ nick ++ "'>"
+      ++ countable (length cs) "child" "ren" ++ "</a>, "
       ++ countable (gather ((+1) . sum) 1 cs - 1) "descendant" "s" ++ ", "
       ++ countable (gather ((+1) . maximum) 0 cs) "level" "s" ++ ")</span>"
       ++ link ls p
@@ -144,21 +151,27 @@
     fromMessageM m = do l <- lookM m "line"; return (getNick m, l)
     
 renderLog nick lastlog = do 
+    Note title _ _ _ <- liftM executeAll get
     lines <- if not lastlog then get 
                  else get >>= return . reverse . take 15 . reverse
-    respond $ style ++ flip concatMap lines renderLine
-           ++ views (if lastlog then 2 else 1) nick ++ form nick 
-           
+    respond $ header (title'++title) ++ views'
+           ++ flip concatMap lines renderLine
+           ++ views' ++ form nick ++ footer
+    where
+          (title',views') | lastlog   = ("LastLog for ", views 2 nick)
+                          | otherwise = ("Log for "    , views 1 nick)
 itemLog nick path = do
     lines <- get; respond $ case getPath path (executeAll lines) of
         Nothing -> "Path not found: " ++ renderPath path
-        Just (Note _ _ ls _) -> style ++ concatMap renderLine' ls 
-                             ++ views (-1) (nick :: String)
+        Just (Note title _ ls _) ->
+            let title' = "Log for item " ++ renderPath path ++ " " ++ title in
+            header title' ++ "<h2>" ++ title' ++ "</h2>" ++ views (-1) nick
+         ++ concatMap renderLine' ls ++ views (-1) (nick :: String) ++ footer
     where renderLine' l@(Line t _ _) =
               renderLine l ++ " (<a href='/log#"++show t++"'>context</a>)"
            
 renderLine (Line time nick body) =
-    "<p class='logline' id='"++show time++"'>" 
+    "\n<p class='logline' id='"++show time++"'>"
  ++ renderTime time ++ " " ++ renderBody nick body
                   
 renderBody :: String -> Body -> String




More information about the Fencommits mailing list