From e42f4e864bac21ed3b19d1869df2cdd4f8c3433c Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 22 Feb 2020 14:53:03 +0100 Subject: compiler: flatten gallery config GitHub: closes #129 --- compiler/src/Config.hs | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'compiler/src/Config.hs') 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 @@ -- along with this program. If not, see . module Config - ( GalleryConfig(..) - , CompilerConfig(..) + ( GalleryConfig(..), readConfig + , ViewerConfig(..), viewerConfig , TagsFromDirectoriesConfig(..) , Resolution(..) - , readConfig ) where @@ -39,7 +38,18 @@ data Resolution = Resolution } deriving (Generic, Show, ToJSON, FromJSON) -data CompilerConfig = CompilerConfig +data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig + { fromParents :: Int + , prefix :: String + } deriving (Generic, Show) + +instance FromJSON TagsFromDirectoriesConfig where + parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig + <$> v .:? "fromParents" .!= 0 + <*> v .:? "prefix" .!= "" + + +data GalleryConfig = GalleryConfig { includedDirectories :: [String] , excludedDirectories :: [String] , includedFiles :: [String] @@ -49,8 +59,8 @@ data CompilerConfig = CompilerConfig , pictureMaxResolution :: Maybe Resolution } deriving (Generic, Show) -instance FromJSON CompilerConfig where - parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig +instance FromJSON GalleryConfig where + parseJSON = withObject "GalleryConfig" $ \v -> GalleryConfig <$> v .:? "includedDirectories" .!= ["*"] <*> v .:? "excludedDirectories" .!= [] <*> v .:? "includedFiles" .!= ["*"] @@ -59,22 +69,13 @@ instance FromJSON CompilerConfig where <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) <*> v .:? "pictureMaxResolution" - -data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig - { fromParents :: Int - , prefix :: String - } deriving (Generic, Show) - -instance FromJSON TagsFromDirectoriesConfig where - parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig - <$> v .:? "fromParents" .!= 0 - <*> v .:? "prefix" .!= "" +readConfig :: FileName -> IO GalleryConfig +readConfig = decodeYamlFile -data GalleryConfig = GalleryConfig - { compiler :: CompilerConfig - , viewer :: JSON.Object - } deriving (Generic, FromJSON, Show) +data ViewerConfig = ViewerConfig + { -- TODO: add viewer config keys (tag groups...) + } deriving (Generic, ToJSON, Show) -readConfig :: FileName -> IO GalleryConfig -readConfig = decodeYamlFile +viewerConfig :: GalleryConfig -> ViewerConfig +viewerConfig _ = ViewerConfig -- TODO -- cgit v1.2.3