diff --git a/yesod/scaffold/Application.hs.cg b/yesod/scaffold/Application.hs.cg index d7f831c2..df7f4b82 100644 --- a/yesod/scaffold/Application.hs.cg +++ b/yesod/scaffold/Application.hs.cg @@ -1,6 +1,6 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Application - ( getApplication + ( makeApplication , getApplicationDev ) where @@ -32,15 +32,9 @@ mkYesodDispatch "~sitearg~" resources~sitearg~ -- performs initialization and creates a WAI application. This is also the -- place to put your migrate statements to have automatic database -- migrations handled by Yesod. -getApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application -getApplication conf logger = do - manager <- newManager def - s <- staticSite - dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf) - Database.Persist.Store.loadConfig >>= - Database.Persist.Store.applyEnv - p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)~runMigration~ - let foundation = ~sitearg~ conf setLogger s p manager dbconf +makeApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application +makeApplication conf logger = do + foundation <- makeFoundation conf logger app <- toWaiAppPlain foundation return $ logWare app where @@ -52,10 +46,20 @@ getApplication conf logger = do logWare = logCallback (logBS setLogger) #endif +makeFoundation :: AppConfig DefaultEnv Extra -> Logger -> IO ~sitearg~ +makeFoundation conf _ = do + manager <- newManager def + s <- staticSite + dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf) + Database.Persist.Store.loadConfig >>= + Database.Persist.Store.applyEnv + p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)~runMigration~ + return $ ~sitearg~ conf setLogger s p manager dbconf + -- for yesod devel getApplicationDev :: IO (Int, Application) getApplicationDev = - defaultDevelApp loader getApplication + defaultDevelApp loader makeApplication where loader = loadConfig (configSettings Development) { csParseExtra = parseExtra diff --git a/yesod/scaffold/deploy/Procfile.cg b/yesod/scaffold/deploy/Procfile.cg index 837d0001..2dde3081 100644 --- a/yesod/scaffold/deploy/Procfile.cg +++ b/yesod/scaffold/deploy/Procfile.cg @@ -25,8 +25,8 @@ # #endif # # -# getApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application -# getApplication conf logger = do +# makeApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application +# makeApplication conf logger = do # manager <- newManager def # s <- staticSite # hconfig <- loadHerokuConfig diff --git a/yesod/scaffold/main.hs.cg b/yesod/scaffold/main.hs.cg index 4fbcefd0..a059fcb1 100644 --- a/yesod/scaffold/main.hs.cg +++ b/yesod/scaffold/main.hs.cg @@ -2,7 +2,7 @@ import Prelude (IO) import Yesod.Default.Config (fromArgs) import Yesod.Default.Main (defaultMain) import Settings (parseExtra) -import Application (getApplication) +import Application (makeApplication) main :: IO () -main = defaultMain (fromArgs parseExtra) getApplication +main = defaultMain (fromArgs parseExtra) makeApplication diff --git a/yesod/scaffold/tests/HomeTest.hs.cg b/yesod/scaffold/tests/HomeTest.hs.cg new file mode 100644 index 00000000..b5ed0f72 --- /dev/null +++ b/yesod/scaffold/tests/HomeTest.hs.cg @@ -0,0 +1,22 @@ +module TestHome (homeSpecs) where + +import Import +import Yesod.Test + +homeSpecs :: Specs +homeSpecs = + describe "These are some example tests" $ + it "loads the index and checks it looks right" $ do + get_ "/" + statusIs 200 + htmlAllContain "h1" "Hello" + + post "/" $ do + addNonce + fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference + byLabel "What's on the file?" "Some Content" + + statusIs 200 + htmlCount ".message" 1 + htmlAllContain ".message" "Some Content" + htmlAllContain ".message" "text/plain" diff --git a/yesod/scaffold/tests/main.hs.cg b/yesod/scaffold/tests/main.hs.cg index a9e8e47b..8ec0dd59 100644 --- a/yesod/scaffold/tests/main.hs.cg +++ b/yesod/scaffold/tests/main.hs.cg @@ -6,41 +6,15 @@ module Main where import Import import Settings -import Yesod.Static import Yesod.Logger (defaultDevelopmentLogger) -import qualified Database.Persist.Store -import Database.Persist.GenericSql (runMigration) import Yesod.Default.Config import Yesod.Test -import Network.HTTP.Conduit (newManager, def) -import Application() +import Application (makeFoundation) main :: IO a main = do conf <- loadConfig $ (configSettings Testing) { csParseExtra = parseExtra } - manager <- newManager def logger <- defaultDevelopmentLogger - dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf) - Database.Persist.Store.loadConfig - s <- static Settings.staticDir - p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)~runMigration~ - app <- toWaiAppPlain $ ~sitearg~ conf logger s p manager dbconf - runTests app p allTests - -allTests :: Specs -allTests = do - describe "These are some example tests" $ do - it "loads the index and checks it looks right" $ do - get_ "/" - statusIs 200 - htmlAllContain "h1" "Hello" - - post "/" $ do - addNonce - fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference - byLabel "What's on the file?" "Some Content" - - statusIs 200 - htmlCount ".message" 1 - htmlAllContain ".message" "Some Content" - htmlAllContain ".message" "text/plain" + foundation <- makeFoundation conf logger + app <- toWaiAppPlain foundation + runTests app (connPool foundation) homeSpecs diff --git a/yesod/scaffold/tiny/Application.hs.cg b/yesod/scaffold/tiny/Application.hs.cg index 917f6a37..73caa164 100644 --- a/yesod/scaffold/tiny/Application.hs.cg +++ b/yesod/scaffold/tiny/Application.hs.cg @@ -1,6 +1,6 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Application - ( getApplication + ( makeApplication , getApplicationDev ) where @@ -27,14 +27,18 @@ import Handler.Home -- the comments there for more details. mkYesodDispatch "~sitearg~" resources~sitearg~ +makeFoundation :: AppConfig DefaultEnv Extra -> Logger -> IO ~sitearg~ +makeFoundation conf _ = do + s <- staticSite + return $ ~sitearg~ conf setLogger s + -- This function allocates resources (such as a database connection pool), -- performs initialization and creates a WAI application. This is also the -- place to put your migrate statements to have automatic database -- migrations handled by Yesod. -getApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application -getApplication conf logger = do - s <- staticSite - let foundation = ~sitearg~ conf setLogger s +makeApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application +makeApplication conf logger = do + foundation <- makeFoundation app <- toWaiAppPlain foundation return $ logWare app where @@ -49,7 +53,7 @@ getApplication conf logger = do -- for yesod devel getApplicationDev :: IO (Int, Application) getApplicationDev = - defaultDevelApp loader getApplication + defaultDevelApp loader makeApplication where loader = loadConfig (configSettings Development) { csParseExtra = parseExtra diff --git a/yesod/scaffold/tiny/Foundation.hs.cg b/yesod/scaffold/tiny/Foundation.hs.cg index 1dbec877..c5906f6d 100644 --- a/yesod/scaffold/tiny/Foundation.hs.cg +++ b/yesod/scaffold/tiny/Foundation.hs.cg @@ -5,6 +5,7 @@ module Foundation , resources~sitearg~ , Handler , Widget + , Form , module Yesod.Core , module Settings , liftIO @@ -57,6 +58,8 @@ mkMessage "~sitearg~" "messages" "en" -- split these actions into two functions and place them in separate files. mkYesodData "~sitearg~" $(parseRoutesFile "config/routes") +type Form x = Html -> MForm ~sitearg~ ~sitearg~ (FormResult x, Widget) + -- Please see the documentation for the Yesod typeclass. There are a number -- of settings which can be configured by overriding methods here. instance Yesod ~sitearg~ where