From 709a6892da7b328416da17eda1a218e8d944ddcd Mon Sep 17 00:00:00 2001 From: Greg Weber Date: Fri, 12 Aug 2011 21:14:53 -0700 Subject: [PATCH] cleanup scaffolding config/Settings.hs --- yesod/scaffold.hs | 2 +- yesod/scaffold/config/Settings.hs.cg | 6 +-- yesod/scaffold/tiny/cabal.cg | 7 +-- yesod/scaffold/tiny/config/Settings.hs.cg | 61 +++++++++++++---------- 4 files changed, 44 insertions(+), 32 deletions(-) diff --git a/yesod/scaffold.hs b/yesod/scaffold.hs index 728506ec..bdd5764d 100644 --- a/yesod/scaffold.hs +++ b/yesod/scaffold.hs @@ -118,7 +118,7 @@ scaffold = do Tiny -> "" settingsTextImport = case backend of - Postgresql -> "import Text.Shakespeare.Text (st)\nimport Data.Text (Text, concat)" + Postgresql -> "import Data.Text (Text, concat)" _ -> "import Data.Text" packages = if backend == MongoDB then ", mongoDB\n , bson\n" else "" diff --git a/yesod/scaffold/config/Settings.hs.cg b/yesod/scaffold/config/Settings.hs.cg index 3a0eb6a6..b82359b1 100644 --- a/yesod/scaffold/config/Settings.hs.cg +++ b/yesod/scaffold/config/Settings.hs.cg @@ -117,7 +117,7 @@ staticDir = "static" -- -- To see how this value is used, see urlRenderOverride in ~sitearg~.hs staticRoot :: AppConfig -> Text -staticRoot conf = [st|#{appRoot conf}:#{appPort conf}/static|] +staticRoot conf = [st|#{appRoot conf}:#{show $ appPort conf}/static|] -- The rest of this file contains settings which rarely need changing by a @@ -129,8 +129,8 @@ staticRoot conf = [st|#{appRoot conf}:#{appPort conf}/static|] -- them yourself. ~withConnectionPool~ --- The following three functions are used for calling HTML, CSS and --- Javascript templates from your Haskell code. During development, +-- The following functions are used for calling HTML, CSS, +-- Javascript, and plain text templates from your Haskell code. During development, -- the "Debug" versions of these functions are used so that changes to -- the templates are immediately reflected in an already running -- application. When making a production compile, the non-debug version diff --git a/yesod/scaffold/tiny/cabal.cg b/yesod/scaffold/tiny/cabal.cg index 3eebaae6..bb90305e 100644 --- a/yesod/scaffold/tiny/cabal.cg +++ b/yesod/scaffold/tiny/cabal.cg @@ -54,9 +54,10 @@ executable ~project~ , bytestring , text , template-haskell - , hamlet - , shakespeare-css - , shakespeare-js + , hamlet >= 0.10 && < 0.11 + , shakespeare-css >= 0.10 && < 0.11 + , shakespeare-js >= 0.10 && < 0.11 + , shakespeare-text >= 0.10 && < 0.11 , transformers , data-object , data-object-yaml diff --git a/yesod/scaffold/tiny/config/Settings.hs.cg b/yesod/scaffold/tiny/config/Settings.hs.cg index 558d519c..e9059b95 100644 --- a/yesod/scaffold/tiny/config/Settings.hs.cg +++ b/yesod/scaffold/tiny/config/Settings.hs.cg @@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TemplateHaskell, QuasiQuotes #-} {-# LANGUAGE OverloadedStrings #-} -- | Settings are centralized, as much as possible, into this file. This -- includes database connection settings, static file locations, etc. @@ -19,13 +19,15 @@ module Settings , AppConfig(..) ) where -import qualified Text.Hamlet as H -import qualified Text.Cassius as H -import qualified Text.Julius as H -import qualified Text.Lucius as H +import qualified Text.Hamlet as S +import qualified Text.Cassius as S +import qualified Text.Julius as S +import qualified Text.Lucius as S +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 Data.Monoid (mempty, mappend) +import Data.Monoid (mempty) import System.Directory (doesFileExist) import Data.Text (Text) import Data.Object @@ -92,13 +94,13 @@ staticDir = "static" -- -- To see how this value is used, see urlRenderOverride in ~project~.hs staticRoot :: AppConfig -> Text -staticRoot conf = (appRoot conf) `mappend` "/static" +staticRoot conf = [st|#{appRoot conf}:#{show $ appPort conf}/static|] -- The rest of this file contains settings which rarely need changing by a -- user. --- The following three functions are used for calling HTML, CSS and --- Javascript templates from your Haskell code. During development, +-- The following functions are used for calling HTML, CSS, +-- Javascript, and plain text templates from your Haskell code. During development, -- the "Debug" versions of these functions are used so that changes to -- the templates are immediately reflected in an already running -- application. When making a production compile, the non-debug version @@ -110,42 +112,51 @@ staticRoot conf = (appRoot conf) `mappend` "/static" -- used; to get the same auto-loading effect, it is recommended that you -- use the devel server. -toHamletFile, toCassiusFile, toJuliusFile, toLuciusFile :: String -> FilePath -toHamletFile x = "hamlet/" ++ x ++ ".hamlet" -toCassiusFile x = "cassius/" ++ x ++ ".cassius" -toJuliusFile x = "julius/" ++ x ++ ".julius" -toLuciusFile x = "lucius/" ++ x ++ ".lucius" +-- | expects a root folder for each type, e.g: hamlet/ lucius/ julius/ +globFile :: String -> String -> FilePath +globFile kind x = kind ++ "/" ++ x ++ "." ++ kind hamletFile :: FilePath -> Q Exp -hamletFile = H.hamletFile . toHamletFile +hamletFile = S.hamletFile . globFile "hamlet" cassiusFile :: FilePath -> Q Exp +cassiusFile = #ifdef PRODUCTION -cassiusFile = H.cassiusFile . toCassiusFile + S.cassiusFile . globFile "cassius" #else -cassiusFile = H.cassiusFileDebug . toCassiusFile + S.cassiusFileDebug . globFile "cassius" #endif luciusFile :: FilePath -> Q Exp +luciusFile = #ifdef PRODUCTION -luciusFile = H.luciusFile . toLuciusFile + S.luciusFile . globFile "lucius" #else -luciusFile = H.luciusFileDebug . toLuciusFile + S.luciusFileDebug . globFile "lucius" #endif juliusFile :: FilePath -> Q Exp +juliusFile = #ifdef PRODUCTION -juliusFile = H.juliusFile . toJuliusFile + S.juliusFile . globFile "julius" #else -juliusFile = H.juliusFileDebug . toJuliusFile + S.juliusFileDebug . globFile "julius" +#endif + +textFile :: FilePath -> Q Exp +textFile = +#ifdef PRODUCTION + S.textFile . globFile "text" +#else + S.textFileDebug . globFile "text" #endif widgetFile :: FilePath -> Q Exp widgetFile x = do - let h = whenExists toHamletFile $ whamletFile . toHamletFile - let c = whenExists toCassiusFile cassiusFile - let j = whenExists toJuliusFile juliusFile - let l = whenExists toLuciusFile luciusFile + let h = whenExists (globFile "hamlet") (whamletFile . globFile "hamlet") + let c = whenExists (globFile "cassius") cassiusFile + let j = whenExists (globFile "julius") juliusFile + let l = whenExists (globFile "lucius") luciusFile [|addWidget $h >> addCassius $c >> addJulius $j >> addLucius $l|] where whenExists tofn f = do