fix scaffolding

This commit is contained in:
Greg Weber 2011-08-23 07:25:54 -07:00
parent 9b9b021705
commit c0a8a53ad2
3 changed files with 29 additions and 30 deletions

View File

@ -83,11 +83,10 @@ devel cabalCmd = do
, concat , concat
[ "import \"" [ "import \""
, pi' , pi'
, "\" Application (withDevelApp)" , "\" Application (withDevelAppPort)"
] ]
, "import Data.Dynamic (fromDynamic)" , "import Data.Dynamic (fromDynamic)"
, "import Network.Wai.Handler.Warp (run)" , "import Network.Wai.Handler.Warp (run)"
, "import Network.Wai.Middleware.Debug (debugHandle)"
, "import Data.Maybe (fromJust)" , "import Data.Maybe (fromJust)"
, "import Control.Concurrent (forkIO)" , "import Control.Concurrent (forkIO)"
, "import System.Directory (doesFileExist, removeFile)" , "import System.Directory (doesFileExist, removeFile)"
@ -97,7 +96,7 @@ devel cabalCmd = do
, "main = do" , "main = do"
, " putStrLn \"Starting app\"" , " putStrLn \"Starting app\""
, " wdap <- return $ fromJust $ fromDynamic withDevelAppPort" , " wdap <- return $ fromJust $ fromDynamic withDevelAppPort"
, " forkIO $ wdap $ \\(port, debugLogHandle app) -> (run port . debugHandle debugLogHandle) app" , " forkIO $ wdap $ \\(port, app) -> run port app"
, " loop" , " loop"
, "" , ""
, "loop :: IO ()" , "loop :: IO ()"

View File

@ -46,6 +46,11 @@ getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)
-- migrations handled by Yesod. -- migrations handled by Yesod.
with~sitearg~ :: AppConfig -> Logger -> (Application -> IO a) -> IO () with~sitearg~ :: AppConfig -> Logger -> (Application -> IO a) -> IO ()
with~sitearg~ conf logger f = do with~sitearg~ conf logger f = do
#ifdef PRODUCTION
s <- static Settings.staticDir
#else
s <- staticDevel Settings.staticDir
#endif
Settings.withConnectionPool conf $ \p -> do Settings.withConnectionPool conf $ \p -> do
runConnectionPool (runMigration migrateAll) p runConnectionPool (runMigration migrateAll) p
let h = ~sitearg~ conf logger s p let h = ~sitearg~ conf logger s p
@ -60,12 +65,6 @@ with~sitearg~ conf logger f = do
putMVar flag ()) Nothing putMVar flag ()) Nothing
takeMVar flag takeMVar flag
#endif #endif
where
#ifdef PRODUCTION
s = static Settings.staticDir
#else
s = staticDevel Settings.staticDir
#endif
-- for yesod devel -- for yesod devel
withDevelApp :: Dynamic withDevelApp :: Dynamic

View File

@ -1,19 +1,21 @@
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_GHC -fno-warn-orphans #-}
module Application module Application
( with~sitearg~ ( with~sitearg~
, withDevelApp , withDevelAppPort
) where ) where
import Foundation import Foundation
import Settings import Settings
import Yesod.Static import Yesod.Static
import Yesod.Logger (makeLogger, flushLogger, Logger) import Yesod.Logger (makeLogger, flushLogger, Logger, logLazyText, logString)
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Network.Wai (Application) import Network.Wai (Application)
import Data.Dynamic (Dynamic, toDyn) import Data.Dynamic (Dynamic, toDyn)
import Network.Wai.Middleware.Debug (debugHandle)
-- Import all relevant handler modules here. -- Import all relevant handler modules here.
import Handler.Root import Handler.Root
@ -37,18 +39,17 @@ getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)
-- migrations handled by Yesod. -- migrations handled by Yesod.
with~sitearg~ :: AppConfig -> Logger -> (Application -> IO a) -> IO a with~sitearg~ :: AppConfig -> Logger -> (Application -> IO a) -> IO a
with~sitearg~ conf logger f = do with~sitearg~ conf logger f = do
#ifdef PRODUCTION
s <- static Settings.staticDir
#else
s <- staticDevel Settings.staticDir
#endif
let h = ~sitearg~ conf logger s let h = ~sitearg~ conf logger s
toWaiApp h >>= f toWaiApp h >>= f
where
#ifdef PRODUCTION
s = static Settings.staticDir
#else
s = staticDevel Settings.staticDir
#endif
-- for yesod devel -- for yesod devel
withDevelApp :: Dynamic withDevelAppPort :: Dynamic
withDevelApp = withDevelAppPort =
toDyn go toDyn go
where where
go :: ((Int, Application) -> IO ()) -> IO () go :: ((Int, Application) -> IO ()) -> IO ()