{-# LANGUAGE CPP, OverloadedStrings, QuasiQuotes #-}
module Hledger.Web.Settings where
import Data.Default (def)
#if !(MIN_VERSION_base(4,13,0))
import Data.Semigroup ((<>))
#endif
import Data.Text (Text)
import Data.Yaml
import Language.Haskell.TH.Syntax (Q, Exp)
import Text.Hamlet
import Text.Shakespeare.Text (st)
import Yesod.Default.Config
import Yesod.Default.Util
development :: Bool
development =
#if DEVELOPMENT
True
#else
False
#endif
production :: Bool
production = not development
hledgerorgurl :: Text
hledgerorgurl = "http://hledger.org"
manualurl :: Text
manualurl = hledgerorgurl <> "/manual"
defhost :: String
defhost = "127.0.0.1"
defport :: Int
defport = 5000
defbaseurl :: String -> Int -> String
defbaseurl host port =
if ':' `elem` host then
"http://[" ++ host ++ "]" ++ if port /= 80 then ":" ++ show port else ""
else
"http://" ++ host ++ if port /= 80 then ":" ++ show port else ""
staticDir :: FilePath
staticDir = "static"
staticRoot :: AppConfig DefaultEnv Extra -> Text
staticRoot conf = case extraStaticRoot $ appExtra conf of
Just root -> root
Nothing -> [st|#{appRoot conf}/static|]
widgetFileSettings :: WidgetFileSettings
widgetFileSettings = def
{ wfsHamletSettings = defaultHamletSettings
{ hamletNewlines = AlwaysNewlines
}
}
widgetFile :: String -> Q Exp
widgetFile = (if development then widgetFileReload
else widgetFileNoReload)
widgetFileSettings
data Extra = Extra
{ extraCopyright :: Text
, extraAnalytics :: Maybe Text
, extraStaticRoot :: Maybe Text
} deriving Show
parseExtra :: DefaultEnv -> Object -> Parser Extra
parseExtra _ o = Extra
<$> o .: "copyright"
<*> o .:? "analytics"
<*> o .:? "staticRoot"