Created
February 27, 2012 09:32
-
-
Save scan/1922803 to your computer and use it in GitHub Desktop.
Settings for coffee and lucius only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Settings are centralized, as much as possible, into this file. This | |
-- includes database connection settings, static file locations, etc. | |
-- In addition, you can configure a number of different aspects of Yesod | |
-- by overriding methods in the Yesod typeclass. That instance is | |
-- declared in the Foundation.hs file. | |
module Settings | |
( widgetFile | |
, PersistConfig | |
, staticRoot | |
, staticDir | |
, Extra (..) | |
, parseExtra | |
) where | |
import Prelude | |
import Text.Shakespeare.Text (st) | |
import Language.Haskell.TH.Syntax | |
import Database.Persist.Postgresql (PostgresConf) | |
import Yesod.Default.Config | |
import qualified Yesod.Default.Util as DU | |
import Data.Text (Text) | |
import Data.Yaml | |
import Data.Monoid (mempty) | |
import Control.Applicative | |
import Text.Lucius (luciusFile, luciusFileReload) | |
import Text.Coffee (coffeeFile, coffeeFileReload) | |
import Yesod.Core (whamletFile, addJulius, addLucius) | |
import System.Directory (doesFileExist) | |
-- | Which Persistent backend this site is using. | |
type PersistConfig = PostgresConf | |
-- Static setting below. Changing these requires a recompile | |
-- | The location of static files on your system. This is a file system | |
-- path. The default value works properly with your scaffolded site. | |
staticDir :: FilePath | |
staticDir = "static" | |
-- | The base URL for your static files. As you can see by the default | |
-- value, this can simply be "static" appended to your application root. | |
-- A powerful optimization can be serving static files from a separate | |
-- domain name. This allows you to use a web server optimized for static | |
-- files, more easily set expires and cache values, and avoid possibly | |
-- costly transference of cookies on static files. For more information, | |
-- please see: | |
-- http://code.google.com/speed/page-speed/docs/request.html#ServeFromCookielessDomain | |
-- | |
-- If you change the resource pattern for StaticR in Foundation.hs, you will | |
-- have to make a corresponding change here. | |
-- | |
-- To see how this value is used, see urlRenderOverride in Foundation.hs | |
staticRoot :: AppConfig DefaultEnv x -> Text | |
staticRoot conf = [st|#{appRoot conf}/static|] | |
-- The rest of this file contains settings which rarely need changing by a | |
-- user. | |
widgetFile :: String -> Q Exp | |
#if DEVELOPMENT | |
widgetFile = widgetFileReload | |
#else | |
widgetFile = widgetFileNoReload | |
#endif | |
widgetFileNoReload :: FilePath -> Q Exp | |
widgetFileNoReload x = do | |
let h = whenExists x "hamlet" whamletFile | |
let c = whenExists x "coffee" coffeeFile | |
let l = whenExists x "lucius" luciusFile | |
[|$h >> addJulius $c >> addLucius $l|] | |
widgetFileReload :: FilePath -> Q Exp | |
widgetFileReload x = do | |
let h = whenExists x "hamlet" whamletFile | |
let c = whenExists x "coffee" coffeeFileReload | |
let l = whenExists x "lucius" luciusFileReload | |
[|$h >> addJulius $c >> addLucius $l|] | |
whenExists :: String -> String -> (FilePath -> Q Exp) -> Q Exp | |
whenExists x glob f = do | |
let fn = DU.globFile glob x | |
e <- qRunIO $ doesFileExist fn | |
if e then f fn else [|mempty|] | |
data Extra = Extra | |
{ extraCopyright :: Text | |
, extraAnalytics :: Maybe Text -- ^ Google Analytics | |
} deriving Show | |
parseExtra :: DefaultEnv -> Object -> Parser Extra | |
parseExtra _ o = Extra | |
<$> o .: "copyright" | |
<*> o .:? "analytics" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment