forked from dtekcth/DtekPortalen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.hs
136 lines (123 loc) · 4.46 KB
/
Settings.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- | 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
, development
, swedishTimeLocale
, swedishHumanTimeLocale
) where
import Prelude
import Text.Shakespeare.Text (st)
import Language.Haskell.TH.Syntax
import Database.Persist.Postgresql (PostgresConf)
import Yesod.Default.Config
import Yesod.Default.Util
import Data.Text (Text)
import Data.Yaml
import Control.Applicative
import Settings.Development
import Data.Default (def)
import Text.Hamlet
import System.Locale
import Data.Time.Format.Human
-- | 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|]
-- | Settings for 'widgetFile', such as which template languages to support and
-- default Hamlet settings.
widgetFileSettings :: WidgetFileSettings
widgetFileSettings = def
{ wfsHamletSettings = defaultHamletSettings
{ hamletNewlines = AlwaysNewlines
}
}
-- The rest of this file contains settings which rarely need changing by a
-- user.
widgetFile :: String -> Q Exp
widgetFile = (if development then widgetFileReload
else widgetFileNoReload)
widgetFileSettings
data Extra = Extra
{ extraCalendar :: Text -- ^ Google Calendar
, extraAnalytics :: Maybe Text -- ^ Google Analytics
} deriving Show
parseExtra :: DefaultEnv -> Object -> Parser Extra
parseExtra _ o = Extra
<$> o .: "calendar"
<*> o .:? "analytics"
swedishTimeLocale :: TimeLocale
swedishTimeLocale = TimeLocale {
wDays = [ ("söndag", "sön")
, ("måndag", "mån")
, ("tisdag", "tis")
, ("onsdag", "ons")
, ("torsdag", "tor")
, ("fredag", "fre")
, ("lördag", "lör")],
months = [ ("januari", "jan")
, ("februari", "feb")
, ("mars", "mar")
, ("april", "apr")
, ("maj", "maj")
, ("juni", "jun")
, ("juli", "jul")
, ("augusti", "aug")
, ("september", "sep")
, ("oktober", "okt")
, ("november", "nov")
, ("december", "dec")],
intervals = [ ("år", "år")
, ("månad", "månader")
, ("dag", "dagar")
, ("timme", "timmar")
, ("minut", "minuter")
, ("sekund", "sekunder")
, ("µsekund", "µsekunder")],
amPm = ("fm", "em"),
dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",
dateFmt = "%Y-%m-%d",
timeFmt = "%H:%M:%S",
time12Fmt = "%I:%M:%S %p"
}
swedishHumanTimeLocale :: HumanTimeLocale
swedishHumanTimeLocale = HumanTimeLocale
{ justNow = "just nu"
, secondsAgo = \x -> "för " ++ x ++ " sekunder sedan"
, oneMinuteAgo = "en minut sedan"
, minutesAgo = \x -> "för " ++ x ++ " minuter sedan"
, oneHourAgo = "en timme sedan"
, aboutHoursAgo = \x -> "för cirka " ++ x ++ " timmar sedan"
, at = \x -> "i " ++ x ++ "s"
, daysAgo = \x -> "för " ++ x ++ " dagar sedan"
, weekAgo = \x -> "för " ++ x ++ " vecka sedan"
, weeksAgo = \x -> "för " ++ x ++ " veckor sedan"
, onYear = ("" ++)
, locale = swedishTimeLocale
}