summaryrefslogtreecommitdiff
path: root/app/Views.hs
diff options
context:
space:
mode:
authorAndrew Guschin <guschin.drew@gmail.com>2023-03-05 13:45:37 +0400
committerAndrew Guschin <guschin.drew@gmail.com>2023-03-05 13:47:41 +0400
commita0e8e5a91d15ed8c79f4a1b5914d3a6242c0cbd3 (patch)
tree76f76788523a16c0db8cb8f3a90b23912acd37d4 /app/Views.hs
parentdd73de2e563c332c5a90bb21c5c7e6cbebc0ab86 (diff)
Migrated project to cabal
Diffstat (limited to 'app/Views.hs')
-rw-r--r--app/Views.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/Views.hs b/app/Views.hs
new file mode 100644
index 0000000..54cd844
--- /dev/null
+++ b/app/Views.hs
@@ -0,0 +1,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