{- DisTract ------------------------------------------------------\ | | | Copyright (c) 2007, Matthew Sackman (matthew@wellquite.org) | | | | DisTract is freely distributable under the terms of a 3-Clause | | BSD-style license. For details, see the DisTract web site: | | http://distract.wellquite.org/ | | | \-----------------------------------------------------------------} {-# LANGUAGE TemplateHaskell #-} module DisTract.HTML.BugView (formatBug, formatBugId, bugToHTML ) where import Text.HTML.Chunks import DisTract.Types import DisTract.Bug import DisTract.Utils import DisTract.Layout import DisTract.HTML.Fields import System.FilePath import Data.List import Data.Time import qualified JSON as J import qualified Data.Map as M $(chunksFromFile "./html/templates/bugView.html") formatBug :: Config -> Maybe Bug -> IO () formatBug _ Nothing = return () formatBug config (Just bug) = do { htmlStr <- bugToHTML config bug ; writeFile path htmlStr } where path = combine (htmlDir . baseDir $ config) filename filename = addExtension (show . bugId $ bug) "html" formatBugId :: Config -> BugId -> IO () formatBugId config bid = loadBug config bid >>= formatBug config bugToHTML :: Config -> Bug -> IO String bugToHTML config (Bug bid comments fields) = do { time <- (getZonedTime >>= formatTimeHuman) ; commentsFormatted <- formatComments filename True comments ; return $ format $ Chunk_page { page_title = header, page_comments = commentsFormatted, page_fields = "