-- | DisplayHTML.hs -- A module which contain functions for display html from board -- structures. module DisplayHTML ( displayOneThread, displayBoard, displayError ) where import Board import HTML import HSP -- | Display full thread by call displayThread and glue it with full -- page template. displayOneThread :: TagPosts -> HSP XML displayOneThread tagPosts@(tag, _, _) = fullPageTemplate True tag [displayThread True tagPosts] -- | Display board by gluing partial threads. displayBoard :: String -> (Int, Int) -> [TagPosts] -> HSP XML displayBoard tagsStr pages tagsPosts = fullPageTemplate False tagsStr $ map (displayThread False) tagsPosts++[pagesTemplate tagsStr pages] displayError :: String -> HSP XML displayError = errorPageTemplate --- -- | Display full or partial thread. displayThread :: Bool -> TagPosts -> HSP XML displayThread full (tag, omitted, posts) = threadTemplate full tag num $ case lenPosts of 0 -> [displayError "Error! Empty thread."] -- should not happened 1 -> [opPost] _ -> [opPost, omit] ++ replies where opPost = opPostTemplate full (head posts) omit = omittedTemplate omitted replies = map reply (tail posts) reply = replyTemplate full lenPosts = length posts num = if lenPosts > 0 then show $ pnumber $ head posts else "0"