Commits

Luke Plant committed d0068b5

Began to implement template and main page

  • Participants
  • Parent commits efcf095

Comments (0)

Files changed (3)

File src/Blog/Templates.hs

+module Blog.Templates 
+where
+
+import Text.XHtml
+
+-- Complete page template
+page ptitle pcontent = 
+    header
+    << (meta ! [httpequiv "Content-Type",
+                content "text/html; charset=utf-8"]
+        +++ thelink ! [rel "alternate",
+                       thetype "application/rss+xml",
+                       title "RSS",
+                       href "/TODO"] << ""
+        +++ thelink ! [rel "StyleSheet",
+                       href "style.css",
+                       thetype "text/css"] << ""
+        +++ thelink ! [rel "StyleSheet",
+                       href "blog.css",
+                       thetype "text/css"] << ""
+        +++ thelink ! [rel "shortcut icon",
+                       href "/favicon.ico",
+                       thetype "image/x-icon"] << ""
+        +++ (thetitle << ptitle)
+       )
+    +++
+    body
+    << pcontent
+
+
+-- Page specific templates
+
+mainIndexPage = page "All Unkept"
+                (h1 << "All Unkept" +++
+                 p << "This is a test")

File src/Blog/Views.hs

 
 import Web.Request
 import Web.Response
-import Data.ByteString.Lazy.Char8 (ByteString)
 import Web.Utils
-import Web.Framework (View)
+import Blog.Templates
 
-mainIndexPage :: ByteString
-mainIndexPage = "<h1>Hello, from “Luke's é web framework”</h1>" 
-
-mainIndex :: View
+mainIndex :: Request -> IO (Maybe Response)
 mainIndex req = let resp = buildResponse utf8HtmlResponse [
-                            addContent mainIndexPage
+                            addHtml mainIndexPage
                            ]
                 in return $ Just resp

File src/Web/Utils.hs

 
 import Data.ByteString.Lazy.Char8 (ByteString)
 import qualified Data.ByteString.Lazy.UTF8 as UTF8
+import Text.XHtml (renderHtml)
+import Web.Response (addContent)
+
 
 import GHC.Exts( IsString(..) )
 instance IsString ByteString where
     fromString = UTF8.fromString
 
-utf8 = UTF8.fromString
+utf8 = UTF8.fromString
+
+-- Utility functions
+addHtml html resp = addContent (utf8 $ renderHtml html) resp