[Add WebData structure to the HTML output pages, move to dumping out with the new routines, and delete the old file replacement stuff Neil Mitchell**20060818181637] { hunk ./src/Web/HTML.hsx 4 -module Web.HTML(htmlFront, htmlError) where +module Web.HTML(WebData(..), htmlFront, htmlError, htmlAnswers, innerNoResult) where hunk ./src/Web/HTML.hsx 9 +data WebData = WebData {webSearch :: String, webPackage :: String, webLogo :: String} + + + hunk ./src/Web/HTML.hsx 17 -anyPage search body = doctype ++ "\n" ++ show html +anyPage webData@WebData{webSearch=webSearch} body = doctype ++ "\n" ++ show html hunk ./src/Web/HTML.hsx 23 - <% if null search then "" else search ++ " - " %>Hoogle + <% if null webSearch then "" else webSearch ++ " - " %>Hoogle hunk ./src/Web/HTML.hsx 28 - + hunk ./src/Web/HTML.hsx 58 -searchPage search inner = anyPage search $ +searchPage :: ToXMLs a => WebData -> a -> String +searchPage webData inner = anyPage webData $ hunk ./src/Web/HTML.hsx 68 - + hunk ./src/Web/HTML.hsx 73 - <% inner %> + toXMLs <% inner %> hunk ./src/Web/HTML.hsx 78 -htmlError :: String -> String -> String -htmlError search errmsg = searchPage search $ +htmlError :: WebData -> String -> String +htmlError webData errmsg = searchPage webData $ hunk ./src/Web/HTML.hsx 97 +-- no results have been found, i.e. blah +innerNoResult :: String +innerNoResult = show $ +
+ Your search returned no results: + +
+ + + +htmlAnswers :: WebData -> String -> String +htmlAnswers webData inner = searchPage webData inner + + + + hunk ./src/Web/HTML.hsx 118 -htmlFront :: String -htmlFront = anyPage "" $ +htmlFront :: WebData -> String +htmlFront webData = anyPage webData $ hunk ./src/Web/Main.hs 68 - if null input then hoogleBlank args + + let dat = WebData input + (if ("package","gtk") `elem` args then "gtk" else "") + (lookupDef "default" "logo" args) + + if null input then putLine $ htmlFront dat hunk ./src/Web/Main.hs 76 - Just x -> showError input x - Nothing -> showResults p args + Just x -> putLine $ htmlError dat x + Nothing -> showResults dat p args hunk ./src/Web/Main.hs 93 --- | Show the search box -hoogleBlank :: [(String,String)] -> IO () -hoogleBlank args = if ("package","gtk") `elem` args - then outputFile "front_gtk"else - putLine htmlFront - - --- | Replace all occurances of $ with the parameter -outputFileParam :: FilePath -> String -> IO () -outputFileParam x param = do src <- readFile ("res/" ++ x ++ ".inc") - putLine (f src) - where - f ('$':xs) = param ++ f xs - f (x:xs) = x : f xs - f [] = [] - -outputFile :: FilePath -> IO () -outputFile x = do src <- readFile ("res/" ++ x ++ ".inc") - putLine src - - -showError :: String -> String -> IO () -showError input err = putLine $ htmlError input err - - - hunk ./src/Web/Main.hs 94 -showResults :: Search -> [(String, String)] -> IO () -showResults input args = +showResults :: WebData -> Search -> [(String, String)] -> IO () +showResults dat input args = hunk ./src/Web/Main.hs 104 - outputFileParam (if useGtk then "prefix_gtk" else "prefix") tSearch - - putLine $ - "
" ++ - "Searched for " ++ showTags search ++ - "" ++ - (if lres == 0 then "No results found" else f lres) ++ - "
" + let count = + "
" ++ + "Searched for " ++ showTags search ++ + "" ++ + (if lres == 0 then "No results found" else f lres) ++ + "
" hunk ./src/Web/Main.hs 111 - case hoogleSuggest True input of - Nothing -> return () - Just x -> putLine $ "

Hoogle says: " ++ - showTags x ++ "

" + let suggest = case hoogleSuggest True input of + Nothing -> "" + Just x -> "

Hoogle says: " ++ showTags x ++ "

" hunk ./src/Web/Main.hs 116 - case lam of - Nothing -> return () - Just x -> putLine $ "

" ++ - "Lambdabot says: " - ++ x ++ "

" + let lambdabot = case lam of + Nothing -> "" + Just x -> "

" ++ + "Lambdabot says: " + ++ x ++ "

" hunk ./src/Web/Main.hs 122 - if null res then outputFileParam "noresults" tSearch - else putLine $ "" ++ concatMap showResult useres ++ "
" + let results = if null res then innerNoResult + else "" ++ concatMap showResult useres ++ "
" hunk ./src/Web/Main.hs 125 - putLine $ g lres + let pageFlip = g lres hunk ./src/Web/Main.hs 127 - putLine $ if format == "sherlock" then sherlock useres else "" + let sher = if format == "sherlock" then sherlock useres else "" hunk ./src/Web/Main.hs 129 - outputFileParam "suffix" tSearch + putLine $ htmlAnswers dat (count ++ suggest ++ lambdabot ++ results ++ pageFlip ++ sher) }