blob: 2e0482f9725cd3c27dfff79644494c189210ab4a (
plain)
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
|
module Views where
import System.IO
import qualified Data.Text as T
import Data.Text (Text)
import Web.Request
import Web.Response
indexGet :: Request -> IO Response
indexGet _ = renderTemplate "index.html"
helloGet :: Request -> IO Response
helloGet _ = renderTemplate "hello.html"
renderTemplate :: String -> IO Response
renderTemplate name = do
template <- readTemplate name
return $ HtmlResponse 200 template
readTemplate :: String -> IO Text
readTemplate name = do
handle <- openFile ("templates/" ++ name) ReadMode
contents <- hGetContents handle
return $ T.pack contents
|