aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Config.hs
diff options
context:
space:
mode:
authorpacien2020-05-02 04:11:24 +0200
committerpacien2020-05-02 04:11:24 +0200
commit8e3ac8fe44bebb38e1882ca7f06b8100078ad88d (patch)
treea748fa1e639cb3b5e1f24a8150e89dbb28c980cb /compiler/src/Config.hs
parent7042ffc06326fa8ffe70f5a59747709250166c16 (diff)
parent0e0b5b0ae44da7c1d67983dedd8f8d8d3516236f (diff)
downloadldgallery-8e3ac8fe44bebb38e1882ca7f06b8100078ad88d.tar.gz
Merge branch 'develop': release v1.0v1.0
Diffstat (limited to 'compiler/src/Config.hs')
-rw-r--r--compiler/src/Config.hs76
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
19module Config 19module 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
26import GHC.Generics (Generic) 27import GHC.Generics (Generic)
27import Data.Aeson (FromJSON, withObject, (.:?), (.!=)) 28import Data.Aeson (ToJSON, FromJSON, withObject, (.:?), (.!=))
28import qualified Data.Aeson as JSON 29import qualified Data.Aeson as JSON
29 30
30import Files (FileName) 31import Files (FileName)
31import Input (decodeYamlFile) 32import Input (decodeYamlFile)
32import Resource (Resolution(..))
33 33
34 34
35data CompilerConfig = CompilerConfig 35data 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 41data TagsFromDirectoriesConfig = TagsFromDirectoriesConfig
42 { fromParents :: Int
43 , prefix :: String
42 } deriving (Generic, Show) 44 } deriving (Generic, Show)
43 45
44instance FromJSON CompilerConfig where 46instance 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
54data GalleryConfig = GalleryConfig 52data 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
66instance 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
59readConfig :: FileName -> IO GalleryConfig 80readConfig :: FileName -> IO GalleryConfig
60readConfig = decodeYamlFile 81readConfig = decodeYamlFile
82
83
84data ViewerConfig = ViewerConfig
85 { galleryTitle :: String
86 , tagCategories :: [String]
87 } deriving (Generic, ToJSON, Show)
88
89viewerConfig :: GalleryConfig -> ViewerConfig
90viewerConfig GalleryConfig{galleryTitle, tagCategories} = ViewerConfig galleryTitle tagCategories