widgetFile in scaffolded site
This commit is contained in:
parent
92ab8ee889
commit
dd693a96a4
@ -16,7 +16,5 @@ getRootR = do
|
|||||||
defaultLayout $ do
|
defaultLayout $ do
|
||||||
h2id <- newIdent
|
h2id <- newIdent
|
||||||
setTitle "~project~ homepage"
|
setTitle "~project~ homepage"
|
||||||
addCassius $(cassiusFile "homepage")
|
addWidget $(widgetFile "homepage")
|
||||||
addJulius $(juliusFile "homepage")
|
|
||||||
addWidget $(hamletFile "homepage")
|
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ module Settings
|
|||||||
( hamletFile
|
( hamletFile
|
||||||
, cassiusFile
|
, cassiusFile
|
||||||
, juliusFile
|
, juliusFile
|
||||||
|
, widgetFile
|
||||||
, connStr
|
, connStr
|
||||||
, ConnectionPool
|
, ConnectionPool
|
||||||
, withConnectionPool
|
, withConnectionPool
|
||||||
@ -22,7 +23,9 @@ import qualified Text.Cassius as H
|
|||||||
import qualified Text.Julius as H
|
import qualified Text.Julius as H
|
||||||
import Language.Haskell.TH.Syntax
|
import Language.Haskell.TH.Syntax
|
||||||
import Database.Persist.~upper~
|
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
|
-- | The base URL for your application. This will usually be different for
|
||||||
-- development and production. Yesod automatically constructs URLs for you,
|
-- 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
|
-- used; to get the same auto-loading effect, it is recommended that you
|
||||||
-- use the devel server.
|
-- 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 :: FilePath -> Q Exp
|
||||||
hamletFile x = H.hamletFile $ "hamlet/" ++ x ++ ".hamlet"
|
hamletFile = H.hamletFile . toHamletFile
|
||||||
|
|
||||||
cassiusFile :: FilePath -> Q Exp
|
cassiusFile :: FilePath -> Q Exp
|
||||||
#ifdef PRODUCTION
|
#ifdef PRODUCTION
|
||||||
cassiusFile x = H.cassiusFile $ "cassius/" ++ x ++ ".cassius"
|
cassiusFile = H.cassiusFile . toCassiusFile
|
||||||
#else
|
#else
|
||||||
cassiusFile x = H.cassiusFileDebug $ "cassius/" ++ x ++ ".cassius"
|
cassiusFile = H.cassiusFileDebug . toCassiusFile
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
juliusFile :: FilePath -> Q Exp
|
juliusFile :: FilePath -> Q Exp
|
||||||
#ifdef PRODUCTION
|
#ifdef PRODUCTION
|
||||||
juliusFile x = H.juliusFile $ "julius/" ++ x ++ ".julius"
|
juliusFile = H.juliusFile . toJuliusFile
|
||||||
#else
|
#else
|
||||||
juliusFile x = H.juliusFileDebug $ "julius/" ++ x ++ ".julius"
|
juliusFile = H.juliusFileDebug . toJuliusFile
|
||||||
#endif
|
#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
|
-- The next two functions are for allocating a connection pool and running
|
||||||
-- database actions using a pool, respectively. It is used internally
|
-- database actions using a pool, respectively. It is used internally
|
||||||
-- by the scaffolded application, and therefore you will rarely need to use
|
-- by the scaffolded application, and therefore you will rarely need to use
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import System.Directory
|
|||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Web.Routes.Site (Site (formatPathSegments))
|
import Web.Routes.Site (Site (formatPathSegments))
|
||||||
import Database.Persist.GenericSql
|
import Database.Persist.GenericSql
|
||||||
import Settings (hamletFile, cassiusFile, juliusFile)
|
import Settings (hamletFile, cassiusFile, juliusFile, widgetFile)
|
||||||
import Model
|
import Model
|
||||||
import Data.Maybe (isJust)
|
import Data.Maybe (isJust)
|
||||||
import Control.Monad (join)
|
import Control.Monad (join)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user