production -> dev, devel -> library-only, debug -> reload

This commit is contained in:
Michael Snoyman 2011-12-14 08:52:07 +02:00
parent 7e643d6848
commit 4ed96e82ac
12 changed files with 65 additions and 53 deletions

View File

@ -54,8 +54,8 @@ library
, path-pieces >= 0.0 && < 0.1
, hamlet >= 0.10 && < 0.11
, shakespeare >= 0.10 && < 0.11
, shakespeare-js >= 0.10 && < 0.11
, shakespeare-css >= 0.10 && < 0.11
, shakespeare-js >= 0.10.4 && < 0.11
, shakespeare-css >= 0.10.5 && < 0.11
, shakespeare-i18n >= 0.0 && < 0.1
, blaze-builder >= 0.2.1.4 && < 0.4
, transformers >= 0.2.2 && < 0.3

View File

@ -5,8 +5,8 @@
module Yesod.Default.Util
( addStaticContentExternal
, globFile
, widgetFileProduction
, widgetFileDebug
, widgetFileNoReload
, widgetFileReload
) where
import Control.Monad.IO.Class (liftIO)
@ -16,9 +16,9 @@ import Yesod.Core -- purposely using complete import so that Haddock will see ad
import Control.Monad (unless)
import System.Directory (doesFileExist, createDirectoryIfMissing)
import Language.Haskell.TH.Syntax
import Text.Lucius (luciusFile, luciusFileDebug)
import Text.Julius (juliusFile, juliusFileDebug)
import Text.Cassius (cassiusFile, cassiusFileDebug)
import Text.Lucius (luciusFile, luciusFileReload)
import Text.Julius (juliusFile, juliusFileReload)
import Text.Cassius (cassiusFile, cassiusFileReload)
import Data.Monoid (mempty)
-- | An implementation of 'addStaticContent' which stores the contents in an
@ -56,20 +56,20 @@ addStaticContentExternal minify hash staticDir toRoute ext' _ content = do
globFile :: String -> String -> FilePath
globFile kind x = "templates/" ++ x ++ "." ++ kind
widgetFileProduction :: FilePath -> Q Exp
widgetFileProduction x = do
widgetFileNoReload :: FilePath -> Q Exp
widgetFileNoReload x = do
let h = whenExists x "hamlet" whamletFile
let c = whenExists x "cassius" cassiusFile
let j = whenExists x "julius" juliusFile
let l = whenExists x "lucius" luciusFile
[|$h >> addCassius $c >> addJulius $j >> addLucius $l|]
widgetFileDebug :: FilePath -> Q Exp
widgetFileDebug x = do
widgetFileReload :: FilePath -> Q Exp
widgetFileReload x = do
let h = whenExists x "hamlet" whamletFile
let c = whenExists x "cassius" cassiusFileDebug
let j = whenExists x "julius" juliusFileDebug
let l = whenExists x "lucius" luciusFileDebug
let c = whenExists x "cassius" cassiusFileReload
let j = whenExists x "julius" juliusFileReload
let l = whenExists x "lucius" luciusFileReload
[|$h >> addCassius $c >> addJulius $j >> addLucius $l|]
whenExists :: String -> String -> (FilePath -> Q Exp) -> Q Exp

View File

@ -27,8 +27,8 @@ library
, transformers >= 0.2.2 && < 0.3
, text >= 0.9
, directory >= 1.0
, shakespeare-css >= 0.10 && < 0.11
, shakespeare-js >= 0.10 && < 0.11
, shakespeare-css >= 0.10.5 && < 0.11
, shakespeare-js >= 0.10.4 && < 0.11
, template-haskell
, data-object >= 0.3 && < 0.4
, data-object-yaml >= 0.3 && < 0.4

14
yesod/Devel.hs Executable file → Normal file
View File

@ -66,8 +66,18 @@ devel isDevel = do
checkCabalFile gpd
_ <- if isDevel
then rawSystem "cabal-dev" ["configure", "--cabal-install-arg=-fdevel", "--disable-library-profiling"]
else rawSystem "cabal" ["configure", "-fdevel", "--disable-library-profiling"]
then rawSystem "cabal-dev"
[ "configure"
, "--cabal-install-arg=-fdevel" -- legacy
, "--cabal-install-arg=-flibrary-only"
, "--disable-library-profiling"
]
else rawSystem "cabal"
[ "configure"
, "-fdevel" -- legacy
, "-flibrary-only"
, "--disable-library-profiling"
]
T.writeFile "dist/devel.hs" (develFile pid)

View File

@ -29,10 +29,10 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
-- migrations handled by Yesod.
with~sitearg~ :: AppConfig DefaultEnv () -> Logger -> (Application -> IO ()) -> IO ()
with~sitearg~ conf logger f = do
#ifdef PRODUCTION
s <- static Settings.staticDir
#else
#ifdef DEV
s <- staticDevel Settings.staticDir
#else
s <- static Settings.staticDir
#endif
dbconf <- withYamlEnvironment "config/~dbConfigFile~.yml" (appEnv conf)
$ either error return . Database.Persist.Base.loadConfig

