Simplify Post
You need to import this as qualified or things will break. Also add some blaze crap for the lols
This commit is contained in:
parent
1a31e0146a
commit
7bc70e9753
|
@ -3,17 +3,17 @@ module Main where
|
||||||
|
|
||||||
import qualified Database.SQLite.Simple as Db
|
import qualified Database.SQLite.Simple as Db
|
||||||
import qualified Web.Spock.Safe as S hiding (head)
|
import qualified Web.Spock.Safe as S hiding (head)
|
||||||
import Within.DBMemorial.Post
|
import qualified Within.DBMemorial.Post as Post
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
conn <- Db.open "../db/posts.db"
|
conn <- Db.open "../db/posts.db"
|
||||||
|
|
||||||
-- Simple tests to prove we're reading from SQLite
|
-- 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
|
let h = head r
|
||||||
|
|
||||||
-- Set up the URL router
|
-- Set up the URL router
|
||||||
S.runSpock 5000 $ S.spockT id $ do
|
S.runSpock 5000 $ S.spockT id $ do
|
||||||
S.get S.root $
|
S.get S.root $
|
||||||
S.text $ postBody h
|
S.text $ Post.body h
|
||||||
|
|
|
@ -7,12 +7,12 @@ import Data.Text
|
||||||
import Database.SQLite.Simple.FromRow
|
import Database.SQLite.Simple.FromRow
|
||||||
|
|
||||||
data Post = Post
|
data Post = Post
|
||||||
{ postID :: Int
|
{ id :: Int
|
||||||
, postOID :: Text
|
, oID :: Text
|
||||||
, postBody :: Text
|
, body :: Text
|
||||||
, postMarkdown :: Text
|
, markdown :: Text
|
||||||
, postAuthor :: Text
|
, author :: Text
|
||||||
, postPage :: Int
|
, page :: Int
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
instance FromRow Post where
|
instance FromRow Post where
|
||||||
|
|
|
@ -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"
|
Loading…
Reference in New Issue