New Scaffold! hurrah!

This commit is contained in:
patrick brisbin 2011-09-21 18:52:57 -04:00
parent a20c28dfad
commit a6e7924e7c
16 changed files with 38 additions and 24 deletions

View File

@ -12,6 +12,8 @@ import Foundation
import Settings import Settings
import Settings.StaticFiles (static) import Settings.StaticFiles (static)
import Yesod.Auth import Yesod.Auth
import Yesod.Default.Config
import Yesod.Default.Main
import Yesod.Logger (Logger) import Yesod.Logger (Logger)
import Database.Persist.~importGenericDB~ import Database.Persist.~importGenericDB~
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
@ -43,7 +45,7 @@ getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)
-- performs initialization and creates a WAI application. This is also the -- performs initialization and creates a WAI application. This is also the
-- place to put your migrate statements to have automatic database -- place to put your migrate statements to have automatic database
-- migrations handled by Yesod. -- migrations handled by Yesod.
with~sitearg~ :: AppConfig -> Logger -> (Application -> IO a) -> IO () with~sitearg~ :: AppConfig DefaultEnv -> Logger -> (Application -> IO a) -> IO ()
with~sitearg~ conf logger f = do with~sitearg~ conf logger f = do
s <- static Settings.staticDir s <- static Settings.staticDir
Settings.withConnectionPool conf $ \p -> do~runMigration~ Settings.withConnectionPool conf $ \p -> do~runMigration~

View File

