diff options
Diffstat (limited to 'compiler/src/Config.hs')
-rw-r--r-- | compiler/src/Config.hs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index f147bdd..fe981c3 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs | |||
@@ -20,6 +20,7 @@ | |||
20 | DuplicateRecordFields | 20 | DuplicateRecordFields |
21 | , DeriveGeneric | 21 | , DeriveGeneric |
22 | , DeriveAnyClass | 22 | , DeriveAnyClass |
23 | , OverloadedStrings | ||
23 | #-} | 24 | #-} |
24 | 25 | ||
25 | module Config | 26 | module Config |
@@ -29,25 +30,31 @@ module Config | |||
29 | ) where | 30 | ) where |
30 | 31 | ||
31 | 32 | ||
33 | import Data.Text (Text) | ||
32 | import GHC.Generics (Generic) | 34 | import GHC.Generics (Generic) |
33 | import Data.Aeson (ToJSON, FromJSON) | 35 | import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=)) |
34 | import qualified Data.Aeson as JSON | 36 | import qualified Data.Aeson as JSON |
35 | 37 | ||
36 | import Files (FileName) | 38 | import Files (FileName) |
37 | import Input (decodeYamlFile) | 39 | import Input (decodeYamlFile) |
40 | import Processors (Resolution(..)) | ||
38 | 41 | ||
39 | 42 | ||
40 | data CompilerConfig = CompilerConfig | 43 | data CompilerConfig = CompilerConfig |
41 | { dummy :: Maybe String -- TODO | 44 | { thumbnailResolution :: Resolution |
42 | } deriving (Generic, FromJSON, Show) | 45 | , pictureMaxResolution :: Maybe Resolution |
46 | } deriving (Generic, Show) | ||
47 | |||
48 | instance FromJSON CompilerConfig where | ||
49 | parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig | ||
50 | <$> v .:? "thumbnailResolution" .!= (Resolution 400 400) | ||
51 | <*> v .:? "pictureMaxResolution" | ||
52 | |||
43 | 53 | ||
44 | data GalleryConfig = GalleryConfig | 54 | data GalleryConfig = GalleryConfig |
45 | { compiler :: CompilerConfig | 55 | { compiler :: CompilerConfig |
46 | , viewer :: JSON.Object | 56 | , viewer :: JSON.Object |
47 | } deriving (Generic, FromJSON, Show) | 57 | } deriving (Generic, FromJSON, Show) |
48 | 58 | ||
49 | -- TODO: add compiler config keys and their default values | ||
50 | |||
51 | |||
52 | readConfig :: FileName -> IO GalleryConfig | 59 | readConfig :: FileName -> IO GalleryConfig |
53 | readConfig = decodeYamlFile | 60 | readConfig = decodeYamlFile |