data-object-yaml to yaml 0.5
This commit is contained in:
parent
50ce1da37e
commit
c90cf34ef5
@ -73,8 +73,6 @@ library
|
|||||||
, case-insensitive >= 0.2
|
, case-insensitive >= 0.2
|
||||||
, parsec >= 2 && < 3.2
|
, parsec >= 2 && < 3.2
|
||||||
, directory >= 1 && < 1.2
|
, directory >= 1 && < 1.2
|
||||||
, data-object >= 0.3 && < 0.4
|
|
||||||
, data-object-yaml >= 0.3 && < 0.4
|
|
||||||
, vector >= 0.9 && < 0.10
|
, vector >= 0.9 && < 0.10
|
||||||
, aeson >= 0.5
|
, aeson >= 0.5
|
||||||
, fast-logger >= 0.0.1
|
, fast-logger >= 0.0.1
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
{-# LANGUAGE DeriveDataTypeable #-}
|
{-# LANGUAGE DeriveDataTypeable #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE PatternGuards #-}
|
||||||
module Yesod.Default.Config
|
module Yesod.Default.Config
|
||||||
( DefaultEnv (..)
|
( DefaultEnv (..)
|
||||||
, fromArgs
|
, fromArgs
|
||||||
@ -18,10 +19,9 @@ import Data.Char (toUpper, toLower)
|
|||||||
import System.Console.CmdArgs hiding (args)
|
import System.Console.CmdArgs hiding (args)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Control.Monad (join)
|
import Data.Yaml
|
||||||
import Data.Object
|
|
||||||
import Data.Object.Yaml
|
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
import qualified Data.HashMap.Strict as M
|
||||||
|
|
||||||
-- | A yesod-provided @'AppEnv'@, allows for Development, Testing, and
|
-- | A yesod-provided @'AppEnv'@, allows for Development, Testing, and
|
||||||
-- Production environments
|
-- Production environments
|
||||||
@ -55,13 +55,13 @@ fromArgs = fromArgsExtra (const $ const $ return ())
|
|||||||
|
|
||||||
-- | Same as 'fromArgs', but allows you to specify how to parse the 'appExtra'
|
-- | Same as 'fromArgs', but allows you to specify how to parse the 'appExtra'
|
||||||
-- record.
|
-- record.
|
||||||
fromArgsExtra :: (DefaultEnv -> TextObject -> IO extra)
|
fromArgsExtra :: (DefaultEnv -> Value -> IO extra)
|
||||||
-> IO (AppConfig DefaultEnv extra)
|
-> IO (AppConfig DefaultEnv extra)
|
||||||
fromArgsExtra = fromArgsWith defaultArgConfig
|
fromArgsExtra = fromArgsWith defaultArgConfig
|
||||||
|
|
||||||
fromArgsWith :: (Read env, Show env)
|
fromArgsWith :: (Read env, Show env)
|
||||||
=> ArgConfig
|
=> ArgConfig
|
||||||
-> (env -> TextObject -> IO extra)
|
-> (env -> Value -> IO extra)
|
||||||
-> IO (AppConfig env extra)
|
-> IO (AppConfig env extra)
|
||||||
fromArgsWith argConfig getExtra = do
|
fromArgsWith argConfig getExtra = do
|
||||||
args <- cmdArgs argConfig
|
args <- cmdArgs argConfig
|
||||||
@ -103,12 +103,12 @@ data ConfigSettings environment extra = ConfigSettings
|
|||||||
-- environment. Usually, you will use 'DefaultEnv' for this type.
|
-- environment. Usually, you will use 'DefaultEnv' for this type.
|
||||||
csEnv :: environment
|
csEnv :: environment
|
||||||
-- | Load any extra data, to be used by the application.
|
-- | Load any extra data, to be used by the application.
|
||||||
, csLoadExtra :: environment -> TextObject -> IO extra
|
, csLoadExtra :: environment -> Value -> IO extra
|
||||||
-- | Return the path to the YAML config file.
|
-- | Return the path to the YAML config file.
|
||||||
, csFile :: environment -> IO FilePath
|
, csFile :: environment -> IO FilePath
|
||||||
-- | Get the sub-object (if relevant) from the given YAML source which
|
-- | Get the sub-object (if relevant) from the given YAML source which
|
||||||
-- contains the specific settings for the current environment.
|
-- contains the specific settings for the current environment.
|
||||||
, csGetObject :: environment -> TextObject -> IO TextObject
|
, csGetObject :: environment -> Value -> IO Value
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Default config settings.
|
-- | Default config settings.
|
||||||
@ -117,14 +117,17 @@ configSettings env0 = ConfigSettings
|
|||||||
{ csEnv = env0
|
{ csEnv = env0
|
||||||
, csLoadExtra = \_ _ -> return ()
|
, csLoadExtra = \_ _ -> return ()
|
||||||
, csFile = \_ -> return "config/settings.yml"
|
, csFile = \_ -> return "config/settings.yml"
|
||||||
, csGetObject = \env obj -> do
|
, csGetObject = \env v -> do
|
||||||
envs <- fromMapping obj
|
envs <-
|
||||||
|
case v of
|
||||||
|
Object obj -> return obj
|
||||||
|
_ -> fail "Expected Object"
|
||||||
let senv = show env
|
let senv = show env
|
||||||
tenv = T.pack senv
|
tenv = T.pack senv
|
||||||
maybe
|
maybe
|
||||||
(error $ "Could not find environment: " ++ senv)
|
(error $ "Could not find environment: " ++ senv)
|
||||||
return
|
return
|
||||||
(lookup tenv envs)
|
(M.lookup tenv envs)
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Load an @'AppConfig'@.
|
-- | Load an @'AppConfig'@.
|
||||||
@ -160,10 +163,14 @@ loadConfig :: ConfigSettings environment extra
|
|||||||
-> IO (AppConfig environment extra)
|
-> IO (AppConfig environment extra)
|
||||||
loadConfig (ConfigSettings env loadExtra getFile getObject) = do
|
loadConfig (ConfigSettings env loadExtra getFile getObject) = do
|
||||||
fp <- getFile env
|
fp <- getFile env
|
||||||
topObj <- join $ decodeFile fp
|
mtopObj <- decodeFile fp
|
||||||
|
topObj <- maybe (fail "Invalid YAML file") return mtopObj
|
||||||
obj <- getObject env topObj
|
obj <- getObject env topObj
|
||||||
|
m <-
|
||||||
|
case obj of
|
||||||
|
Object m -> return m
|
||||||
|
_ -> fail "Expected map"
|
||||||
|
|
||||||
m <- maybe (fail "Expected map") return $ fromMapping obj
|
|
||||||
let mssl = lookupScalar "ssl" m
|
let mssl = lookupScalar "ssl" m
|
||||||
let mhost = lookupScalar "host" m
|
let mhost = lookupScalar "host" m
|
||||||
let mport = lookupScalar "port" m
|
let mport = lookupScalar "port" m
|
||||||
@ -192,6 +199,11 @@ loadConfig (ConfigSettings env loadExtra getFile getObject) = do
|
|||||||
}
|
}
|
||||||
|
|
||||||
where
|
where
|
||||||
|
lookupScalar k m =
|
||||||
|
case M.lookup k m of
|
||||||
|
Just (String t) -> return t
|
||||||
|
Just _ -> fail $ "Invalid value for: " ++ show k
|
||||||
|
Nothing -> fail $ "Not found: " ++ show k
|
||||||
toBool :: Text -> Bool
|
toBool :: Text -> Bool
|
||||||
toBool = (`elem` ["true", "TRUE", "yes", "YES", "Y", "1"])
|
toBool = (`elem` ["true", "TRUE", "yes", "YES", "Y", "1"])
|
||||||
|
|
||||||
@ -216,11 +228,12 @@ safeRead name' t = case reads s of
|
|||||||
withYamlEnvironment :: Show e
|
withYamlEnvironment :: Show e
|
||||||
=> FilePath -- ^ the yaml file
|
=> FilePath -- ^ the yaml file
|
||||||
-> e -- ^ the environment you want to load
|
-> e -- ^ the environment you want to load
|
||||||
-> (TextObject -> IO a) -- ^ what to do with the mapping
|
-> (Value -> IO a) -- ^ what to do with the mapping
|
||||||
-> IO a
|
-> IO a
|
||||||
withYamlEnvironment fp env f = do
|
withYamlEnvironment fp env f = do
|
||||||
obj <- join $ decodeFile fp
|
mval <- decodeFile fp
|
||||||
envs <- fromMapping obj
|
case mval of
|
||||||
conf <- maybe (fail $ "Could not find environment: " ++ show env) return
|
Nothing -> fail $ "Invalid YAML file: " ++ show fp
|
||||||
$ lookup (T.pack $ show env) envs
|
Just (Object obj)
|
||||||
f conf
|
| Just v <- M.lookup (T.pack $ show env) obj -> f v
|
||||||
|
_ -> fail $ "Could not find environment: " ++ show env
|
||||||
|
|||||||
@ -30,8 +30,8 @@ library
|
|||||||
, shakespeare-css >= 0.10.5 && < 0.11
|
, shakespeare-css >= 0.10.5 && < 0.11
|
||||||
, shakespeare-js >= 0.10.4 && < 0.11
|
, shakespeare-js >= 0.10.4 && < 0.11
|
||||||
, template-haskell
|
, template-haskell
|
||||||
, data-object >= 0.3 && < 0.4
|
, yaml >= 0.5 && < 0.6
|
||||||
, data-object-yaml >= 0.3 && < 0.4
|
, unordered-containers
|
||||||
|
|
||||||
if !os(windows)
|
if !os(windows)
|
||||||
build-depends: unix
|
build-depends: unix
|
||||||
|
|||||||
@ -10,7 +10,6 @@ module Yesod.Form.Types
|
|||||||
, FileEnv
|
, FileEnv
|
||||||
, Ints (..)
|
, Ints (..)
|
||||||
-- * Form
|
-- * Form
|
||||||
, Form
|
|
||||||
, MForm
|
, MForm
|
||||||
, AForm (..)
|
, AForm (..)
|
||||||
-- * Build forms
|
-- * Build forms
|
||||||
@ -75,8 +74,6 @@ type Env = Map.Map Text [Text]
|
|||||||
type FileEnv = Map.Map Text FileInfo
|
type FileEnv = Map.Map Text FileInfo
|
||||||
|
|
||||||
type Lang = Text
|
type Lang = Text
|
||||||
type Form sub master a = RWST (Maybe (Env, FileEnv), master, [Lang]) Enctype Ints (GHandlerT sub master IO) a
|
|
||||||
{-# DEPRECATED Form "Use MForm instead" #-}
|
|
||||||
type MForm sub master a = RWST (Maybe (Env, FileEnv), master, [Lang]) Enctype Ints (GHandlerT sub master IO) a
|
type MForm sub master a = RWST (Maybe (Env, FileEnv), master, [Lang]) Enctype Ints (GHandlerT sub master IO) a
|
||||||
|
|
||||||
newtype AForm sub master a = AForm
|
newtype AForm sub master a = AForm
|
||||||
|
|||||||
@ -9,8 +9,8 @@ module Yesod.Json
|
|||||||
, parseJsonBody
|
, parseJsonBody
|
||||||
-- * Produce JSON values
|
-- * Produce JSON values
|
||||||
, J.Value (..)
|
, J.Value (..)
|
||||||
, toObject
|
, object
|
||||||
, toArray
|
, array
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Handler (GHandler, waiRequest)
|
import Yesod.Handler (GHandler, waiRequest)
|
||||||
@ -26,7 +26,6 @@ import Data.Aeson.Encode (fromValue)
|
|||||||
import Data.Conduit.Attoparsec (sinkParser)
|
import Data.Conduit.Attoparsec (sinkParser)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
import Data.HashMap.Strict (fromList)
|
|
||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
import Text.Julius (ToJavascript (..))
|
import Text.Julius (ToJavascript (..))
|
||||||
import Data.Text.Lazy.Builder (fromLazyText)
|
import Data.Text.Lazy.Builder (fromLazyText)
|
||||||
@ -68,9 +67,9 @@ instance ToJavascript J.Value where
|
|||||||
toJavascript = fromLazyText . decodeUtf8 . JE.encode
|
toJavascript = fromLazyText . decodeUtf8 . JE.encode
|
||||||
|
|
||||||
-- | Convert a list of pairs to an 'J.Object'.
|
-- | Convert a list of pairs to an 'J.Object'.
|
||||||
toObject :: [(Text, J.Value)] -> J.Value
|
object :: [(Text, J.Value)] -> J.Value
|
||||||
toObject = J.Object . fromList
|
object = J.object
|
||||||
|
|
||||||
-- | Convert a list of values to an 'J.Array'.
|
-- | Convert a list of values to an 'J.Array'.
|
||||||
toArray :: [J.Value] -> J.Value
|
array :: [J.Value] -> J.Value
|
||||||
toArray = J.Array . V.fromList
|
array = J.Array . V.fromList
|
||||||
|
|||||||
@ -20,7 +20,6 @@ library
|
|||||||
, shakespeare-js >= 0.10 && < 0.11
|
, shakespeare-js >= 0.10 && < 0.11
|
||||||
, vector >= 0.9
|
, vector >= 0.9
|
||||||
, containers >= 0.2
|
, containers >= 0.2
|
||||||
, unordered-containers
|
|
||||||
, blaze-builder
|
, blaze-builder
|
||||||
, attoparsec-conduit >= 0.0 && < 0.1
|
, attoparsec-conduit >= 0.0 && < 0.1
|
||||||
, conduit >= 0.0 && < 0.1
|
, conduit >= 0.0 && < 0.1
|
||||||
|
|||||||
@ -66,8 +66,8 @@ scaffold = do
|
|||||||
backendC <- prompt $ flip elem $ map (return . toLower . head . show) backends
|
backendC <- prompt $ flip elem $ map (return . toLower . head . show) backends
|
||||||
let (backend, importGenericDB, dbMonad, importPersist, mkPersistSettings) =
|
let (backend, importGenericDB, dbMonad, importPersist, mkPersistSettings) =
|
||||||
case backendC of
|
case backendC of
|
||||||
"s" -> (Sqlite, "GenericSql", "SqlPersist", "Sqlite", "sqlSettings")
|
"s" -> (Sqlite, "GenericSql", "SqlPersist", "Sqlite", "sqlMkSettings")
|
||||||
"p" -> (Postgresql, "GenericSql", "SqlPersist", "Postgresql", "sqlSettings")
|
"p" -> (Postgresql, "GenericSql", "SqlPersist", "Postgresql", "sqlMkSettings")
|
||||||
"m" -> (MongoDB, "MongoDB", "Action", "MongoDB", "MkPersistSettings { mpsBackend = ConT ''Action }")
|
"m" -> (MongoDB, "MongoDB", "Action", "MongoDB", "MkPersistSettings { mpsBackend = ConT ''Action }")
|
||||||
"t" -> (Tiny, "","","",undefined)
|
"t" -> (Tiny, "","","",undefined)
|
||||||
_ -> error $ "Invalid backend: " ++ backendC
|
_ -> error $ "Invalid backend: " ++ backendC
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import Network.Wai.Middleware.RequestLogger (logHandleDev)
|
|||||||
import Yesod.Logger (Logger)
|
import Yesod.Logger (Logger)
|
||||||
import Network.Wai.Middleware.RequestLogger (logStdout)
|
import Network.Wai.Middleware.RequestLogger (logStdout)
|
||||||
#endif
|
#endif
|
||||||
import qualified Database.Persist.Base~importMigration~
|
import qualified Database.Persist.Store~importMigration~
|
||||||
|
|
||||||
-- Import all relevant handler modules here.
|
-- Import all relevant handler modules here.
|
||||||
import Handler.Root
|
import Handler.Root
|
||||||
@ -33,12 +33,12 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
|
|||||||
-- 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 DefaultEnv () -> Logger -> (Application -> IO ()) -> IO ()
|
with~sitearg~ :: AppConfig DefaultEnv Extra -> Logger -> (Application -> IO ()) -> IO ()
|
||||||
with~sitearg~ conf logger f = do
|
with~sitearg~ conf logger f = do
|
||||||
s <- staticSite
|
s <- staticSite
|
||||||
dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf)
|
dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf)
|
||||||
$ either error return . Database.Persist.Base.loadConfig
|
$ either error return . Database.Persist.Store.loadConfig
|
||||||
Database.Persist.Base.withPool (dbconf :: Settings.PersistConfig) $ \p -> do~runMigration~
|
Database.Persist.Store.withPool (dbconf :: Settings.PersistConfig) $ \p -> do~runMigration~
|
||||||
let h = ~sitearg~ conf logger s p
|
let h = ~sitearg~ conf logger s p
|
||||||
defaultRunner (f . logWare) h
|
defaultRunner (f . logWare) h
|
||||||
where
|
where
|
||||||
@ -50,4 +50,10 @@ with~sitearg~ conf logger f = do
|
|||||||
|
|
||||||
-- for yesod devel
|
-- for yesod devel
|
||||||
withDevelAppPort :: Dynamic
|
withDevelAppPort :: Dynamic
|
||||||
withDevelAppPort = toDyn $ defaultDevelApp with~sitearg~
|
withDevelAppPort =
|
||||||
|
toDyn $ defaultDevelAppWith loader with~sitearg~
|
||||||
|
where
|
||||||
|
loader = loadConfig (configSettings Development)
|
||||||
|
{ csLoadExtra = loadExtra
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ module Foundation
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
import Yesod hiding (Form, AppConfig (..), withYamlEnvironment)
|
import Yesod
|
||||||
import Yesod.Static (Static, base64md5, StaticRoute(..))
|
import Yesod.Static (Static, base64md5, StaticRoute(..))
|
||||||
import Settings.StaticFiles
|
import Settings.StaticFiles
|
||||||
import Yesod.Auth
|
import Yesod.Auth
|
||||||
@ -29,9 +29,9 @@ import Yesod.Logger (logLazyText)
|
|||||||
#endif
|
#endif
|
||||||
import qualified Settings
|
import qualified Settings
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import qualified Database.Persist.Base
|
import qualified Database.Persist.Store
|
||||||
import Database.Persist.~importGenericDB~
|
import Database.Persist.~importGenericDB~
|
||||||
import Settings (widgetFile)
|
import Settings (widgetFile, Extra)
|
||||||
import Model
|
import Model
|
||||||
import Text.Jasmine (minifym)
|
import Text.Jasmine (minifym)
|
||||||
import Web.ClientSession (getKey)
|
import Web.ClientSession (getKey)
|
||||||
@ -47,10 +47,10 @@ import Network.Mail.Mime (sendmail)
|
|||||||
-- 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 DefaultEnv ()
|
{ settings :: AppConfig DefaultEnv Extra
|
||||||
, getLogger :: Logger
|
, getLogger :: Logger
|
||||||
, getStatic :: Static -- ^ Settings for static file serving.
|
, getStatic :: Static -- ^ Settings for static file serving.
|
||||||
, connPool :: Database.Persist.Base.PersistConfigPool Settings.PersistConfig -- ^ Database connection pool.
|
, connPool :: Database.Persist.Store.PersistConfigPool Settings.PersistConfig -- ^ Database connection pool.
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Set up i18n messages. See the message folder.
|
-- Set up i18n messages. See the message folder.
|
||||||
@ -125,8 +125,7 @@ instance Yesod ~sitearg~ where
|
|||||||
-- How to run database actions.
|
-- How to run database actions.
|
||||||
instance YesodPersist ~sitearg~ where
|
instance YesodPersist ~sitearg~ where
|
||||||
type YesodPersistBackend ~sitearg~ = ~dbMonad~
|
type YesodPersistBackend ~sitearg~ = ~dbMonad~
|
||||||
runDB f = liftIOHandler
|
runDB f = fmap connPool getYesod >>= Database.Persist.Store.runPool (undefined :: Settings.PersistConfig) f
|
||||||
$ fmap connPool getYesod >>= Database.Persist.Base.runPool (undefined :: Settings.PersistConfig) f
|
|
||||||
|
|
||||||
instance YesodAuth ~sitearg~ where
|
instance YesodAuth ~sitearg~ where
|
||||||
type AuthId ~sitearg~ = UserId
|
type AuthId ~sitearg~ = UserId
|
||||||
|
|||||||
@ -3,11 +3,13 @@ module Model where
|
|||||||
import Prelude
|
import Prelude
|
||||||
import Yesod
|
import Yesod
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
import Database.Persist.Quasi
|
||||||
~modelImports~
|
~modelImports~
|
||||||
|
|
||||||
-- You can define all of your database entities in the entities file.
|
-- You can define all of your database entities in the entities file.
|
||||||
-- You can find more information on persistent and how to declare entities
|
-- You can find more information on persistent and how to declare entities
|
||||||
-- at:
|
-- at:
|
||||||
-- http://www.yesodweb.com/book/persistent/
|
-- http://www.yesodweb.com/book/persistent/
|
||||||
share [mkPersist ~mkPersistSettings~, mkMigrate "migrateAll"] $(persistFile "config/models")
|
share [mkPersist ~mkPersistSettings~, mkMigrate "migrateAll"]
|
||||||
|
$(persistFile upperCaseSettings "config/models")
|
||||||
|
|
||||||
|
|||||||
@ -8,15 +8,18 @@ module Settings
|
|||||||
, PersistConfig
|
, PersistConfig
|
||||||
, staticRoot
|
, staticRoot
|
||||||
, staticDir
|
, staticDir
|
||||||
|
, Extra (..)
|
||||||
|
, loadExtra
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude (FilePath, String)
|
import Prelude
|
||||||
import Text.Shakespeare.Text (st)
|
import Text.Shakespeare.Text (st)
|
||||||
import Language.Haskell.TH.Syntax
|
import Language.Haskell.TH.Syntax
|
||||||
import Database.Persist.~importPersist~ (~configPersist~)
|
import Database.Persist.~importPersist~ (~configPersist~)
|
||||||
import Yesod.Default.Config
|
import Yesod.Default.Config
|
||||||
import qualified Yesod.Default.Util
|
import qualified Yesod.Default.Util
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
import Data.Yaml
|
||||||
|
|
||||||
-- | Which Persistent backend this site is using.
|
-- | Which Persistent backend this site is using.
|
||||||
type PersistConfig = ~configPersist~
|
type PersistConfig = ~configPersist~
|
||||||
@ -54,3 +57,9 @@ widgetFile = Yesod.Default.Util.widgetFileReload
|
|||||||
#else
|
#else
|
||||||
widgetFile = Yesod.Default.Util.widgetFileNoReload
|
widgetFile = Yesod.Default.Util.widgetFileNoReload
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
data Extra = Extra
|
||||||
|
|
||||||
|
loadExtra :: DefaultEnv -> Value -> IO Extra
|
||||||
|
loadExtra _ _ = return Extra
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import Yesod.Default.Config (fromArgs)
|
|
||||||
import Yesod.Default.Main (defaultMain)
|
|
||||||
import Application (with~sitearg~)
|
|
||||||
import Prelude (IO)
|
import Prelude (IO)
|
||||||
|
import Yesod.Default.Config (fromArgsExtra)
|
||||||
|
import Yesod.Default.Main (defaultMain)
|
||||||
|
import Settings (loadExtra)
|
||||||
|
import Application (with~sitearg~)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = defaultMain fromArgs with~sitearg~
|
main = defaultMain (fromArgsExtra loadExtra) with~sitearg~
|
||||||
|
|||||||
@ -74,24 +74,25 @@ executable ~project~
|
|||||||
FlexibleContexts
|
FlexibleContexts
|
||||||
|
|
||||||
build-depends: base >= 4 && < 5
|
build-depends: base >= 4 && < 5
|
||||||
, yesod >= 0.9.3.4 && < 0.10
|
, yesod >= 0.10 && < 0.11
|
||||||
, yesod-core >= 0.9.3 && < 0.10
|
, yesod-core >= 0.10 && < 0.11
|
||||||
, yesod-auth >= 0.7.3 && < 0.8
|
, yesod-auth >= 0.8 && < 0.9
|
||||||
, yesod-static >= 0.3.1 && < 0.4
|
, yesod-static >= 0.10 && < 0.11
|
||||||
, yesod-default >= 0.5 && < 0.6
|
, yesod-default >= 0.6 && < 0.7
|
||||||
, yesod-form >= 0.3.4 && < 0.4
|
, yesod-form >= 0.4 && < 0.5
|
||||||
, mime-mail >= 0.3.0.3 && < 0.5
|
, mime-mail >= 0.3.0.3 && < 0.5
|
||||||
, clientsession >= 0.7.3 && < 0.8
|
, clientsession >= 0.7.3 && < 0.8
|
||||||
, bytestring >= 0.9 && < 0.10
|
, bytestring >= 0.9 && < 0.10
|
||||||
, text >= 0.11 && < 0.12
|
, text >= 0.11 && < 0.12
|
||||||
, persistent >= 0.6.2 && < 0.7
|
, persistent >= 0.7 && < 0.8
|
||||||
, persistent-~backendLower~ >= 0.6 && < 0.7
|
, persistent-~backendLower~ >= 0.7 && < 0.8
|
||||||
, template-haskell
|
, template-haskell
|
||||||
, hamlet >= 0.10 && < 0.11
|
, hamlet >= 0.10 && < 0.11
|
||||||
, shakespeare-css >= 0.10 && < 0.11
|
, shakespeare-css >= 0.10 && < 0.11
|
||||||
, shakespeare-js >= 0.10 && < 0.11
|
, shakespeare-js >= 0.10 && < 0.11
|
||||||
, shakespeare-text >= 0.10 && < 0.11
|
, shakespeare-text >= 0.10 && < 0.11
|
||||||
, hjsmin >= 0.0.14 && < 0.1
|
, hjsmin >= 0.0.14 && < 0.1
|
||||||
, monad-control ~monadControlVersion~
|
, monad-control >= 0.3 && < 0.4
|
||||||
, wai-extra >= 0.4.6 && < 0.5
|
, wai-extra >= 1.0 && < 1.1
|
||||||
|
, yaml >= 0.5 && < 0.6
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,10 @@ module Application
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import
|
||||||
|
import Settings (loadExtra)
|
||||||
import Settings.StaticFiles (staticSite)
|
import Settings.StaticFiles (staticSite)
|
||||||
import Yesod.Default.Config
|
import Yesod.Default.Config
|
||||||
import Yesod.Default.Main (defaultDevelApp, defaultRunner)
|
import Yesod.Default.Main (defaultDevelAppWith, defaultRunner)
|
||||||
import Yesod.Default.Handlers (getFaviconR, getRobotsR)
|
import Yesod.Default.Handlers (getFaviconR, getRobotsR)
|
||||||
import Yesod.Logger (Logger)
|
import Yesod.Logger (Logger)
|
||||||
import Network.Wai (Application)
|
import Network.Wai (Application)
|
||||||
@ -25,7 +26,7 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
|
|||||||
-- 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 DefaultEnv () -> Logger -> (Application -> IO ()) -> IO ()
|
with~sitearg~ :: AppConfig DefaultEnv Extra -> Logger -> (Application -> IO ()) -> IO ()
|
||||||
with~sitearg~ conf logger f = do
|
with~sitearg~ conf logger f = do
|
||||||
s <- staticSite
|
s <- staticSite
|
||||||
let h = ~sitearg~ conf logger s
|
let h = ~sitearg~ conf logger s
|
||||||
@ -33,4 +34,10 @@ with~sitearg~ conf logger f = do
|
|||||||
|
|
||||||
-- for yesod devel
|
-- for yesod devel
|
||||||
withDevelAppPort :: Dynamic
|
withDevelAppPort :: Dynamic
|
||||||
withDevelAppPort = toDyn $ defaultDevelApp with~sitearg~
|
withDevelAppPort =
|
||||||
|
toDyn $ defaultDevelAppWith loader withFoobar
|
||||||
|
where
|
||||||
|
loader = loadConfig (configSettings Development)
|
||||||
|
{ csLoadExtra = loadExtra
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,14 +13,14 @@ module Foundation
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
import Yesod.Core hiding (AppConfig (..))
|
import Yesod.Core
|
||||||
import Yesod.Default.Config
|
import Yesod.Default.Config
|
||||||
import Yesod.Default.Util (addStaticContentExternal)
|
import Yesod.Default.Util (addStaticContentExternal)
|
||||||
import Yesod.Static (Static, base64md5, StaticRoute(..))
|
import Yesod.Static (Static, base64md5, StaticRoute(..))
|
||||||
import Settings.StaticFiles
|
import Settings.StaticFiles
|
||||||
import Yesod.Logger (Logger, logMsg, formatLogText)
|
import Yesod.Logger (Logger, logMsg, formatLogText)
|
||||||
import qualified Settings
|
import qualified Settings
|
||||||
import Settings (widgetFile)
|
import Settings (Extra, widgetFile)
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
import Control.Monad.IO.Class (liftIO)
|
import Control.Monad.IO.Class (liftIO)
|
||||||
import Web.ClientSession (getKey)
|
import Web.ClientSession (getKey)
|
||||||
@ -31,7 +31,7 @@ import Text.Hamlet (hamletFile)
|
|||||||
-- 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 DefaultEnv ()
|
{ settings :: AppConfig DefaultEnv Extra
|
||||||
, getLogger :: Logger
|
, getLogger :: Logger
|
||||||
, getStatic :: Static -- ^ Settings for static file serving.
|
, getStatic :: Static -- ^ Settings for static file serving.
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,14 +7,17 @@ module Settings
|
|||||||
( widgetFile
|
( widgetFile
|
||||||
, staticRoot
|
, staticRoot
|
||||||
, staticDir
|
, staticDir
|
||||||
|
, Extra (..)
|
||||||
|
, loadExtra
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude (FilePath, String)
|
import Prelude
|
||||||
import Text.Shakespeare.Text (st)
|
import Text.Shakespeare.Text (st)
|
||||||
import Language.Haskell.TH.Syntax
|
import Language.Haskell.TH.Syntax
|
||||||
import Yesod.Default.Config
|
import Yesod.Default.Config
|
||||||
import qualified Yesod.Default.Util
|
import qualified Yesod.Default.Util
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
|
import Data.Yaml
|
||||||
|
|
||||||
-- | The location of static files on your system. This is a file system
|
-- | The location of static files on your system. This is a file system
|
||||||
-- path. The default value works properly with your scaffolded site.
|
-- path. The default value works properly with your scaffolded site.
|
||||||
@ -43,3 +46,8 @@ widgetFile = Yesod.Default.Util.widgetFileReload
|
|||||||
#else
|
#else
|
||||||
widgetFile = Yesod.Default.Util.widgetFileNoReload
|
widgetFile = Yesod.Default.Util.widgetFileNoReload
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
data Extra = Extra
|
||||||
|
|
||||||
|
loadExtra :: DefaultEnv -> Value -> IO Extra
|
||||||
|
loadExtra _ _ = return Extra
|
||||||
|
|||||||
@ -66,16 +66,17 @@ executable ~project~
|
|||||||
TypeFamilies
|
TypeFamilies
|
||||||
|
|
||||||
build-depends: base >= 4 && < 5
|
build-depends: base >= 4 && < 5
|
||||||
, yesod-core >= 0.9.3 && < 0.10
|
, yesod-core >= 0.10 && < 0.11
|
||||||
, yesod-static >= 0.3.1 && < 0.4
|
, yesod-static >= 0.10 && < 0.11
|
||||||
, yesod-default >= 0.5 && < 0.6
|
, yesod-default >= 0.6 && < 0.7
|
||||||
, clientsession >= 0.7.3 && < 0.8
|
, clientsession >= 0.7.3 && < 0.8
|
||||||
, bytestring >= 0.9 && < 0.10
|
, bytestring >= 0.9 && < 0.10
|
||||||
, text >= 0.11 && < 0.12
|
, text >= 0.11 && < 0.12
|
||||||
, template-haskell
|
, template-haskell
|
||||||
, hamlet >= 0.10 && < 0.11
|
, hamlet >= 0.10 && < 0.11
|
||||||
, shakespeare-text >= 0.10 && < 0.11
|
, shakespeare-text >= 0.10 && < 0.11
|
||||||
, wai >= 0.4.2 && < 0.5
|
, wai >= 1.0 && < 1.1
|
||||||
, transformers >= 0.2 && < 0.3
|
, transformers >= 0.2 && < 0.3
|
||||||
, monad-control >= 0.3 && < 0.4
|
, monad-control >= 0.3 && < 0.4
|
||||||
|
, yaml >= 0.5 && < 0.6
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user