yesod/examples/hamlet.hs
2010-04-14 12:38:58 -07:00

42 lines
912 B
Haskell

{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Yesod
import Network.Wai.Handler.SimpleServer
data Ham = Ham
mkYesod "Ham" [$parseRoutes|
/ Homepage GET
/#another Another GET
|]
instance Yesod Ham where
approot _ = "http://localhost:3000"
data NextLink m = NextLink { nextLink :: m HamRoutes }
nl :: Monad m => HamRoutes -> NextLink m
nl = NextLink . return
template :: Monad m => NextLink m -> Hamlet HamRoutes m ()
template = [$hamlet|
%a!href=@nextLink@ Next page
|]
getHomepage :: Handler Ham RepHtml
getHomepage = hamletToRepHtml $ template $ nl $ Another 1
getAnother :: Integer -> Handler Ham RepHtml
getAnother i = hamletToRepHtml $ template $ nl next
where
next = case i of
5 -> Homepage
_ -> Another $ i + 1
main :: IO ()
main = do
putStrLn "Running..."
toWaiApp Ham >>= run 3000