Changeset 1187 for lang/haskell

Show
Ignore:
Timestamp:
11/06/07 16:42:46 (13 months ago)
Author:
jknaoya
Message:

lang/haskell/blosxkel/blosxkel.hs:

よみやすいように整形しました。data の宣言はうえのほうにしました

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/blosxkel/blosxkel.hs

    r1169 r1187  
    1919import Network.CGI 
    2020 
     21data Entry = Entry { 
     22    file  :: FilePath, 
     23    path  :: String, 
     24    title :: String, 
     25    time  :: ClockTime, 
     26    body  :: [String] 
     27} 
     28 
     29 
    2130-- ref. http://i.loveruby.net/ja/stdhaskell/samples/lazylines/Template.hs.html 
    2231fillFlavour :: String -> String -> [(String, String)] -> IO String 
    23 fillFlavour flavour place params = return . fill =<< (readFile $ place ++ flavour) 
     32fillFlavour flavour place params = do 
     33    { 
     34    ; tmpl <- (readFile $ place ++ flavour) 
     35    ; return $ fill $ tmpl 
     36    } 
    2437    where 
    2538        fill ""   = "" 
     
    4255                  | otherwise     = let (k, (':':v)) = (break (== ':') l) 
    4356                                    in [(strip k, strip v)] 
    44         strip     = rstrip . lstrip 
     57        strip     = rstrip  . lstrip 
    4558        rstrip    = reverse . lstrip . reverse 
    4659        lstrip    = dropWhile isSpace 
     
    4861getConfig :: [(String, String)] -> String -> String 
    4962getConfig 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 } 
    5863 
    5964 
     
    7479-- http://www.tom.sfc.keio.ac.jp/~sakai/2ch/1162902266.html 
    7580getRecursiveContents :: FilePath -> IO [FilePath] 
    76 getRecursiveContents fp = getDirectoryContents fp >>= mapM (fx fp) >>= return . concat 
     81getRecursiveContents fp = do 
     82    { 
     83    ; dc <- getDirectoryContents fp 
     84    ; re <- mapM (fx fp) dc 
     85    ; return $ concat $ re 
     86    } 
    7787    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 np 
    83                        if b then getRecursiveContents np 
    84                             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] 
    8595 
    8696 
     
    141151    } where 
    142152        fill place params = fillFlavour (getConfig cgiparams "flavour") place 
    143                                         (params ++ [("title"  , getConfig config "title"), 
     153                                        (params ++ [ 
     154                                        ("title"  , getConfig config "title"), 
    144155                                        ("author" , getConfig config "author"), 
    145                                         ("version", unwords [os, arch, compilerName, showVersion compilerVersion])] ++ cgiparams) 
     156                                        ("version", unwords [os, arch, compilerName, showVersion compilerVersion]) 
     157                                        ] ++ cgiparams) 
    146158 
    147159cgiMain :: CGI CGIResult 
     
    153165    ; servername <- serverName 
    154166    ; flavour    <- return $ takeExtension pathinfo 
    155     ; (ct, cb)   <- liftIO $ getResult [("home", home), 
    156                                         ("pathinfo", pathinfo), 
     167    ; (ct, cb)   <- liftIO $ getResult [("home"      , home), 
     168                                        ("pathinfo"  , pathinfo), 
    157169                                        ("servername", "http://" ++ servername), 
    158                                         ("flavour", if length flavour == 0 
    159                                                     then getConfig config "default-flavour" 
    160                                                     else flavour)] config 
     170                                        ("flavour"   , if length flavour == 0 
     171                                                       then getConfig config "default-flavour" 
     172                                                       else flavour)] config 
    161173    ; setHeader "Content-Type" $ reverse $ dropWhile isSpace $ reverse $ ct 
    162174    ; output $ cb