View File

@ -33,10 +33,10 @@ import Model
import Text.Jasmine (minifym)
import Web.ClientSession (getKey)
import Text.Hamlet (hamletFile)
#if PRODUCTION
import Network.Mail.Mime (sendmail)
#else
#if DEV
import qualified Data.Text.Lazy.Encoding
#else
import Network.Mail.Mime (sendmail)
#endif
-- | The site argument for your application. This can be a good place to
@ -145,10 +145,10 @@ instance YesodAuth ~sitearg~ where
-- Sends off your mail. Requires sendmail in production!
deliver :: ~sitearg~ -> L.ByteString -> IO ()
#ifdef PRODUCTION
deliver _ = sendmail
#else
#ifdef DEV
deliver y = logLazyText (getLogger y) . Data.Text.Lazy.Encoding.decodeUtf8
#else
deliver _ = sendmail
#endif
-- This instance is required to use forms. You can modify renderMessage to

View File

@ -49,8 +49,8 @@ staticRoot conf = [~qq~st|#{appRoot conf}/static|]
-- user.
widgetFile :: String -> Q Exp
#if PRODUCTION
widgetFile = Yesod.Default.Util.widgetFileProduction
#if DEV
widgetFile = Yesod.Default.Util.widgetFileReload
#else
widgetFile = Yesod.Default.Util.widgetFileDebug
widgetFile = Yesod.Default.Util.widgetFileNoReload
#endif

View File

@ -27,12 +27,12 @@
#
# * add code in Settings.hs to turn that url into connection parameters. The below works for Postgresql.
#
# #ifdef PRODUCTION
# #ifdef !DEV
# import qualified Web.Heroku
# #endif
#
# dbConnParams :: AppEnvironment -> IO [(Text, Text)]
# #ifdef PRODUCTION
# #ifdef !DEV
# dbConnParams _ = Web.Heroku.dbConnParams
# #else
# dbConnParams env = do

View File

@ -21,7 +21,7 @@ Flag devel
Default: False
library
if flag(devel)
if flag(library-only)
Buildable: True
else
Buildable: False
@ -35,6 +35,7 @@ library
Handler.Root
ghc-options: -Wall -threaded -O0
cpp-options: -DDEV
extensions: TemplateHaskell
QuasiQuotes
@ -49,14 +50,14 @@ library
FlexibleContexts
executable ~project~
if flag(devel)
if flag(library-only)
Buildable: False
if flag(production)
cpp-options: -DPRODUCTION
ghc-options: -Wall -threaded -O2
else
if flag(dev)
cpp-options: -DDEV
ghc-options: -Wall -threaded -O0
else
ghc-options: -Wall -threaded
main-is: main.hs

View File

@ -28,10 +28,10 @@ mkYesodDispatch "~sitearg~" resources~sitearg~
-- migrations handled by Yesod.
with~sitearg~ :: AppConfig DefaultEnv () -> Logger -> (Application -> IO ()) -> IO ()
with~sitearg~ conf logger f = do
#ifdef PRODUCTION
s <- static Settings.staticDir
#else
#ifdef DEV
s <- staticDevel Settings.staticDir
#else
s <- static Settings.staticDir
#endif
let h = ~sitearg~ conf logger s
defaultRunner f h

View File

@ -38,8 +38,8 @@ staticRoot :: AppConfig DefaultEnv a -> Text
staticRoot conf = [~qq~st|#{appRoot conf}/static|]
widgetFile :: String -> Q Exp
#if PRODUCTION
widgetFile = Yesod.Default.Util.widgetFileProduction
#if DEV
widgetFile = Yesod.Default.Util.widgetFileReload
#else
widgetFile = Yesod.Default.Util.widgetFileDebug
widgetFile = Yesod.Default.Util.widgetFileNoReload
#endif

View File

@ -12,16 +12,16 @@ cabal-version: >= 1.6
build-type: Simple
homepage: http://~project~.yesodweb.com/
Flag production
Description: Build the production executable.
Flag dev
Description: Turn on development settings, like auto-reload templates.
Default: False
Flag devel
Flag library-only
Description: Build for use with "yesod devel"
Default: False
library
if flag(devel)
if flag(library-only)
Buildable: True
else
Buildable: False
@ -33,6 +33,7 @@ library
Handler.Root
ghc-options: -Wall -threaded -O0
cpp-options: -DDEV
extensions: TemplateHaskell
QuasiQuotes
@ -44,14 +45,14 @@ library
TypeFamilies
executable ~project~
if flag(devel)
if flag(library-only)
Buildable: False
if flag(production)
cpp-options: -DPRODUCTION
ghc-options: -Wall -threaded -O2
else
if flag(dev)
cpp-options: -DDEV
ghc-options: -Wall -threaded -O0
else
ghc-options: -Wall -threaded
main-is: main.hs