1 /**
2 * Copyright © Webd 2018
3 * License: MIT (https://github.com/DiamondMVC/Webd/blob/master/LICENSE)
4 * Author: Jacob Jensen (bausshf)
5 */
6 module webd.core.config;
7 
8 import vibe.data.serialization : optional;
9 
10 /// Webd configurations.
11 class WebdConfig
12 {
13   /// The name of the website.
14   string websiteName;
15 
16   /// The root path of the website.
17   @optional string rootPath;
18 
19   /// The language.
20   @optional string language;
21 }
22 
23 /// The webd configuration.
24 private static __gshared WebdConfig _webdConfig;
25 
26 /// Gets the webd configuration.
27 @property WebdConfig webdConfig() { return _webdConfig; }
28 
29 /// Loads the webd configuration.
30 void loadWebdConfig()
31 {
32   import vibe.d : deserializeJson;
33   import std.file : readText;
34 
35   _webdConfig = deserializeJson!WebdConfig(readText("config/webd.json"));
36 
37   import std.file : thisExePath;
38   import std.path : dirName, absolutePath;
39 
40   if (!_webdConfig.rootPath)
41   {
42     _webdConfig.rootPath = absolutePath(dirName(thisExePath));
43   }
44 
45   import webd.dal;
46   auto website = getWebsite(_webdConfig.websiteName);
47 
48   if (website)
49   {
50     if (!_webdConfig.language)
51     {
52       _webdConfig.language = website.language;
53     }
54   }
55 }