diff --git a/scaffold/Root_hs.cg b/scaffold/Root_hs.cg index c05d8e37..2c3f42f9 100644 --- a/scaffold/Root_hs.cg +++ b/scaffold/Root_hs.cg @@ -16,7 +16,5 @@ getRootR = do defaultLayout $ do h2id <- newIdent setTitle "~project~ homepage" - addCassius $(cassiusFile "homepage") - addJulius $(juliusFile "homepage") - addWidget $(hamletFile "homepage") + addWidget $(widgetFile "homepage") diff --git a/scaffold/Settings_hs.cg b/scaffold/Settings_hs.cg index e1ba8c7f..7e80e669 100644 --- a/scaffold/Settings_hs.cg +++ b/scaffold/Settings_hs.cg @@ -8,6 +8,7 @@ module Settings ( hamletFile , cassiusFile , juliusFile + , widgetFile , connStr , ConnectionPool , withConnectionPool @@ -22,7 +23,9 @@ import qualified Text.Cassius as H import qualified Text.Julius as H import Language.Haskell.TH.Syntax import Database.Persist.~upper~ -import Yesod (MonadInvertIO) +import Yesod (MonadInvertIO, addWidget, addCassius, addJulius) +import Data.Monoid (mempty) +import System.Directory (doesFileExist) -- | The base URL for your application. This will usually be different for -- development and production. Yesod automatically constructs URLs for you, @@ -98,23 +101,39 @@ connectionCount = 10 -- used; to get the same auto-loading effect, it is recommended that you -- use the devel server. +toHamletFile, toCassiusFile, toJuliusFile :: String -> FilePath +toHamletFile x = "hamlet/" ++ x ++ ".hamlet" +toCassiusFile x = "cassius/" ++ x ++ ".cassius" +toJuliusFile x = "julius/" ++ x ++ ".julius" + hamletFile :: FilePath -> Q Exp -hamletFile x = H.hamletFile $ "hamlet/" ++ x ++ ".hamlet" +hamletFile = H.hamletFile . toHamletFile cassiusFile :: FilePath -> Q Exp #ifdef PRODUCTION -cassiusFile x = H.cassiusFile $ "cassius/" ++ x ++ ".cassius" +cassiusFile = H.cassiusFile . toCassiusFile #else -cassiusFile x = H.cassiusFileDebug $ "cassius/" ++ x ++ ".cassius" +cassiusFile = H.cassiusFileDebug . toCassiusFile #endif juliusFile :: FilePath -> Q Exp #ifdef PRODUCTION -juliusFile x = H.juliusFile $ "julius/" ++ x ++ ".julius" +juliusFile = H.juliusFile . toJuliusFile #else -juliusFile x = H.juliusFileDebug $ "julius/" ++ x ++ ".julius" +juliusFile = H.juliusFileDebug . toJuliusFile #endif +widgetFile :: FilePath -> Q Exp +widgetFile x = do + let h = unlessExists toHamletFile hamletFile + let c = unlessExists toCassiusFile cassiusFile + let j = unlessExists toJuliusFile juliusFile + [|addWidget $h >> addCassius $c >> addJulius $j|] + where + unlessExists tofn f = do + e <- qRunIO $ doesFileExist $ tofn x + if e then f x else [|mempty|] + -- The next two functions are for allocating a connection pool and running -- database actions using a pool, respectively. It is used internally -- by the scaffolded application, and therefore you will rarely need to use diff --git a/scaffold/sitearg_hs.cg b/scaffold/sitearg_hs.cg index dad00631..493c27d4 100644 --- a/scaffold/sitearg_hs.cg +++ b/scaffold/sitearg_hs.cg @@ -24,7 +24,7 @@ import System.Directory import qualified Data.ByteString.Lazy as L import Web.Routes.Site (Site (formatPathSegments)) import Database.Persist.GenericSql -import Settings (hamletFile, cassiusFile, juliusFile) +import Settings (hamletFile, cassiusFile, juliusFile, widgetFile) import Model import Data.Maybe (isJust) import Control.Monad (join)