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.StaticFiles (static)
import Yesod.Auth
import Yesod.Default.Config
import Yesod.Default.Main
import Yesod.Logger (Logger)
import Database.Persist.~importGenericDB~
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
-- place to put your migrate statements to have automatic database
-- 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
s <- static Settings.staticDir
Settings.withConnectionPool conf $ \p -> do~runMigration~

View File

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

View File

@ -29,7 +29,7 @@ import Text.Shakespeare.Text (st)
import Language.Haskell.TH.Syntax
import Database.Persist.~importPersist~
import Yesod (liftIO, MonadControlIO, addWidget, addCassius, addJulius, addLucius, whamletFile)
import Yesod.Settings
import Yesod.Default.Config
import Data.Monoid (mempty)
import System.Directory (doesFileExist)
import Data.Text (Text)
@ -55,7 +55,7 @@ staticDir = "static"
-- have to make a corresponding change here.
--
-- 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|]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
runConnectionPool :: MonadControlIO m => Action m a -> ConnectionPool -> m a
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
(database,host) <- liftIO $ loadMongoConnParams (appEnv conf)
withMongoDBPool (u database) host (connectionPoolSize conf) f
dbConf <- liftIO $ loadMongo (appEnv conf)
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 = runSqlPool
withConnectionPool :: MonadControlIO m => AppConfig -> (ConnectionPool -> m a) -> m a
withConnectionPool :: MonadControlIO m => AppConfig DefaultEnv -> (ConnectionPool -> m a) -> m a
withConnectionPool conf f = do
cs <- liftIO $ load~upper~ConnStr (appEnv conf)
with~upper~Pool cs (connectionPoolSize conf) f
dbConf <- liftIO $ load~upper~ (appEnv conf)
with~upper~Pool (pgConnStr dbConf) (pgPoolSize dbConf) f
-- Example of making a dynamic configuration static
-- use /return $(mkConnStr Production)/ instead of loadConnStr

View File

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

View File

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

View File

@ -11,8 +11,8 @@ module Application
import Foundation
import Settings
import Yesod.Static
import Yesod.Settings
import Yesod.Main (defaultDevelApp)
import Yesod.Default.Config
import Yesod.Default.Main (defaultDevelApp)
import Yesod.Logger (Logger)
import Data.ByteString (ByteString)
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
-- place to put your migrate statements to have automatic database
-- 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
#ifdef PRODUCTION
s <- static Settings.staticDir

View File

@ -14,7 +14,7 @@ module Foundation
) where
import Yesod.Core
import Yesod.Settings (AppConfig(..))
import Yesod.Default.Config
import Yesod.Static (Static, base64md5, StaticRoute(..))
import Settings.StaticFiles
import Yesod.Logger (Logger, logLazyText)
@ -33,7 +33,7 @@ import Web.ClientSession (getKey)
-- starts running, such as database connections. Every handler will have
-- access to the data present here.
data ~sitearg~ = ~sitearg~
{ settings :: AppConfig
{ settings :: AppConfig DefaultEnv
, getLogger :: Logger
, 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 Language.Haskell.TH.Syntax
import Yesod.Widget (addWidget, addCassius, addJulius, addLucius, whamletFile)
import Yesod.Settings
import Yesod.Default.Config
import Data.Monoid (mempty)
import System.Directory (doesFileExist)
import Data.Text (Text)
@ -47,7 +47,7 @@ staticDir = "static"
-- have to make a corresponding change here.
--
-- 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|]
-- The rest of this file contains settings which rarely need changing by a

View File

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