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.hs45
1 files changed, 23 insertions, 22 deletions
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs
index bf5a28e..5f1806d 100644
--- a/compiler/src/Config.hs
+++ b/compiler/src/Config.hs
@@ -17,11 +17,10 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18 18
19module Config 19module Config
20 ( GalleryConfig(..) 20 ( GalleryConfig(..), readConfig
21 , CompilerConfig(..) 21 , ViewerConfig(..), viewerConfig
22 , TagsFromDirectoriesConfig(..) 22 , TagsFromDirectoriesConfig(..)
23 , Resolution(..) 23 , Resolution(..)
24 , readConfig
25 ) where 24 ) where
26 25
27 26
@@ -39,7 +38,18 @@ data Resolution = Resolution
39 } deriving (Generic, Show, ToJSON, FromJSON) 38 } deriving (Generic, Show, ToJSON, FromJSON)
40 39
41 40
42data CompilerConfig = CompilerConfig 41data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig
42 { fromParents :: Int
43 , prefix :: String
44 } deriving (Generic, Show)
45
46instance FromJSON TagsFromDirectoriesConfig where
47 parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig
48 <$> v .:? "fromParents" .!= 0
49 <*> v .:? "prefix" .!= ""
50
51
52data GalleryConfig = GalleryConfig
43 { includedDirectories :: [String] 53 { includedDirectories :: [String]
44 , excludedDirectories :: [String] 54 , excludedDirectories :: [String]
45 , includedFiles :: [String] 55 , includedFiles :: [String]
@@ -49,8 +59,8 @@ data CompilerConfig = CompilerConfig
49 , pictureMaxResolution :: Maybe Resolution 59 , pictureMaxResolution :: Maybe Resolution
50 } deriving (Generic, Show) 60 } deriving (Generic, Show)
51 61
52instance FromJSON CompilerConfig where 62instance FromJSON GalleryConfig where
53 parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig 63 parseJSON = withObject "GalleryConfig" $ \v -> GalleryConfig
54 <$> v .:? "includedDirectories" .!= ["*"] 64 <$> v .:? "includedDirectories" .!= ["*"]
55 <*> v .:? "excludedDirectories" .!= [] 65 <*> v .:? "excludedDirectories" .!= []
56 <*> v .:? "includedFiles" .!= ["*"] 66 <*> v .:? "includedFiles" .!= ["*"]
@@ -59,22 +69,13 @@ instance FromJSON CompilerConfig where
59 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) 69 <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300)
60 <*> v .:? "pictureMaxResolution" 70 <*> v .:? "pictureMaxResolution"
61 71
62 72readConfig :: FileName -> IO GalleryConfig
63data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig 73readConfig = decodeYamlFile
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 74
73 75
74data GalleryConfig = GalleryConfig 76data ViewerConfig = ViewerConfig
75 { compiler :: CompilerConfig 77 { -- TODO: add viewer config keys (tag groups...)
76 , viewer :: JSON.Object 78 } deriving (Generic, ToJSON, Show)
77 } deriving (Generic, FromJSON, Show)
78 79
79readConfig :: FileName -> IO GalleryConfig 80viewerConfig :: GalleryConfig -> ViewerConfig
80readConfig = decodeYamlFile 81viewerConfig _ = ViewerConfig -- TODO