packages feed

CHXHtml-0.1.1: demoFastCGI.hs


import Network.FastCGI
import Text.CHXHtml.XHtml1_strict
-- CHXHtml demoFastCGI.hs
-- 
-- Paul Talaga -- June 5, 2010
-- 
-- Construct a static Hello World XHTML1 Strict compliant page
-- render it to FastCGI via ByteString for speed
-- containing a from to specify how large the table should be.
--
-- If the 'n' parameter is set produce a multiplication table of that size.


main = runFastCGI $ handleErrors test

test :: CGI CGIResult
test  = do n <- (Network.FastCGI.getInput "n");
           case n of
               Just m -> outputFPS $ render_bs (helloWorldTable (read m::Int))
               Nothing -> outputFPS $ render_bs helloWorld

helloWorld = helloWorldTemplate [] 

-- Simple Hello World template page
helloWorldTemplate content = 
    _html [
        _head [
            _title [pcdata "Hello World Multi Table"]
        ],
        _body [_h1 [pcdata "Hello World Multiplication Table"],
            _hr,
            form_ [method_att Get] [div_ [] [
                    _label [pcdata "nxn:"],
                    input_ 
                ]
            ],
            -- The <a> tag can not be under <body>, but inside a <div>.
            -- Try > htmlHelp ["html","body"]   to get a list of allowed tags and attributes
            -- Uncomment the following line to cause a type error.
            -- _a [pcdata "Will not work!"],
            _div  content
        ]
    ]
             
-- Hello World table page with dynamic table multiplication table
-- Because children are specified as a list, we can use Haskell's built-in functions for
-- list manipulation and creation.          
helloWorldTable n = helloWorldTemplate 
    [table_ [border_att "1"] 
        (map (\i->_tr 
                (map (\j->_td [pcdata (show (i * j))]) [1..n])
             ) [1..n])
    
    ]