happstack css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Happstack.Server
import Text.Blaze ((!))
import Control.Monad (forM_, msum)
import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A

appTemplate :: String -> H.AttributeValue -> [H.Html] -> H.Html -> H.Html
appTemplate title css headers body =
    H.html $ do
      H.head $ do
        H.title (H.string title)
        H.link ! A.rel "stylesheet" ! A.type_ "text/css" ! A.href css
        H.meta ! A.httpEquiv "Content-Type" ! A.content "text/html;charset=utf-8"
        sequence_ headers
      H.body $ do
        body

index :: ServerPart Response
index = 
   ok $ toResponse $ 
    appTemplate "my page" "index.css"
                [H.meta ! A.name "keywords" ! A.content "happstack, blaze, html"] 
                (H.p "Welcome to my page!!!")

main :: IO ()
main = simpleHTTP nullConf $ msum [ dir "index.html" $ index ]