--------------------
-- Sample HTML file generation using the Html library
--------------------
-- make sure ":{Hugs}/libraries" is in your path!
import Text.Html
--------------------
makePage t c b = header << thetitle << t +++ body ! [bgcolor c] << b
jump fn = anchor ! [href fn]
dump f p = writeFile (path f) (renderHtml p)
--------------------
sampage = makePage "Sample Page via HTML library" cs454color pageBody
cs454color = "#FFCC99"
pageBody = table ! [border 0] << mainTable
+++ br
+++ p << note "(Haskell is a trademark of Haskell, Inc.)"
mainTable = lambda `beside` (haskell `above` purely)
where haskell = td ! [align "center"] << bigg "Haskell"
purely = td << norm "A Purely Functional Language"
lambda = td << image ! [src "lambda.gif"]
-- some style stuff (this is better done via CSS ...)
note txt = font ! [size "2"] << italics << txt
bigg txt = font ! [size "7", face "Arial Black"] << txt
norm txt = font ! [size "6"] << txt
--------------------
path = ("/Users/fruehr/Desktop/FRUEHR/public_html/454/html/" ++)
exfn str = concat ["example", str, ".htm"]
main1 = dump (exfn "1") sampage
--------------------
main2 = dbgen (exfn "2") (exfn "db") sampage
dbgen f1 f2 page = do dump f1 ( page +++ p << jump f2 << note "(see debug)")
dump f2 (debugHtml page +++ p << jump f1 << note "(back)")
--------------------
bluepage n = makePage bluen "#AADDFF" (p << bigg bluen)
where bluen = "This is blue page #" ++ show n
bluefn n = concat ["blue", show n, ".htm"]
main3 = dump (bluefn 0) (bluepage 0)
blulnk n = dump (bluefn n) (bluepage n +++ p << jump (bluefn (n+1)) << note (bigg "next"))
main4 = mapM_ blulnk [1..8]
--------------------
nestab 0 htm = htm
nestab n htm = table ! [border n] << td << (nestab (n-1) htm)
nestpg n = makePage np "#AAFFDD" (p << nestab n (norm np))
where np = "This is a nested table page (" ++ show n ++ " deep)"
nestfn n = concat ["nest", show n, ".htm"]
nestlnk n = dump (nestfn n) (nestpg n +++ p << jump (nestfn (n+1)) << note (norm "next"))
main5 = mapM_ nestlnk [1..10]
--------------------