Yammer (Twitter clone)
Yesod Screencast: Yammer from Michael Snoyman on Vimeo.
Introduction to Yesod Web Framework 0.5
Hello World
Blog, part 1
Blog Tutorial - Part 1 - Yesod Web Framework 0.4.0 from Michael Snoyman on Vimeo.
Here's the source code:
{-# LANGUAGE TypeFamilies, QuasiQuotes, GeneralizedNewtypeDeriving #-}
import Yesod
import Database.Persist.Sqlite
import Data.Time (Day)
mkPersist [$persist|
Entry
title String
day Day Desc
content Html'
deriving
|]
data Blog = Blog { pool :: Pool Connection }
mkYesod "Blog" [$parseRoutes|
/ RootR GET
/entry/#EntryId EntryR GET
|]
instance Yesod Blog where
approot _ = "http://localhost:3000"
instance YesodPersist Blog where
type YesodDB Blog = SqliteReader
runDB db = fmap pool getYesod>>= runSqlite db
getRootR = do
entries <- runDB $ select [] [EntryDayDesc]
applyLayoutW $ do
setTitle $ string "Yesod Blog Tutorial Homepage"
addBody [$hamlet|
%h1 Archive
%ul
$forall entries entry
%li
%[email protected]@ $entryTitle.snd.entry$
|]
getEntryR entryid = do
entry <- runDB $ get404 entryid
applyLayoutW $ do
setTitle $ string $ entryTitle entry
addBody [$hamlet|
%h1 $entryTitle.entry$
%h2 $show.entryDay.entry$
$entryContent.entry$
|]
withBlog f = withSqlite "blog.db3" 8 $ \pool -> do
flip runSqlite pool $ initialize (undefined :: Entry)
f $ Blog pool
main = withBlog $ basicHandler 3000
Blog, part 2
Blog Tutorial - Part 2 - Yesod Web Framework 0.4.0 from Michael Snoyman on Vimeo.
Here's the source code:
{-# LANGUAGE TypeFamilies, QuasiQuotes, GeneralizedNewtypeDeriving #-}
import Yesod
import Yesod.Helpers.Crud
import Database.Persist.Sqlite
import Data.Time (Day)
share2 mkToForm mkPersist [$persist|
Entry
title String
day JqueryDay Desc
content NicHtml
deriving
|]
instance Item Entry where
itemTitle = entryTitle
data Blog = Blog { pool :: Pool Connection }
type EntryCrud = Crud Blog Entry
mkYesod "Blog" [$parseRoutes|
/ RootR GET
/entry/#EntryId EntryR GET
/admin AdminR EntryCrud defaultCrud
|]
instance Yesod Blog where
approot _ = "http://localhost:3000"
instance YesodPersist Blog where
type YesodDB Blog = SqliteReader
runDB db = fmap pool getYesod>gt;>gt;= runSqlite db
getRootR = do
entries gt; do
flip runSqlite pool $ do
initialize (undefined :: Entry)
f $ Blog pool
main = withBlog $ basicHandler 3000