From 469d58cf6d18bf9cf774d1c70334eeb7a5393066 Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 12:43:20 -0700 Subject: [PATCH 01/10] Revert "another Session hide" This reverts commit 589ab4a5472608479cf49178787e2315f03550f4. --- yesod-core/test/YesodCoreTest/CleanPath.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-core/test/YesodCoreTest/CleanPath.hs b/yesod-core/test/YesodCoreTest/CleanPath.hs index bacfbbc0..ba3d7a00 100644 --- a/yesod-core/test/YesodCoreTest/CleanPath.hs +++ b/yesod-core/test/YesodCoreTest/CleanPath.hs @@ -6,7 +6,7 @@ module YesodCoreTest.CleanPath (cleanPathTest, Widget) where import Test.Hspec import Test.Hspec.HUnit() -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Network.Wai import Network.Wai.Test From 47b89724e88bade7d1d59bd7c03b53be84c80982 Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 12:43:36 -0700 Subject: [PATCH 02/10] Revert "fix tests: import Yesod.Core hiding (Session)" This reverts commit f548a4c5666c2d065f091f06c5c356e7b05e6fd5. --- yesod-core/test/YesodCoreTest/Cache.hs | 2 +- yesod-core/test/YesodCoreTest/ErrorHandling.hs | 2 +- yesod-core/test/YesodCoreTest/Exceptions.hs | 2 +- yesod-core/test/YesodCoreTest/JsLoader.hs | 2 +- yesod-core/test/YesodCoreTest/Links.hs | 2 +- yesod-core/test/YesodCoreTest/Media.hs | 2 +- yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs | 2 +- yesod-core/test/YesodCoreTest/WaiSubsite.hs | 3 ++- yesod-core/test/YesodCoreTest/Widget.hs | 2 +- yesod-core/test/YesodCoreTest/YesodTest.hs | 2 +- 10 files changed, 11 insertions(+), 10 deletions(-) diff --git a/yesod-core/test/YesodCoreTest/Cache.hs b/yesod-core/test/YesodCoreTest/Cache.hs index 3553b1e2..30dcfaaa 100644 --- a/yesod-core/test/YesodCoreTest/Cache.hs +++ b/yesod-core/test/YesodCoreTest/Cache.hs @@ -9,7 +9,7 @@ import Test.Hspec.HUnit() import Network.Wai import Network.Wai.Test -import Yesod.Core hiding (Session) +import Yesod.Core data C = C diff --git a/yesod-core/test/YesodCoreTest/ErrorHandling.hs b/yesod-core/test/YesodCoreTest/ErrorHandling.hs index 64a978f8..40038082 100644 --- a/yesod-core/test/YesodCoreTest/ErrorHandling.hs +++ b/yesod-core/test/YesodCoreTest/ErrorHandling.hs @@ -3,7 +3,7 @@ module YesodCoreTest.ErrorHandling ( errorHandlingTest , Widget ) where -import Yesod.Core hiding (Session) +import Yesod.Core import Test.Hspec import Test.Hspec.HUnit() import Network.Wai diff --git a/yesod-core/test/YesodCoreTest/Exceptions.hs b/yesod-core/test/YesodCoreTest/Exceptions.hs index 356bf0a0..93368b7a 100644 --- a/yesod-core/test/YesodCoreTest/Exceptions.hs +++ b/yesod-core/test/YesodCoreTest/Exceptions.hs @@ -6,7 +6,7 @@ module YesodCoreTest.Exceptions (exceptionsTest, Widget) where import Test.Hspec import Test.Hspec.HUnit () -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Network.Wai import Network.Wai.Test import Network.HTTP.Types (status301) diff --git a/yesod-core/test/YesodCoreTest/JsLoader.hs b/yesod-core/test/YesodCoreTest/JsLoader.hs index a8b6261c..676e0f1d 100644 --- a/yesod-core/test/YesodCoreTest/JsLoader.hs +++ b/yesod-core/test/YesodCoreTest/JsLoader.hs @@ -9,7 +9,7 @@ import YesodCoreTest.JsLoaderSites.Bottom (B(..)) import Test.Hspec import Test.Hspec.HUnit () -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Network.Wai.Test data H = H diff --git a/yesod-core/test/YesodCoreTest/Links.hs b/yesod-core/test/YesodCoreTest/Links.hs index 237899bc..34b5dc4c 100644 --- a/yesod-core/test/YesodCoreTest/Links.hs +++ b/yesod-core/test/YesodCoreTest/Links.hs @@ -6,7 +6,7 @@ module YesodCoreTest.Links (linksTest, Widget) where import Test.Hspec import Test.Hspec.HUnit () -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Text.Hamlet import Network.Wai.Test diff --git a/yesod-core/test/YesodCoreTest/Media.hs b/yesod-core/test/YesodCoreTest/Media.hs index 9922b402..7ce98286 100644 --- a/yesod-core/test/YesodCoreTest/Media.hs +++ b/yesod-core/test/YesodCoreTest/Media.hs @@ -6,7 +6,7 @@ module YesodCoreTest.Media (mediaTest, Widget) where import Test.Hspec import Test.Hspec.HUnit () -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Network.Wai import Network.Wai.Test import Text.Lucius diff --git a/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs b/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs index 98c538d7..b32e6d65 100644 --- a/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs +++ b/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs @@ -5,7 +5,7 @@ module YesodCoreTest.NoOverloadedStrings (noOverloadedTest, Widget) where import Test.Hspec import Test.Hspec.HUnit () -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Network.Wai.Test import Data.Monoid (mempty) diff --git a/yesod-core/test/YesodCoreTest/WaiSubsite.hs b/yesod-core/test/YesodCoreTest/WaiSubsite.hs index 6fcb38d2..baf66979 100644 --- a/yesod-core/test/YesodCoreTest/WaiSubsite.hs +++ b/yesod-core/test/YesodCoreTest/WaiSubsite.hs @@ -2,8 +2,9 @@ module YesodCoreTest.WaiSubsite (specs, Widget) where import YesodCoreTest.YesodTest -import Yesod.Core hiding (Session) +import Yesod.Core import qualified Network.HTTP.Types as H +import Network.Wai myApp :: Application myApp _ = return $ responseLBS H.status200 [("Content-type", "text/plain")] "WAI" diff --git a/yesod-core/test/YesodCoreTest/Widget.hs b/yesod-core/test/YesodCoreTest/Widget.hs index 5ba4bfd3..f102136e 100644 --- a/yesod-core/test/YesodCoreTest/Widget.hs +++ b/yesod-core/test/YesodCoreTest/Widget.hs @@ -6,7 +6,7 @@ module YesodCoreTest.Widget (widgetTest) where import Test.Hspec import Test.Hspec.HUnit () -import Yesod.Core hiding (Request, Session) +import Yesod.Core hiding (Request) import Text.Julius import Text.Lucius import Text.Hamlet diff --git a/yesod-core/test/YesodCoreTest/YesodTest.hs b/yesod-core/test/YesodCoreTest/YesodTest.hs index 07585554..46040f84 100644 --- a/yesod-core/test/YesodCoreTest/YesodTest.hs +++ b/yesod-core/test/YesodCoreTest/YesodTest.hs @@ -9,7 +9,7 @@ module YesodCoreTest.YesodTest , module Test.Hspec ) where -import Yesod.Core hiding (Session, Request) +import Yesod.Core hiding (Request) import Network.Wai.Test import Network.Wai import Test.Hspec From 3bb3db16b1871007d2590e0f4ffd6262a0599ba9 Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 12:43:53 -0700 Subject: [PATCH 03/10] Revert "fix Session export" This reverts commit 03634a13b8f0d3d5d4df1cfdce2486db6334ae03. --- yesod-core/Yesod/Core.hs | 2 +- yesod-core/Yesod/Internal/Core.hs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/yesod-core/Yesod/Core.hs b/yesod-core/Yesod/Core.hs index e9e4b4bc..8a1c0dd2 100644 --- a/yesod-core/Yesod/Core.hs +++ b/yesod-core/Yesod/Core.hs @@ -52,7 +52,7 @@ module Yesod.Core ) where import Yesod.Internal.Core -import Yesod.Internal (Header(..)) +import Yesod.Internal import Yesod.Content import Yesod.Dispatch import Yesod.Handler diff --git a/yesod-core/Yesod/Internal/Core.hs b/yesod-core/Yesod/Internal/Core.hs index 0beb568b..0726cca2 100644 --- a/yesod-core/Yesod/Internal/Core.hs +++ b/yesod-core/Yesod/Internal/Core.hs @@ -26,7 +26,6 @@ module Yesod.Internal.Core , fileLocationToString , messageLoggerHandler -- * Sessions - , Session , SessionBackend (..) , defaultClientSessionBackend , clientSessionBackend From f147e7623101cdfbb55647d80e6de9e8c71cb019 Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 12:44:34 -0700 Subject: [PATCH 04/10] Revert "Session and Headers exportet" This reverts commit f58a695c84bc4e3b532c94e8dc8c810c58ee6ff7. --- yesod-core/Yesod/Core.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/yesod-core/Yesod/Core.hs b/yesod-core/Yesod/Core.hs index 8a1c0dd2..4362cee1 100644 --- a/yesod-core/Yesod/Core.hs +++ b/yesod-core/Yesod/Core.hs @@ -28,13 +28,11 @@ module Yesod.Core , logError , logOther -- * Sessions - , Session , SessionBackend (..) , defaultClientSessionBackend , clientSessionBackend , saveClientSession , loadClientSession - , Header(..) -- * JS loaders , loadJsYepnope , ScriptLoadPosition (..) @@ -52,7 +50,6 @@ module Yesod.Core ) where import Yesod.Internal.Core -import Yesod.Internal import Yesod.Content import Yesod.Dispatch import Yesod.Handler From 3f0848121c27c8fb76e1c6a8c29696aec71b58ca Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 13:28:31 -0700 Subject: [PATCH 05/10] Session -> BackendSession --- yesod-core/Yesod/Core.hs | 3 +++ yesod-core/Yesod/Internal/Core.hs | 23 +++++---------------- yesod-core/Yesod/Internal/Session.hs | 21 +++++++++++++++++++ yesod-core/test/YesodCoreTest/WaiSubsite.hs | 1 - 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/yesod-core/Yesod/Core.hs b/yesod-core/Yesod/Core.hs index 4362cee1..27f9c8be 100644 --- a/yesod-core/Yesod/Core.hs +++ b/yesod-core/Yesod/Core.hs @@ -33,6 +33,8 @@ module Yesod.Core , clientSessionBackend , saveClientSession , loadClientSession + , Header(..) + , BackendSession -- * JS loaders , loadJsYepnope , ScriptLoadPosition (..) @@ -50,6 +52,7 @@ module Yesod.Core ) where import Yesod.Internal.Core +import Yesod.Internal (Header(..)) import Yesod.Content import Yesod.Dispatch import Yesod.Handler diff --git a/yesod-core/Yesod/Internal/Core.hs b/yesod-core/Yesod/Internal/Core.hs index 0726cca2..6482e137 100644 --- a/yesod-core/Yesod/Internal/Core.hs +++ b/yesod-core/Yesod/Internal/Core.hs @@ -31,6 +31,7 @@ module Yesod.Internal.Core , clientSessionBackend , saveClientSession , loadClientSession + , BackendSession -- * jsLoader , ScriptLoadPosition (..) , BottomOfHeadAsync @@ -323,20 +324,6 @@ $doctype 5 key <- CS.getKey CS.defaultKeyFile return $ Just $ clientSessionBackend key 120 -type Session = [(Text, S8.ByteString)] - -data SessionBackend master = SessionBackend - { sbSaveSession :: master - -> W.Request - -> UTCTime -- ^ The current time - -> Session -- ^ The old session (before running handler) - -> Session -- ^ The final session - -> IO [Header] - , sbLoadSession :: master - -> W.Request - -> UTCTime -- ^ The current time - -> IO Session - } messageLoggerHandler :: Yesod m => Loc -> LogLevel -> Text -> GHandler s m () @@ -724,7 +711,7 @@ loadClientSession :: Yesod master -> master -> W.Request -> UTCTime - -> IO Session + -> IO BackendSession loadClientSession key _ req now = return . fromMaybe [] $ do raw <- lookup "Cookie" $ W.requestHeaders req val <- lookup sessionName $ parseCookies raw @@ -737,12 +724,12 @@ saveClientSession :: Yesod master -> master -> W.Request -> UTCTime - -> Session - -> Session + -> BackendSession + -> BackendSession -> IO [Header] saveClientSession key timeout master _ now _ sess = do -- fixme should we be caching this? - iv <- liftIO $ CS.randomIV + iv <- liftIO CS.randomIV return [AddCookie def { setCookieName = sessionName , setCookieValue = sessionVal iv diff --git a/yesod-core/Yesod/Internal/Session.hs b/yesod-core/Yesod/Internal/Session.hs index 320f7b86..ac84a862 100644 --- a/yesod-core/Yesod/Internal/Session.hs +++ b/yesod-core/Yesod/Internal/Session.hs @@ -1,8 +1,11 @@ module Yesod.Internal.Session ( encodeClientSession , decodeClientSession + , BackendSession + , SessionBackend(..) ) where +import Yesod.Internal (Header(..)) import qualified Web.ClientSession as CS import Data.Serialize import Data.Time @@ -12,6 +15,24 @@ import Data.Text (Text, pack, unpack) import Control.Arrow (first) import Control.Applicative ((<$>)) +import qualified Data.ByteString.Char8 as S8 +import qualified Network.Wai as W + +type BackendSession = [(Text, S8.ByteString)] + +data SessionBackend master = SessionBackend + { sbSaveSession :: master + -> W.Request + -> UTCTime -- ^ The current time + -> BackendSession -- ^ The old session (before running handler) + -> BackendSession -- ^ The final session + -> IO [Header] + , sbLoadSession :: master + -> W.Request + -> UTCTime -- ^ The current time + -> IO BackendSession + } + encodeClientSession :: CS.Key -> CS.IV -> UTCTime -- ^ expire time diff --git a/yesod-core/test/YesodCoreTest/WaiSubsite.hs b/yesod-core/test/YesodCoreTest/WaiSubsite.hs index baf66979..ee313c32 100644 --- a/yesod-core/test/YesodCoreTest/WaiSubsite.hs +++ b/yesod-core/test/YesodCoreTest/WaiSubsite.hs @@ -4,7 +4,6 @@ module YesodCoreTest.WaiSubsite (specs, Widget) where import YesodCoreTest.YesodTest import Yesod.Core import qualified Network.HTTP.Types as H -import Network.Wai myApp :: Application myApp _ = return $ responseLBS H.status200 [("Content-type", "text/plain")] "WAI" From cff17e632116e76d16790039b09e06b18c5c11da Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 17:22:53 -0700 Subject: [PATCH 06/10] ignore .virthualenv --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fe358fd0..e809c018 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ client_session_key.aes cabal-dev/ yesod/foobar/ yesod-platform/yesod-platform.cabal +.virthualenv From 40cfd1f85748ed1da4f07b43b0b56b2bfa0015a9 Mon Sep 17 00:00:00 2001 From: gregwebs Date: Sun, 25 Mar 2012 21:21:59 -0700 Subject: [PATCH 07/10] build yesod-test --- sources.txt | 1 + yesod-test/yesod-test.cabal | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sources.txt b/sources.txt index b5266622..393ada49 100644 --- a/sources.txt +++ b/sources.txt @@ -9,3 +9,4 @@ ./yesod-sitemap ./yesod-default ./yesod +./yesod-test diff --git a/yesod-test/yesod-test.cabal b/yesod-test/yesod-test.cabal index f038e611..401eae81 100644 --- a/yesod-test/yesod-test.cabal +++ b/yesod-test/yesod-test.cabal @@ -23,9 +23,9 @@ library build-depends: base >= 4 && < 4.3 build-depends: hxt >= 9.1.6 , parsec >= 2.1 && < 4 - , persistent >= 0.8 && < 0.9 + , persistent >= 0.8 && < 1.1 , transformers >= 0.2.2 && < 0.3 - , wai >= 1.1 && < 1.2 + , wai >= 1.1 && < 1.3 , wai-test >= 1.0 && < 2.0 , network >= 2.2 && < 2.4 , http-types >= 0.6 && < 0.7 From a3cdb27ff09997bd05a6d9cb06a58fb55733e63a Mon Sep 17 00:00:00 2001 From: gregwebs Date: Mon, 26 Mar 2012 09:23:07 -0700 Subject: [PATCH 08/10] hlint --- yesod/Scaffolding/Scaffolder.hs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/yesod/Scaffolding/Scaffolder.hs b/yesod/Scaffolding/Scaffolder.hs index 546b2029..499326d7 100644 --- a/yesod/Scaffolding/Scaffolder.hs +++ b/yesod/Scaffolding/Scaffolder.hs @@ -109,10 +109,10 @@ scaffold = do putStrLn "That's it! I'm creating your files now..." let withConnectionPool = case backend of - Sqlite -> $(codegen $ "sqliteConnPool") - Postgresql -> $(codegen $ "postgresqlConnPool") + Sqlite -> $(codegen "sqliteConnPool") + Postgresql -> $(codegen "postgresqlConnPool") Mysql -> "" - MongoDB -> $(codegen $ "mongoDBConnPool") + MongoDB -> $(codegen "mongoDBConnPool") Tiny -> "" packages = @@ -144,29 +144,29 @@ scaffold = do mkDir "Settings" mkDir "messages" - writeFile' ("deploy/Procfile") $(codegen "deploy/Procfile") + writeFile' "deploy/Procfile" $(codegen "deploy/Procfile") case backend of - Sqlite -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/sqlite.yml")) - Postgresql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/postgresql.yml")) - MongoDB -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mongoDB.yml")) - Mysql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen ("config/mysql.yml")) + Sqlite -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen "config/sqlite.yml") + Postgresql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen "config/postgresql.yml") + MongoDB -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen "config/mongoDB.yml") + Mysql -> writeFile' ("config/" ++ backendLower ++ ".yml") $(codegen "config/mysql.yml") Tiny -> return () let isTiny = backend == Tiny ifTiny a b = if isTiny then a else b - writeFile' ("config/settings.yml") $(codegen "config/settings.yml") - writeFile' ("main.hs") $(codegen "main.hs") - writeFile' ("devel.hs") $(codegen "devel.hs") + writeFile' "config/settings.yml" $(codegen "config/settings.yml") + writeFile' "main.hs" $(codegen "main.hs") + writeFile' "devel.hs" $(codegen "devel.hs") writeFile' (project ++ ".cabal") $ ifTiny $(codegen "tiny/project.cabal") $(codegen "project.cabal") - when useTests $ do + when useTests $ appendFile' (project ++ ".cabal") $(codegen "cabal_test_suite") writeFile' ".ghci" $(codegen ".ghci") writeFile' "LICENSE" $(codegen "LICENSE") - writeFile' ("Foundation.hs") $ ifTiny $(codegen "tiny/Foundation.hs") $(codegen "Foundation.hs") - writeFile' ("Import.hs") $ ifTiny $(codegen "tiny/Import.hs") $(codegen "Import.hs") + writeFile' "Foundation.hs" $ ifTiny $(codegen "tiny/Foundation.hs") $(codegen "Foundation.hs") + writeFile' "Import.hs" $ ifTiny $(codegen "tiny/Import.hs") $(codegen "Import.hs") writeFile' "Application.hs" $ ifTiny $(codegen "tiny/Application.hs") $(codegen "Application.hs") writeFile' "Handler/Home.hs" $(codegen "Handler/Home.hs") unless isTiny $ writeFile' "Model.hs" $(codegen "Model.hs") @@ -200,7 +200,7 @@ scaffold = do return $ pack `AppE` LitE (StringL $ S.unpack bs)) S.writeFile (dir ++ "/config/robots.txt") - $(runIO (S.readFile "scaffold/config/robots.txt.cg") >>= \bs -> do + $(runIO (S.readFile "scaffold/config/robots.txt.cg") >>= \bs -> [|S.pack $(return $ LitE $ StringL $ S.unpack bs)|]) putStr $(codegenDir "input" "done") From 127ddf7181afe69a9f8c957e28f4df31d401148a Mon Sep 17 00:00:00 2001 From: gregwebs Date: Mon, 26 Mar 2012 09:23:35 -0700 Subject: [PATCH 09/10] scaffolding fixes breakup getApplication into makeFoundation and makeApplication that way tests can re-use makeFoundation --- yesod/scaffold/Application.hs.cg | 26 +++++++++++--------- yesod/scaffold/deploy/Procfile.cg | 4 ++-- yesod/scaffold/main.hs.cg | 4 ++-- yesod/scaffold/tests/HomeTest.hs.cg | 22 +++++++++++++++++ yesod/scaffold/tests/main.hs.cg | 34 ++++----------------------- yesod/scaffold/tiny/Application.hs.cg | 16 ++++++++----- yesod/scaffold/tiny/Foundation.hs.cg | 3 +++ 7 files changed, 58 insertions(+), 51 deletions(-) create mode 100644 yesod/scaffold/tests/HomeTest.hs.cg 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 From 4545b2a91de0a8052039662754b671025fa58240 Mon Sep 17 00:00:00 2001 From: gregwebs Date: Mon, 26 Mar 2012 11:18:24 -0700 Subject: [PATCH 10/10] fix need form import --- yesod/scaffold/tiny/Foundation.hs.cg | 1 + yesod/scaffold/tiny/project.cabal.cg | 1 + 2 files changed, 2 insertions(+) diff --git a/yesod/scaffold/tiny/Foundation.hs.cg b/yesod/scaffold/tiny/Foundation.hs.cg index c5906f6d..cc6b65f7 100644 --- a/yesod/scaffold/tiny/Foundation.hs.cg +++ b/yesod/scaffold/tiny/Foundation.hs.cg @@ -13,6 +13,7 @@ module Foundation import Prelude import Yesod.Core hiding (Route) +import Yesod.Form import Yesod.Default.Config import Yesod.Default.Util (addStaticContentExternal) import Yesod.Static diff --git a/yesod/scaffold/tiny/project.cabal.cg b/yesod/scaffold/tiny/project.cabal.cg index 38600c9b..9577b080 100644 --- a/yesod/scaffold/tiny/project.cabal.cg +++ b/yesod/scaffold/tiny/project.cabal.cg @@ -67,6 +67,7 @@ executable ~project~ build-depends: base >= 4 && < 5 , yesod-core >= 1.0 && < 1.1 + , yesod-form >= 1.0 && < 1.1 , yesod-static >= 1.0 && < 1.1 , yesod-default >= 1.0 && < 1.1 , clientsession >= 0.7.3 && < 0.8