Created
March 24, 2011 09:37
-
-
Save snoyberg/884802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings, TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell #-} | |
module Yesod.Dynamic | |
( YesodDynamic | |
, yesodDynamic | |
, Handler | |
, Widget | |
, Method | |
, returnY | |
) where | |
import Yesod.Content | |
import Yesod.Core | |
import Yesod.Handler | |
import Yesod.Widget | |
import Yesod.Dispatch | |
import Yesod.Request | |
import Network.Wai (Application, requestMethod) | |
import qualified Data.ByteString.Char8 as S8 | |
type Method = String | |
type Handler = GHandler YesodDynamic YesodDynamic ChooseRep | |
type Widget = GWidget YesodDynamic YesodDynamic | |
returnY :: HasReps a => a -> Handler | |
returnY = return . chooseRep | |
newtype YesodDynamic = YesodDynamic (Method -> [String] -> Handler) | |
yesodDynamic :: (Method -> [String] -> Handler) -> IO Application | |
yesodDynamic = toWaiApp . YesodDynamic | |
mkYesod "YesodDynamic" [$parseRoutes| | |
/*Strings RootR | |
|] | |
handleRootR :: Strings -> Handler | |
handleRootR pieces = do | |
req <- waiRequest | |
let method = S8.unpack $ requestMethod req | |
YesodDynamic f <- getYesod | |
f method pieces | |
instance Yesod YesodDynamic where | |
approot _ = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Yesod.Dynamic | |
import Yesod.Content | |
import Network.Wai.Handler.Warp (run) | |
import Network.Wai.Middleware.Debug (debug) | |
main = yesodDynamic app >>= run 3000 . debug | |
app _ _ = returnY $ RepPlain "Hello World" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment