{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Hledger.Web.Settings where
import Data.Default (def)
import Data.Maybe (fromMaybe)
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 :: Bool
development =
#if DEVELOPMENT
True
#else
Bool
False
#endif
production :: Bool
production :: Bool
production = Bool -> Bool
not Bool
development
hledgerorgurl :: Text
hledgerorgurl :: Text
hledgerorgurl = Text
"http://hledger.org"
manualurl :: Text
manualurl :: Text
manualurl = Text
hledgerorgurl forall a. Semigroup a => a -> a -> a
<> Text
"hledger.html"
defhost :: String
defhost :: String
defhost = String
"127.0.0.1"
defport :: Int
defport :: Int
defport = Int
5000
defbaseurl :: String -> Int -> String
defbaseurl :: String -> Int -> String
defbaseurl String
host Int
port =
if Char
':' forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
host then
String
"http://[" forall a. [a] -> [a] -> [a]
++ String
host forall a. [a] -> [a] -> [a]
++ String
"]" forall a. [a] -> [a] -> [a]
++ if Int
port forall a. Eq a => a -> a -> Bool
/= Int
80 then String
":" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
port else String
""
else
String
"http://" forall a. [a] -> [a] -> [a]
++ String
host forall a. [a] -> [a] -> [a]
++ if Int
port forall a. Eq a => a -> a -> Bool
/= Int
80 then String
":" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
port else String
""
staticDir :: FilePath
staticDir :: String
staticDir = String
"static"
staticRoot :: AppConfig DefaultEnv Extra -> Text
staticRoot :: AppConfig DefaultEnv Extra -> Text
staticRoot AppConfig DefaultEnv Extra
conf = forall a. a -> Maybe a -> a
fromMaybe [st|#{appRoot conf}/static|] forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extra -> Maybe Text
extraStaticRoot forall a b. (a -> b) -> a -> b
$ forall environment extra. AppConfig environment extra -> extra
appExtra AppConfig DefaultEnv Extra
conf
widgetFileSettings :: WidgetFileSettings
widgetFileSettings :: WidgetFileSettings
widgetFileSettings = forall a. Default a => a
def
{ wfsHamletSettings :: HamletSettings
wfsHamletSettings = HamletSettings
defaultHamletSettings
{ hamletNewlines :: NewlineStyle
hamletNewlines = NewlineStyle
AlwaysNewlines
}
}
widgetFile :: String -> Q Exp
widgetFile :: String -> Q Exp
widgetFile = (if Bool
development then WidgetFileSettings -> String -> Q Exp
widgetFileReload
else WidgetFileSettings -> String -> Q Exp
widgetFileNoReload)
WidgetFileSettings
widgetFileSettings
data =
{ :: Text
, :: Maybe Text
, :: Maybe Text
} deriving Int -> Extra -> ShowS
[Extra] -> ShowS
Extra -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Extra] -> ShowS
$cshowList :: [Extra] -> ShowS
show :: Extra -> String
$cshow :: Extra -> String
showsPrec :: Int -> Extra -> ShowS
$cshowsPrec :: Int -> Extra -> ShowS
Show
parseExtra :: DefaultEnv -> Object -> Parser Extra
DefaultEnv
_ Object
o = Text -> Maybe Text -> Maybe Text -> Extra
Extra
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"copyright"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"analytics"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"staticRoot"