diff options
author | pacien | 2020-05-02 04:11:24 +0200 |
---|---|---|
committer | pacien | 2020-05-02 04:11:24 +0200 |
commit | 8e3ac8fe44bebb38e1882ca7f06b8100078ad88d (patch) | |
tree | a748fa1e639cb3b5e1f24a8150e89dbb28c980cb /compiler/src/Config.hs | |
parent | 7042ffc06326fa8ffe70f5a59747709250166c16 (diff) | |
parent | 0e0b5b0ae44da7c1d67983dedd8f8d8d3516236f (diff) | |
download | ldgallery-8e3ac8fe44bebb38e1882ca7f06b8100078ad88d.tar.gz |
Merge branch 'develop': release v1.0v1.0
Diffstat (limited to 'compiler/src/Config.hs')
-rw-r--r-- | compiler/src/Config.hs | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/compiler/src/Config.hs b/compiler/src/Config.hs index 53333a5..0ae0fa1 100644 --- a/compiler/src/Config.hs +++ b/compiler/src/Config.hs | |||
@@ -17,44 +17,74 @@ | |||
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 | ||
19 | module Config | 19 | module Config |
20 | ( GalleryConfig(..) | 20 | ( GalleryConfig(..), readConfig |
21 | , CompilerConfig(..) | 21 | , ViewerConfig(..), viewerConfig |
22 | , readConfig | 22 | , TagsFromDirectoriesConfig(..) |
23 | , Resolution(..) | ||
23 | ) where | 24 | ) where |
24 | 25 | ||
25 | 26 | ||
26 | import GHC.Generics (Generic) | 27 | import GHC.Generics (Generic) |
27 | import Data.Aeson (FromJSON, withObject, (.:?), (.!=)) | 28 | import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=)) |
28 | import qualified Data.Aeson as JSON | 29 | import qualified Data.Aeson as JSON |
29 | 30 | ||
30 | import Files (FileName) | 31 | import Files (FileName) |
31 | import Input (decodeYamlFile) | 32 | import Input (decodeYamlFile) |
32 | import Resource (Resolution(..)) | ||
33 | 33 | ||
34 | 34 | ||
35 | data CompilerConfig = CompilerConfig | 35 | data Resolution = Resolution |
36 | { galleryName :: String | 36 | { width :: Int |
37 | , includeFiles :: [String] | 37 | , height :: Int |
38 | , excludeFiles :: [String] | 38 | } deriving (Generic, Show, ToJSON, FromJSON) |
39 | , tagsFromDirectories :: Int | 39 | |
40 | , thumbnailMaxResolution :: Resolution | 40 | |
41 | , pictureMaxResolution :: Maybe Resolution | 41 | data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig |
42 | { fromParents :: Int | ||
43 | , prefix :: String | ||
42 | } deriving (Generic, Show) | 44 | } deriving (Generic, Show) |
43 | 45 | ||
44 | instance FromJSON CompilerConfig where | 46 | instance FromJSON TagsFromDirectoriesConfig where |
45 | parseJSON = withObject "CompilerConfig" $ \v -> CompilerConfig | 47 | parseJSON = withObject "TagsFromDirectoriesConfig" $ \v -> TagsFromDirectoriesConfig |
46 | <$> v .:? "galleryName" .!= "Gallery" | 48 | <$> v .:? "fromParents" .!= 0 |
47 | <*> v .:? "includeFiles" .!= ["*"] | 49 | <*> v .:? "prefix" .!= "" |
48 | <*> v .:? "excludeFiles" .!= [] | ||
49 | <*> v .:? "tagsFromDirectories" .!= 0 | ||
50 | <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 400) | ||
51 | <*> v .:? "pictureMaxResolution" | ||
52 | 50 | ||
53 | 51 | ||
54 | data GalleryConfig = GalleryConfig | 52 | data GalleryConfig = GalleryConfig |
55 | { compiler :: CompilerConfig | 53 | { galleryTitle :: String |
56 | , viewer :: JSON.Object | 54 | , includedDirectories :: [String] |
57 | } deriving (Generic, FromJSON, Show) | 55 | , excludedDirectories :: [String] |
56 | , includedFiles :: [String] | ||
57 | , excludedFiles :: [String] | ||
58 | , includedTags :: [String] | ||
59 | , excludedTags :: [String] | ||
60 | , tagCategories :: [String] | ||
61 | , tagsFromDirectories :: TagsFromDirectoriesConfig | ||
62 | , thumbnailMaxResolution :: Resolution | ||
63 | , pictureMaxResolution :: Maybe Resolution | ||
64 | } deriving (Generic, Show) | ||
65 | |||
66 | instance FromJSON GalleryConfig where | ||
67 | parseJSON = withObject "GalleryConfig" $ \v -> GalleryConfig | ||
68 | <$> v .:? "galleryTitle" .!= "ldgallery" | ||
69 | <*> v .:? "includedDirectories" .!= ["*"] | ||
70 | <*> v .:? "excludedDirectories" .!= [] | ||
71 | <*> v .:? "includedFiles" .!= ["*"] | ||
72 | <*> v .:? "excludedFiles" .!= [] | ||
73 | <*> v .:? "includedTags" .!= ["*"] | ||
74 | <*> v .:? "excludedTags" .!= [] | ||
75 | <*> v .:? "tagCategories" .!= [] | ||
76 | <*> v .:? "tagsFromDirectories" .!= (TagsFromDirectoriesConfig 0 "") | ||
77 | <*> v .:? "thumbnailMaxResolution" .!= (Resolution 400 300) | ||
78 | <*> v .:? "pictureMaxResolution" | ||
58 | 79 | ||
59 | readConfig :: FileName -> IO GalleryConfig | 80 | readConfig :: FileName -> IO GalleryConfig |
60 | readConfig = decodeYamlFile | 81 | readConfig = decodeYamlFile |
82 | |||
83 | |||
84 | data ViewerConfig = ViewerConfig | ||
85 | { galleryTitle :: String | ||
86 | , tagCategories :: [String] | ||
87 | } deriving (Generic, ToJSON, Show) | ||
88 | |||
89 | viewerConfig :: GalleryConfig -> ViewerConfig | ||
90 | viewerConfig GalleryConfig{galleryTitle, tagCategories} = ViewerConfig galleryTitle tagCategories | ||