cleanup scaffolding config/Settings.hs
This commit is contained in:
parent
4d09d1ee4d
commit
709a6892da
@ -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 ""
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user