@ -22,6 +22,7 @@ import Settings.StaticFiles
import Yesod.Auth import Yesod.Auth
import Yesod.Auth.OpenId import Yesod.Auth.OpenId
import Yesod.Auth.Email import Yesod.Auth.Email
import Yesod.Default.Config
import Yesod.Logger (Logger, logLazyText) import Yesod.Logger (Logger, logLazyText)
import qualified Settings import qualified Settings
import System.Directory import System.Directory
@ -45,7 +46,7 @@ import Text.Shakespeare.Text (stext)
-- starts running, such as database connections. Every handler will have -- starts running, such as database connections. Every handler will have
-- access to the data present here. -- access to the data present here.
data ~sitearg~ = ~sitearg~ data ~sitearg~ = ~sitearg~
{ settings :: AppConfig { settings :: AppConfig DefaultEnv
, getLogger :: Logger , getLogger :: Logger
, getStatic :: Static -- ^ Settings for static file serving. , getStatic :: Static -- ^ Settings for static file serving.
, connPool :: Settings.ConnectionPool -- ^ Database connection pool. , connPool :: Settings.ConnectionPool -- ^ Database connection pool.

View File

@ -29,7 +29,7 @@ import Text.Shakespeare.Text (st)
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
import Database.Persist.~importPersist~ import Database.Persist.~importPersist~
import Yesod (liftIO, MonadControlIO, addWidget, addCassius, addJulius, addLucius, whamletFile) import Yesod (liftIO, MonadControlIO, addWidget, addCassius, addJulius, addLucius, whamletFile)
import Yesod.Settings import Yesod.Default.Config
import Data.Monoid (mempty) import Data.Monoid (mempty)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import Data.Text (Text) import Data.Text (Text)
@ -55,7 +55,7 @@ staticDir = "static"
-- have to make a corresponding change here. -- have to make a corresponding change here.
-- --
-- To see how this value is used, see urlRenderOverride in Foundation.hs -- To see how this value is used, see urlRenderOverride in Foundation.hs
staticRoot :: AppConfig -> Text staticRoot :: AppConfig DefaultEnv -> Text
staticRoot conf = [st|#{appRoot conf}/static|] staticRoot conf = [st|#{appRoot conf}/static|]

View File

@ -4,6 +4,7 @@ Default: &defaults
host: localhost host: localhost
port: 27017 port: 27017
database: ~project~ database: ~project~
poolsize: 10
Development: Development:
<<: *defaults <<: *defaults
@ -14,8 +15,10 @@ Test:
Staging: Staging:
database: ~project~_staging database: ~project~_staging
poolsize: 100
<<: *defaults <<: *defaults
Production: Production:
database: ~project~_production database: ~project~_production
poolsize: 100
<<: *defaults <<: *defaults

View File

@ -4,6 +4,7 @@ Default: &defaults
host: localhost host: localhost
port: 5432 port: 5432
database: ~project~ database: ~project~
poolsize: 10
Development: Development:
<<: *defaults <<: *defaults
@ -14,7 +15,10 @@ Test:
Staging: Staging:
database: ~project~_staging database: ~project~_staging
poolsize: 100
<<: *defaults
Production: Production:
database: ~project~_production database: ~project~_production
poolsize: 100
<<: *defaults <<: *defaults

View File

@ -1,7 +1,6 @@
Default: &defaults Default: &defaults
host: "http://localhost" host: "http://localhost"
port: 3000 port: 3000
connectionPoolSize: 10
Development: Development:
<<: *defaults <<: *defaults

View File

@ -1,5 +1,6 @@
Default: &defaults Default: &defaults
database: ~project~.sqlite3 database: ~project~.sqlite3
poolsize: 10
Development: Development:
<<: *defaults <<: *defaults
@ -10,8 +11,10 @@ Test:
Staging: Staging:
database: ~project~_staging.sqlite3 database: ~project~_staging.sqlite3
poolsize: 100
<<: *defaults <<: *defaults
Production: Production:
database: ~project~_production.sqlite3 database: ~project~_production.sqlite3
poolsize: 100
<<: *defaults <<: *defaults

View File

@ -1,5 +1,6 @@
import Yesod.Main (defaultMain, fromArgs) import Yesod.Default.Config (fromArgs)
import Application (with~sitearg~) import Yesod.Default.Main (defaultMain)
import Application (with~sitearg~)
main :: IO () main :: IO ()
main = defaultMain fromArgs with~sitearg~ main = defaultMain fromArgs with~sitearg~

View File

@ -1,8 +1,8 @@
runConnectionPool :: MonadControlIO m => Action m a -> ConnectionPool -> m a runConnectionPool :: MonadControlIO m => Action m a -> ConnectionPool -> m a
runConnectionPool = runMongoDBConn (ConfirmWrites [u"j" =: True]) runConnectionPool = runMongoDBConn (ConfirmWrites [u"j" =: True])
withConnectionPool :: (MonadControlIO m, Applicative m) => AppConfig -> (ConnectionPool -> m b) -> m b withConnectionPool :: (MonadControlIO m, Applicative m) => AppConfig DefaultEnv -> (ConnectionPool -> m b) -> m b
withConnectionPool conf f = do withConnectionPool conf f = do
(database,host) <- liftIO $ loadMongoConnParams (appEnv conf) dbConf <- liftIO $ loadMongo (appEnv conf)
withMongoDBPool (u database) host (connectionPoolSize conf) f withMongoDBPool (u $ mgDatabase dbConf) (mgHost dbConf) (mgPoolSize dbConf) f

View File

@ -1,10 +1,10 @@
runConnectionPool :: MonadControlIO m => SqlPersist m a -> ConnectionPool -> m a runConnectionPool :: MonadControlIO m => SqlPersist m a -> ConnectionPool -> m a
runConnectionPool = runSqlPool runConnectionPool = runSqlPool
withConnectionPool :: MonadControlIO m => AppConfig -> (ConnectionPool -> m a) -> m a withConnectionPool :: MonadControlIO m => AppConfig DefaultEnv -> (ConnectionPool -> m a) -> m a
withConnectionPool conf f = do withConnectionPool conf f = do
cs <- liftIO $ load~upper~ConnStr (appEnv conf) dbConf <- liftIO $ load~upper~ (appEnv conf)
with~upper~Pool cs (connectionPoolSize conf) f with~upper~Pool (pgConnStr dbConf) (pgPoolSize dbConf) f
-- Example of making a dynamic configuration static -- Example of making a dynamic configuration static
-- use /return $(mkConnStr Production)/ instead of loadConnStr -- use /return $(mkConnStr Production)/ instead of loadConnStr

View File

@ -58,6 +58,7 @@ executable ~project~
, yesod-core , yesod-core
, yesod-auth , yesod-auth
, yesod-static , yesod-static
, yesod-default
, blaze-html , blaze-html
, yesod-form , yesod-form
, mime-mail , mime-mail

View File

@ -1,10 +1,10 @@
runConnectionPool :: MonadControlIO m => SqlPersist m a -> ConnectionPool -> m a runConnectionPool :: MonadControlIO m => SqlPersist m a -> ConnectionPool -> m a
runConnectionPool = runSqlPool runConnectionPool = runSqlPool
withConnectionPool :: MonadControlIO m => AppConfig -> (ConnectionPool -> m a) -> m a withConnectionPool :: MonadControlIO m => AppConfig DefaultEnv -> (ConnectionPool -> m a) -> m a
withConnectionPool conf f = do withConnectionPool conf f = do
cs <- liftIO $ load~upper~ConnStr (appEnv conf) dbConf <- liftIO $ load~upper~ (appEnv conf)
with~upper~Pool cs (connectionPoolSize conf) f with~upper~Pool (sqlDatabase dbConf) (sqlPoolSize dbConf) f
-- Example of making a dynamic configuration static -- Example of making a dynamic configuration static
-- use /return $(mkConnStr Production)/ instead of loadConnStr -- use /return $(mkConnStr Production)/ instead of loadConnStr

View File

@ -11,8 +11,8 @@ module Application
import Foundation import Foundation
import Settings import Settings
import Yesod.Static import Yesod.Static
import Yesod.Settings import Yesod.Default.Config
import Yesod.Main (defaultDevelApp) import Yesod.Default.Main (defaultDevelApp)
import Yesod.Logger (Logger) import Yesod.Logger (Logger)
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import Network.Wai (Application) import Network.Wai (Application)
@ -38,7 +38,7 @@ getRobotsR = return $ RepPlain $ toContent ("User-agent: *" :: ByteString)
-- performs initialization and creates a WAI application. This is also the -- performs initialization and creates a WAI application. This is also the
-- place to put your migrate statements to have automatic database -- place to put your migrate statements to have automatic database
-- migrations handled by Yesod. -- migrations handled by Yesod.
with~sitearg~ :: AppConfig -> Logger -> (Application -> IO a) -> IO a with~sitearg~ :: AppConfig DefaultEnv -> Logger -> (Application -> IO a) -> IO a
with~sitearg~ conf logger f = do with~sitearg~ conf logger f = do
#ifdef PRODUCTION #ifdef PRODUCTION
s <- static Settings.staticDir s <- static Settings.staticDir

View File

@ -14,7 +14,7 @@ module Foundation
) where ) where
import Yesod.Core import Yesod.Core
import Yesod.Settings (AppConfig(..)) import Yesod.Default.Config
import Yesod.Static (Static, base64md5, StaticRoute(..)) import Yesod.Static (Static, base64md5, StaticRoute(..))
import Settings.StaticFiles import Settings.StaticFiles
import Yesod.Logger (Logger, logLazyText) import Yesod.Logger (Logger, logLazyText)
@ -33,7 +33,7 @@ import Web.ClientSession (getKey)
-- starts running, such as database connections. Every handler will have -- starts running, such as database connections. Every handler will have
-- access to the data present here. -- access to the data present here.
data ~sitearg~ = ~sitearg~ data ~sitearg~ = ~sitearg~
{ settings :: AppConfig { settings :: AppConfig DefaultEnv
, getLogger :: Logger , getLogger :: Logger
, getStatic :: Static -- ^ Settings for static file serving. , getStatic :: Static -- ^ Settings for static file serving.
} }

View File

@ -24,7 +24,7 @@ import qualified Text.Shakespeare.Text as S
import Text.Shakespeare.Text (st) import Text.Shakespeare.Text (st)
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
import Yesod.Widget (addWidget, addCassius, addJulius, addLucius, whamletFile) import Yesod.Widget (addWidget, addCassius, addJulius, addLucius, whamletFile)
import Yesod.Settings import Yesod.Default.Config
import Data.Monoid (mempty) import Data.Monoid (mempty)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import Data.Text (Text) import Data.Text (Text)
@ -47,7 +47,7 @@ staticDir = "static"
-- have to make a corresponding change here. -- have to make a corresponding change here.
-- --
-- To see how this value is used, see urlRenderOverride in ~project~.hs -- To see how this value is used, see urlRenderOverride in ~project~.hs
staticRoot :: AppConfig -> Text staticRoot :: AppConfig DefaultEnv -> Text
staticRoot conf = [st|#{appRoot conf}/static|] staticRoot conf = [st|#{appRoot conf}/static|]
-- The rest of this file contains settings which rarely need changing by a -- The rest of this file contains settings which rarely need changing by a

View File

@ -46,9 +46,9 @@ executable ~project~
hs-source-dirs: . hs-source-dirs: .
build-depends: base >= 4 && < 5 build-depends: base >= 4 && < 5
, yesod >= 0.9 && < 0.10
, yesod-core >= 0.9 && < 0.10 , yesod-core >= 0.9 && < 0.10
, yesod-static , yesod-static
, yesod-default
, clientsession , clientsession
, wai-extra , wai-extra
, directory , directory