From 4ed96e82aca1ad1d5bdba0ea5958739a619468ad Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 14 Dec 2011 08:52:07 +0200 Subject: [PATCH] production -> dev, devel -> library-only, debug -> reload --- yesod-core/yesod-core.cabal | 4 ++-- yesod-default/Yesod/Default/Util.hs | 24 ++++++++++++------------ yesod-default/yesod-default.cabal | 4 ++-- yesod/Devel.hs | 14 ++++++++++++-- yesod/scaffold/Application.hs.cg | 6 +++--- yesod/scaffold/Foundation.hs.cg | 12 ++++++------ yesod/scaffold/Settings.hs.cg | 6 +++--- yesod/scaffold/deploy/Procfile.cg | 4 ++-- yesod/scaffold/project.cabal.cg | 13 +++++++------ yesod/scaffold/tiny/Application.hs.cg | 6 +++--- yesod/scaffold/tiny/Settings.hs.cg | 6 +++--- yesod/scaffold/tiny/project.cabal.cg | 19 ++++++++++--------- 12 files changed, 65 insertions(+), 53 deletions(-) mode change 100755 => 100644 yesod/Devel.hs diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index f50af8bc..38963689 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -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 diff --git a/yesod-default/Yesod/Default/Util.hs b/yesod-default/Yesod/Default/Util.hs index 1e3a5418..fd3c4614 100644 --- a/yesod-default/Yesod/Default/Util.hs +++ b/yesod-default/Yesod/Default/Util.hs @@ -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 diff --git a/yesod-default/yesod-default.cabal b/yesod-default/yesod-default.cabal index d0956de2..ca3cd30f 100644 --- a/yesod-default/yesod-default.cabal +++ b/yesod-default/yesod-default.cabal @@ -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 diff --git a/yesod/Devel.hs b/yesod/Devel.hs old mode 100755 new mode 100644 index 09ce09aa..7dabf331 --- a/yesod/Devel.hs +++ b/yesod/Devel.hs @@ -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) diff --git a/yesod/scaffold/Application.hs.cg b/yesod/scaffold/Application.hs.cg index a371a13e..6da71d8f 100644 --- a/yesod/scaffold/Application.hs.cg +++ b/yesod/scaffold/Application.hs.cg @@ -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 diff --git a/yesod/scaffold/Foundation.hs.cg b/yesod/scaffold/Foundation.hs.cg index 5ab6f4f5..5c51cf38 100644 --- a/yesod/scaffold/Foundation.hs.cg +++ b/yesod/scaffold/Foundation.hs.cg @@ -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 diff --git a/yesod/scaffold/Settings.hs.cg b/yesod/scaffold/Settings.hs.cg index 00e19213..982d1e2e 100644 --- a/yesod/scaffold/Settings.hs.cg +++ b/yesod/scaffold/Settings.hs.cg @@ -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 diff --git a/yesod/scaffold/deploy/Procfile.cg b/yesod/scaffold/deploy/Procfile.cg index 69506c21..e4fab22f 100644 --- a/yesod/scaffold/deploy/Procfile.cg +++ b/yesod/scaffold/deploy/Procfile.cg @@ -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 diff --git a/yesod/scaffold/project.cabal.cg b/yesod/scaffold/project.cabal.cg index 27eb73a4..b7ffa518 100644 --- a/yesod/scaffold/project.cabal.cg +++ b/yesod/scaffold/project.cabal.cg @@ -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 diff --git a/yesod/scaffold/tiny/Application.hs.cg b/yesod/scaffold/tiny/Application.hs.cg index 21911c76..61e46664 100644 --- a/yesod/scaffold/tiny/Application.hs.cg +++ b/yesod/scaffold/tiny/Application.hs.cg @@ -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 diff --git a/yesod/scaffold/tiny/Settings.hs.cg b/yesod/scaffold/tiny/Settings.hs.cg index 8d21e88f..b81780aa 100644 --- a/yesod/scaffold/tiny/Settings.hs.cg +++ b/yesod/scaffold/tiny/Settings.hs.cg @@ -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 diff --git a/yesod/scaffold/tiny/project.cabal.cg b/yesod/scaffold/tiny/project.cabal.cg index 057f367e..b57a46b1 100644 --- a/yesod/scaffold/tiny/project.cabal.cg +++ b/yesod/scaffold/tiny/project.cabal.cg @@ -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