aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Config.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Config.hs')
-rw-r--r--compiler/src/Config.hs26
1 files changed, 22 insertions, 4 deletions
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs
index 4826f17..bf5a28e 100644
--- a/compiler/src/Config.hs
+++ b/compiler/src/Config.hs
@@ -19,17 +19,24 @@
19module Config 19module Config
20 ( GalleryConfig(..) 20 ( GalleryConfig(..)
21 , CompilerConfig(..) 21 , CompilerConfig(..)
22 , TagsFromDirectoriesConfig(..)
23 , Resolution(..)
22 , readConfig 24 , readConfig
23 ) where 25 ) where
24 26
25 27
26import GHC.Generics (Generic) 28import GHC.Generics (Generic)
27import Data.Aeson (FromJSON, withObject, (.:?), (.!=)) 29import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=))
28import qualified Data.Aeson as JSON 30import qualified Data.Aeson as JSON
29 31
30import Files (FileName) 32import Files (FileName)
31import Input (decodeYamlFile) 33import Input (decodeYamlFile)
32import Resource (Resolution(..)) 34
35
36data Resolution = Resolution
37 { width :: Int
38 , height :: Int
39 } deriving (Generic, Show, ToJSON, FromJSON)
33 40
34 41
35data CompilerConfig = CompilerConfig 42data CompilerConfig = CompilerConfig
@@ -37,7 +44,7 @@ data CompilerConfig = CompilerConfig
37 , excludedDirectories :: [String] 44 , excludedDirectories :: [String]
38 , includedFiles :: [String] 45 , includedFiles :: [String]
39 , excludedFiles :: [String] 46 , excludedFiles :: [String]
40 , tagsFromDirectories :: Int 47 , tagsFromDirectories :: TagsFromDirectoriesConfig
41 , thumbnailMaxResolution :: Resolution 48 , thumbnailMaxResolution :: Resolution
42 , pictureMaxResolution :: Maybe Resolution 49 , pictureMaxResolution :: Maybe Resolution
43 } deriving (Generic, Show) 50 } deriving (Generic, Show)
@@ -48,11 +55,22 @@ instance FromJSON CompilerConfig where
48 <*> v .:? "excludedDirectories" .!= [] 55 <*> v .:? "excludedDirectories" .!= []
49 <*> v .:? "includedFiles" .!= ["*"] 56 <*> v .:? "includedFiles" .!= ["*"]
50 <*> v .:? "excludedFiles" .!= [] 57 <*> v .:? "excludedFiles" .!= []
51 <*> v .:? "tagsFromDirectories" .!= 0 58 <*> v .:? "tagsFromDirectories" .!= (TagsFromDirectoriesConfig 0 "")
52 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) 59 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300)
53 <*> v .:? "pictureMaxResolution" 60 <*> v .:? "pictureMaxResolution"
54 61
55 62
63data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig
64 { fromParents :: Int
65 , prefix :: String
66 } deriving (Generic, Show)
67
68instance FromJSON TagsFromDirectoriesConfig where
69 parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig
70 <$> v .:? "fromParents" .!= 0
71 <*> v .:? "prefix" .!= ""
72
73
56data GalleryConfig = GalleryConfig 74data GalleryConfig = GalleryConfig
57 { compiler :: CompilerConfig 75 { compiler :: CompilerConfig
58 , viewer :: JSON.Object 76 , viewer :: JSON.Object