Changeset 1157

Show
Ignore:
Timestamp:
11/05/07 21:04:33 (6 years ago)
Author:
jknaoya
Message:

lang/haskell/blosxkel/blosxkel.hs:

関数分離してモナドの中で処理するようにしたらいけました!やった☆

Files:
1 modified

Legend:

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

    r1156 r1157  
    7575    } 
    7676 
    77 applyStory :: (String -> [(String, String)] -> IO String) -> Entry -> IO String 
    78 applyStory fill e = fill "story" [("title", title e), 
    79                                   ("body", concat (body e)), 
    80                                   ("time", formatCalendarTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" (toUTCTime (time e))), 
    81                                   ("path", path e)] 
     77 
     78getResult :: [(String, String)] -> IO (String, String) 
     79getResult cgiparams = do 
     80    { 
     81    ; entries <- getTextFileEntries "data" 
     82    ; ct <- fill "content_type" [] 
     83    ; ch <- fill "head" [] 
     84    ; cs <- mapM 
     85               (\e -> fill "story" 
     86               [("title", title e), 
     87                ("body", concat (body e)), 
     88                ("time", formatCalendarTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" (toUTCTime (time e))), 
     89                ("path", path e)]) 
     90               $ take 7 $ reverse $ sortBy (\a b -> compare (time a) (time b)) entries 
     91    ; cf <- fill "foot" [] 
     92    ; return $ (ct, concat $ [ch, concat cs, cf]) 
     93    } where 
     94        fill place params = fillFlavour "html" place (params ++ [("title", "Blosxkel.hs"), 
     95                                                                 ("version", "aaa")] ++ cgiparams) 
    8296 
    8397cgiMain :: CGI CGIResult 
    8498cgiMain =  do 
    8599    { 
    86     ; entries <- liftIO $ getTextFileEntries "data" 
    87     ; ct <- liftIO $ fill "content_type" [] 
    88     ; ch <- liftIO $ fill "head" [] 
    89     ; cs <- liftIO $ mapM (applyStory fill) $ take 7 $ reverse $ sortBy (\a b -> compare (time a) (time b)) entries 
    90     ; cf <- liftIO $ fill "foot" [] 
    91     ; setHeader "Content-Type" ct 
    92     ; output $ concat $ [ch, concat cs, cf] 
    93     } where 
    94         fill place params = fillFlavour "html" place (params ++ [("title", "Blosxkel.hs"), 
    95                                                                  ("version", "aaa")]) 
     100    ; home <- scriptName 
     101    ; result <- liftIO $ getResult [("home", home)] 
     102    ; setHeader "Content-Type" $ fst result 
     103    ; output $ snd result 
     104    } 
    96105 
    97106main :: IO ()