From 7bc70e97536c8e9404040cd0f32dbb069d9ca91f Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 27 Jul 2015 23:53:11 -0700 Subject: [PATCH] Simplify Post You need to import this as qualified or things will break. Also add some blaze crap for the lols --- web/src/Main.hs | 6 +++--- web/src/Within/DBMemorial/Post.hs | 12 ++++++------ web/src/Within/DBMemorial/Views/Example.hs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 web/src/Within/DBMemorial/Views/Example.hs diff --git a/web/src/Main.hs b/web/src/Main.hs index 03e381a..154e359 100644 --- a/web/src/Main.hs +++ b/web/src/Main.hs @@ -3,17 +3,17 @@ module Main where import qualified Database.SQLite.Simple as Db import qualified Web.Spock.Safe as S hiding (head) -import Within.DBMemorial.Post +import qualified Within.DBMemorial.Post as Post main :: IO () main = do conn <- Db.open "../db/posts.db" -- Simple tests to prove we're reading from SQLite - r <- Db.query_ conn "SELECT * FROM Posts WHERE page=1" :: IO [Post] + r <- Db.query_ conn "SELECT * FROM Posts WHERE page=1" :: IO [Post.Post] let h = head r -- Set up the URL router S.runSpock 5000 $ S.spockT id $ do S.get S.root $ - S.text $ postBody h + S.text $ Post.body h diff --git a/web/src/Within/DBMemorial/Post.hs b/web/src/Within/DBMemorial/Post.hs index b9e55dd..c0b70c3 100644 --- a/web/src/Within/DBMemorial/Post.hs +++ b/web/src/Within/DBMemorial/Post.hs @@ -7,12 +7,12 @@ import Data.Text import Database.SQLite.Simple.FromRow data Post = Post - { postID :: Int - , postOID :: Text - , postBody :: Text - , postMarkdown :: Text - , postAuthor :: Text - , postPage :: Int + { id :: Int + , oID :: Text + , body :: Text + , markdown :: Text + , author :: Text + , page :: Int } deriving (Show, Eq) instance FromRow Post where diff --git a/web/src/Within/DBMemorial/Views/Example.hs b/web/src/Within/DBMemorial/Views/Example.hs new file mode 100644 index 0000000..04667cb --- /dev/null +++ b/web/src/Within/DBMemorial/Views/Example.hs @@ -0,0 +1,19 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Within.DBMemorial.Views.Example where + +import Control.Monad (forM_) +import Text.Blaze.Html +import Text.Blaze.Html5 as H +import Text.Blaze.Html5.Attributes as A + +numbers :: Int -> Html +numbers n = docTypeHtml $ do + H.head $ do + H.title "Natural numbers" + body $ do + p "A list of natural numbers:" + ul $ forM_ [1 .. n] (li . toHtml) + +simpleImage :: Html +simpleImage = img ! src "foo.png"