summaryrefslogtreecommitdiff
path: root/app/Views.hs
blob: 54cd84464f57b6f9ff5c6e601b8b26313a8f3533 (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 req = renderTemplate "index.html"

helloGet :: Request -> IO Response
helloGet req = 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