Changeset 1187 for lang/haskell
- Timestamp:
- 11/06/07 16:42:46 (13 months ago)
- Files:
-
- 1 modified
-
lang/haskell/blosxkel/blosxkel.hs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/blosxkel/blosxkel.hs
r1169 r1187 19 19 import Network.CGI 20 20 21 data Entry = Entry { 22 file :: FilePath, 23 path :: String, 24 title :: String, 25 time :: ClockTime, 26 body :: [String] 27 } 28 29 21 30 -- ref. http://i.loveruby.net/ja/stdhaskell/samples/lazylines/Template.hs.html 22 31 fillFlavour :: String -> String -> [(String, String)] -> IO String 23 fillFlavour flavour place params = return . fill =<< (readFile $ place ++ flavour) 32 fillFlavour flavour place params = do 33 { 34 ; tmpl <- (readFile $ place ++ flavour) 35 ; return $ fill $ tmpl 36 } 24 37 where 25 38 fill "" = "" … … 42 55 | otherwise = let (k, (':':v)) = (break (== ':') l) 43 56 in [(strip k, strip v)] 44 strip = rstrip . lstrip57 strip = rstrip . lstrip 45 58 rstrip = reverse . lstrip . reverse 46 59 lstrip = dropWhile isSpace … … 48 61 getConfig :: [(String, String)] -> String -> String 49 62 getConfig config key = fromJust $ lookup key config 50 51 data Entry = Entry {52 file :: FilePath,53 path :: String,54 title :: String,55 time :: ClockTime,56 body :: [String]57 }58 63 59 64 … … 74 79 -- http://www.tom.sfc.keio.ac.jp/~sakai/2ch/1162902266.html 75 80 getRecursiveContents :: FilePath -> IO [FilePath] 76 getRecursiveContents fp = getDirectoryContents fp >>= mapM (fx fp) >>= return . concat 81 getRecursiveContents fp = do 82 { 83 ; dc <- getDirectoryContents fp 84 ; re <- mapM (fx fp) dc 85 ; return $ concat $ re 86 } 77 87 where 78 fx :: FilePath -> FilePath -> IO [FilePath]79 fx bp "." = return [bp]80 fx bp ".." = return []81 fx bp f = do let np = bp ++ ('/':f)82 b <- doesDirectoryExist np83 if b then getRecursiveContents np84 else return [np]88 fx :: FilePath -> FilePath -> IO [FilePath] 89 fx bp "." = return [bp] 90 fx bp ".." = return [] 91 fx bp f = do let np = bp ++ ('/':f) 92 b <- doesDirectoryExist np 93 if b then getRecursiveContents np 94 else return [np] 85 95 86 96 … … 141 151 } where 142 152 fill place params = fillFlavour (getConfig cgiparams "flavour") place 143 (params ++ [("title" , getConfig config "title"), 153 (params ++ [ 154 ("title" , getConfig config "title"), 144 155 ("author" , getConfig config "author"), 145 ("version", unwords [os, arch, compilerName, showVersion compilerVersion])] ++ cgiparams) 156 ("version", unwords [os, arch, compilerName, showVersion compilerVersion]) 157 ] ++ cgiparams) 146 158 147 159 cgiMain :: CGI CGIResult … … 153 165 ; servername <- serverName 154 166 ; flavour <- return $ takeExtension pathinfo 155 ; (ct, cb) <- liftIO $ getResult [("home" , home),156 ("pathinfo" , pathinfo),167 ; (ct, cb) <- liftIO $ getResult [("home" , home), 168 ("pathinfo" , pathinfo), 157 169 ("servername", "http://" ++ servername), 158 ("flavour" , if length flavour == 0159 then getConfig config "default-flavour"160 else flavour)] config170 ("flavour" , if length flavour == 0 171 then getConfig config "default-flavour" 172 else flavour)] config 161 173 ; setHeader "Content-Type" $ reverse $ dropWhile isSpace $ reverse $ ct 162 174 ; output $ cb
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)