cleanup scaffolding config/Settings.hs

This commit is contained in:
Greg Weber 2011-08-12 21:14:53 -07:00
parent 4d09d1ee4d
commit 709a6892da
4 changed files with 44 additions and 32 deletions

View File

@ -118,7 +118,7 @@ scaffold = do
Tiny -> "" Tiny -> ""
settingsTextImport = case backend of settingsTextImport = case backend of
Postgresql -> "import Text.Shakespeare.Text (st)\nimport Data.Text (Text, concat)" Postgresql -> "import Data.Text (Text, concat)"
_ -> "import Data.Text" _ -> "import Data.Text"
packages = if backend == MongoDB then ", mongoDB\n , bson\n" else "" packages = if backend == MongoDB then ", mongoDB\n , bson\n" else ""

View File

@ -117,7 +117,7 @@ staticDir = "static"
-- --
-- To see how this value is used, see urlRenderOverride in ~sitearg~.hs -- To see how this value is used, see urlRenderOverride in ~sitearg~.hs
staticRoot :: AppConfig -> Text 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 -- 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. -- them yourself.
~withConnectionPool~ ~withConnectionPool~
-- The following three functions are used for calling HTML, CSS and -- The following functions are used for calling HTML, CSS,
-- Javascript templates from your Haskell code. During development, -- Javascript, and plain text templates from your Haskell code. During development,
-- the "Debug" versions of these functions are used so that changes to -- the "Debug" versions of these functions are used so that changes to
-- the templates are immediately reflected in an already running -- the templates are immediately reflected in an already running
-- application. When making a production compile, the non-debug version -- application. When making a production compile, the non-debug version

View File

@ -54,9 +54,10 @@ executable ~project~
, bytestring , bytestring
, text , text
, template-haskell , template-haskell
, hamlet , hamlet >= 0.10 && < 0.11
, shakespeare-css , shakespeare-css >= 0.10 && < 0.11
, shakespeare-js , shakespeare-js >= 0.10 && < 0.11
, shakespeare-text >= 0.10 && < 0.11
, transformers , transformers
, data-object , data-object
, data-object-yaml , data-object-yaml

View File

@ -1,5 +1,5 @@
{-# LANGUAGE CPP #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
-- | Settings are centralized, as much as possible, into this file. This -- | Settings are centralized, as much as possible, into this file. This
-- includes database connection settings, static file locations, etc. -- includes database connection settings, static file locations, etc.
@ -19,13 +19,15 @@ module Settings
, AppConfig(..) , AppConfig(..)
) where ) where
import qualified Text.Hamlet as H import qualified Text.Hamlet as S
import qualified Text.Cassius as H import qualified Text.Cassius as S
import qualified Text.Julius as H import qualified Text.Julius as S
import qualified Text.Lucius as H import qualified Text.Lucius as S
import qualified Text.Shakespeare.Text as S
import Text.Shakespeare.Text (st)
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
import Yesod.Widget (addWidget, addCassius, addJulius, addLucius, whamletFile) import Yesod.Widget (addWidget, addCassius, addJulius, addLucius, whamletFile)
import Data.Monoid (mempty, mappend) import Data.Monoid (mempty)
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
import Data.Text (Text) import Data.Text (Text)
import Data.Object import Data.Object
@ -92,13 +94,13 @@ staticDir = "static"
-- --
-- To see how this value is used, see urlRenderOverride in ~project~.hs -- To see how this value is used, see urlRenderOverride in ~project~.hs
staticRoot :: AppConfig -> Text 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 -- The rest of this file contains settings which rarely need changing by a
-- user. -- user.
-- The following three functions are used for calling HTML, CSS and -- The following functions are used for calling HTML, CSS,
-- Javascript templates from your Haskell code. During development, -- Javascript, and plain text templates from your Haskell code. During development,
-- the "Debug" versions of these functions are used so that changes to -- the "Debug" versions of these functions are used so that changes to
-- the templates are immediately reflected in an already running -- the templates are immediately reflected in an already running
-- application. When making a production compile, the non-debug version -- 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 -- used; to get the same auto-loading effect, it is recommended that you
-- use the devel server. -- use the devel server.
toHamletFile, toCassiusFile, toJuliusFile, toLuciusFile :: String -> FilePath -- | expects a root folder for each type, e.g: hamlet/ lucius/ julius/
toHamletFile x = "hamlet/" ++ x ++ ".hamlet" globFile :: String -> String -> FilePath
toCassiusFile x = "cassius/" ++ x ++ ".cassius" globFile kind x = kind ++ "/" ++ x ++ "." ++ kind
toJuliusFile x = "julius/" ++ x ++ ".julius"
toLuciusFile x = "lucius/" ++ x ++ ".lucius"
hamletFile :: FilePath -> Q Exp hamletFile :: FilePath -> Q Exp
hamletFile = H.hamletFile . toHamletFile hamletFile = S.hamletFile . globFile "hamlet"
cassiusFile :: FilePath -> Q Exp cassiusFile :: FilePath -> Q Exp
cassiusFile =
#ifdef PRODUCTION #ifdef PRODUCTION
cassiusFile = H.cassiusFile . toCassiusFile S.cassiusFile . globFile "cassius"
#else #else
cassiusFile = H.cassiusFileDebug . toCassiusFile S.cassiusFileDebug . globFile "cassius"
#endif #endif
luciusFile :: FilePath -> Q Exp luciusFile :: FilePath -> Q Exp
luciusFile =
#ifdef PRODUCTION #ifdef PRODUCTION
luciusFile = H.luciusFile . toLuciusFile S.luciusFile . globFile "lucius"
#else #else
luciusFile = H.luciusFileDebug . toLuciusFile S.luciusFileDebug . globFile "lucius"
#endif #endif
juliusFile :: FilePath -> Q Exp juliusFile :: FilePath -> Q Exp
juliusFile =
#ifdef PRODUCTION #ifdef PRODUCTION
juliusFile = H.juliusFile . toJuliusFile S.juliusFile . globFile "julius"
#else #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 #endif
widgetFile :: FilePath -> Q Exp widgetFile :: FilePath -> Q Exp
widgetFile x = do widgetFile x = do
let h = whenExists toHamletFile $ whamletFile . toHamletFile let h = whenExists (globFile "hamlet") (whamletFile . globFile "hamlet")
let c = whenExists toCassiusFile cassiusFile let c = whenExists (globFile "cassius") cassiusFile
let j = whenExists toJuliusFile juliusFile let j = whenExists (globFile "julius") juliusFile
let l = whenExists toLuciusFile luciusFile let l = whenExists (globFile "lucius") luciusFile
[|addWidget $h >> addCassius $c >> addJulius $j >> addLucius $l|] [|addWidget $h >> addCassius $c >> addJulius $j >> addLucius $l|]
where where
whenExists tofn f = do whenExists tofn f = do