diff options
author | Ralph Amissah <ralph@amissah.com> | 2018-02-09 22:03:10 -0500 |
---|---|---|
committer | Ralph Amissah <ralph@amissah.com> | 2019-04-10 15:14:14 -0400 |
commit | 1c73ddf3894085c646b55d63e61a2483e03a3b4d (patch) | |
tree | 34e3a837d0e0d224008ff380055ea263a03d3c14 /org/meta_read_source_files.org | |
parent | paths, further adjustments (diff) |
0.24.0 toml or sdlang for configuration
Diffstat (limited to 'org/meta_read_source_files.org')
-rw-r--r-- | org/meta_read_source_files.org | 338 |
1 files changed, 267 insertions, 71 deletions
diff --git a/org/meta_read_source_files.org b/org/meta_read_source_files.org index 3bf02b1..b97eb36 100644 --- a/org/meta_read_source_files.org +++ b/org/meta_read_source_files.org @@ -38,19 +38,126 @@ import module sdp.meta.read_config_files; <<meta_config_file_in>> <<meta_config_file_sdl>> +<<meta_config_file_toml>> <<meta_config_file_hub>> #+END_SRC -** 1. read config file, (conf.sdl & sisu_document_make) :file:config: +*** 0. read config files (config_local_site & sisu_document_make) toml or sdlang +**** 1. site configuration + +#+name: meta_config_file_hub +#+BEGIN_SRC d +static template readConfigSite() { + <<imports_std>> + final auto readConfigSite(M,E)(M _manifest, E _env) { + string config_file_str; + string conf_filename = "NONE"; + auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); + auto possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site; + foreach(conf_fn; [_conf_file_details.config_filename_site_toml, _conf_file_details.config_filename_site_sdl]) { + foreach(pth; possible_config_path_locations) { + auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_fn)).array; + conf_filename = conf_fn; + if (config_file_str.length > 0) { + // conf_filename = conf_fn; + break; + } + try { + if (exists(conf_file)) { + debug(io) { + writeln("WARNING (io debug) in config file found: ", conf_file); + // writeln(__LINE__, ": found: ", conf_file, " in ", pth); + } + config_file_str = conf_file.readText; + break; + } + } + catch (ErrnoException ex) { + } + catch (FileException ex) { + } + } + if (config_file_str.length > 0) { break; } + } + struct _ConfContent { + string filename() { + return conf_filename; + } + string filetype() { + return conf_filename.extension.chompPrefix("."); + } + auto content() { + return config_file_str; + } + } + return _ConfContent(); + } +} +#+END_SRC + +**** 2. document make/config + +#+name: meta_config_file_hub +#+BEGIN_SRC d +static template readConfigDoc() { + <<imports_std>> + final auto readConfigDoc(M,E)(M _manifest, E _env) { + string config_file_str; + string conf_filename = "NONE"; + auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); + auto possible_config_path_locations = _conf_file_details.possible_config_path_locations.sisu_document_make; + foreach(conf_fn; [_conf_file_details.config_filename_document_toml, _conf_file_details.config_filename_document_sdl]) { + foreach(pth; possible_config_path_locations) { + auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_fn)).array; + conf_filename = conf_fn; + if (config_file_str.length > 0) { + // conf_filename = conf_fn; + break; + } + try { + if (exists(conf_file)) { + debug(io) { + writeln("WARNING (io debug) in config file found: ", conf_file); + } + config_file_str = conf_file.readText; + break; + } + } + catch (ErrnoException ex) { + } + catch (FileException ex) { + } + } + if (config_file_str.length > 0) { break; } + } + struct _ConfContent { + string filename() { + return conf_filename; + } + string filetype() { + return conf_filename.extension.chompPrefix("."); + } + auto content() { + return config_file_str; + } + } + return _ConfContent(); + } +} +#+END_SRC + +** A. SDLang +*** 1. SDLang read config files (config_local_site & sisu_document_make) :file:config: +**** SDLang config_local_site #+name: meta_config_file_in #+BEGIN_SRC d -static template configInSite() { +static template configReadInSiteSDL() { <<imports_std>> - final string configInSite(M,E)(M manifest, E env) { + final string configReadInSiteSDL(M,E)(M manifest, E env) { auto conf_file_details = ConfigFilePaths!()(manifest, env); - string conf_sdl = conf_file_details.possible_config_path_locations.config_filename_site; - auto possible_config_path_locations = conf_file_details.possible_config_path_locations.local_site; + string conf_sdl = conf_file_details.config_filename_site_sdl; + auto possible_config_path_locations = conf_file_details.possible_config_path_locations.config_local_site; string config_file_str; debug(io) { writeln("WARNING (io debug) in config filename: ", conf_sdl); @@ -80,14 +187,16 @@ static template configInSite() { } #+END_SRC +**** SDLang sisu_document_make + #+name: meta_config_file_in #+BEGIN_SRC d -static template configInDoc() { +static template configReadInDocSDL() { <<imports_std>> - final string configInDoc(M,E)(M manifest, E env) { + final string configReadInDocSDL(M,E)(M manifest, E env) { auto conf_file_details = ConfigFilePaths!()(manifest, env); - string conf_sdl = conf_file_details.config_filename_document; - auto possible_config_path_locations = conf_file_details.possible_config_path_locations.document; + string conf_sdl = conf_file_details.config_filename_document_sdl; + auto possible_config_path_locations = conf_file_details.possible_config_path_locations.sisu_document_make; string config_file_str; debug(io) { writeln("WARNING (io debug) in config filename: ", conf_sdl); @@ -117,85 +226,181 @@ static template configInDoc() { } #+END_SRC -** 2. config files get sdlang root tag -*** 0. template +*** 2. SDLang config files get (sdlang root tag) + #+name: meta_config_file_sdl #+BEGIN_SRC d -/+ - -+/ -static template ConfigSDLang() { +static template configSDLang() { import sdlang; <<imports_std>> - <<meta_config_file_sdlang>> + auto configSDLang(string configuration, string conf_sdl_filename) { + Tag sdl_root_conf; + try { + sdl_root_conf = parseSource(configuration); + } + catch(ParseException e) { + stderr.writeln("SDLang problem with content for ", conf_sdl_filename); + stderr.writeln(e.msg); + } + return sdl_root_conf; + } } #+END_SRC -*** config file get sdl root tag :file:conf:sdlang: +*** 3. SDLang config (config_local_site & sisu_document_make) :file:config:hub: -#+name: meta_config_file_sdlang +#+name: meta_config_file_hub #+BEGIN_SRC d -auto ConfigSDLang(string configuration, string conf_sdl_filename) { - Tag sdl_root_conf; - try { - sdl_root_conf = parseSource(configuration); +static template configReadSiteSDLang() { + <<imports_std>> + import sdlang; + final auto configReadSiteSDLang(M,E)(M manifest, E env) { + auto configuration = configReadInSiteSDL!()(manifest, env); + auto conf_file_details = ConfigFilePaths!()(manifest, env); + string conf_sdl = conf_file_details.config_filename_site_sdl; + auto sdl_root = configSDLang!()(configuration, conf_sdl); + return sdl_root; } - catch(ParseException e) { - stderr.writeln("SDLang problem with content for ", conf_sdl_filename); - stderr.writeln(e.msg); +} +static template configReadDocSDLang() { + <<imports_std>> + import sdlang; + final auto configReadDocSDLang(M,E)(M manifest, E env) { + auto configuration = configReadInDocSDL!()(manifest, env); + auto conf_file_details = ConfigFilePaths!()(manifest, env); + string conf_sdl = conf_file_details.config_filename_document_sdl; + auto sdl_root = configSDLang!()(configuration, conf_sdl); + return sdl_root; } - return sdl_root_conf; } #+END_SRC -** 3. config file (conf.sdl & sisu_document_make) :file:config:hub: -*** 0. template +** B. TOML +*** 1. TOML read config files (config_local_site & sisu_document_make) :file:config: +**** TOML config_local_site -#+name: meta_config_file_hub +#+name: meta_config_file_in #+BEGIN_SRC d -/+ -+/ -static template configReadSite() { - <<imports_std>> - <<meta_config_file_import_sdlang>> - <<meta_config_file_sdlang_hub_site>> -} -static template configReadDoc() { +static template configReadInSiteTOML() { <<imports_std>> - <<meta_config_file_import_sdlang>> - <<meta_config_file_sdlang_hub_doc>> + final string configReadInSiteTOML(M,E)(M manifest, E env) { + auto conf_file_details = ConfigFilePaths!()(manifest, env); + string conf_toml = conf_file_details.config_filename_site_toml; + auto possible_config_path_locations = conf_file_details.possible_config_path_locations.config_local_site; + string config_file_str; + debug(io) { + writeln("WARNING (io debug) in config filename: ", conf_toml); + writeln("WARNING (io debug) in config possible path locations: ", possible_config_path_locations); + } + foreach(pth; possible_config_path_locations) { + auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_toml)).array; + if (config_file_str.length > 0) { + break; + } + try { + if (exists(conf_file)) { + debug(io) { + writeln("WARNING (io debug) in config file found: ", conf_file); + } + config_file_str = conf_file.readText; + break; + } + } + catch (ErrnoException ex) { + } + catch (FileException ex) { + } + } + return config_file_str; + } } #+END_SRC -*** config hub _import sdlang_ -#+name: meta_config_file_import_mixin +**** TOML sisu_document_make + +#+name: meta_config_file_in #+BEGIN_SRC d -import sdlang; +static template configReadInDocTOML() { + <<imports_std>> + final string configReadInDocTOML(M,E)(M manifest, E env) { + auto conf_file_details = ConfigFilePaths!()(manifest, env); + string conf_toml = conf_file_details.config_filename_document_toml; + auto possible_config_path_locations = conf_file_details.possible_config_path_locations.sisu_document_make; + string config_file_str; + debug(io) { + writeln("WARNING (io debug) in config filename: ", conf_toml); + writeln("WARNING (io debug) in config possible path locations: ", possible_config_path_locations); + } + foreach(pth; possible_config_path_locations) { + auto conf_file = asNormalizedPath(chainPath(to!string(pth), conf_toml)).array; + if (config_file_str.length > 0) { + break; + } + try { + if (exists(conf_file)) { + debug(io) { + writeln("WARNING (io debug) in config file found: ", conf_file); + } + config_file_str = conf_file.readText; + break; + } + } + catch (ErrnoException ex) { + } + catch (FileException ex) { + } + } + return config_file_str; + } +} #+END_SRC -*** config hub function read makes for site & doc - -Read in sdl config file name given, and return sdl root +*** 2. TOML config files get -#+name: meta_config_file_sdlang_hub_site +#+name: meta_config_file_toml #+BEGIN_SRC d -final auto configReadSite(M,E)(M manifest, E env) { - auto configuration = configInSite!()(manifest, env); - auto conf_file_details = ConfigFilePaths!()(manifest, env); - string conf_sdl = conf_file_details.possible_config_path_locations.config_filename_site; - auto sdl_root = ConfigSDLang!()(configuration, conf_sdl); - return sdl_root; +static template configTOML() { + import toml; // + <<imports_std>> + auto configTOML(string configuration, string conf_toml_filename) { + TOMLDocument _toml_conf; + try { + _toml_conf = parseTOML(configuration); // parseTOML(cast(string)(configuration)); + } + catch(ErrnoException e) { + stderr.writeln("Toml problem with content for ", conf_toml_filename); + stderr.writeln(e.msg); + } + return _toml_conf; + } } #+END_SRC -#+name: meta_config_file_sdlang_hub_doc +*** 3. TOML config (config_local_site & sisu_document_make) :file:config:hub: + +#+name: meta_config_file_hub #+BEGIN_SRC d -final auto configReadDoc(M,E)(M manifest, E env) { - auto configuration = configInDoc!()(manifest, env); - auto conf_file_details = ConfigFilePaths!()(manifest, env); - string conf_sdl = conf_file_details.config_filename_document; - auto sdl_root = ConfigSDLang!()(configuration, conf_sdl); - return sdl_root; +static template configReadSiteTOML() { + <<imports_std>> + import toml; + final auto configReadSiteTOML(M,E)(M _manifest, E _env) { + auto _configuration = configReadInSiteTOML!()(_manifest, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); + string _conf_toml = _conf_file_details.config_filename_site_toml; + auto _toml_conf = configTOML!()(_configuration, _conf_toml); + return _toml_conf; + } +} +static template configReadDocTOML() { + <<imports_std>> + import toml; + final auto configReadDocTOML(M,E)(M _manifest, E _env) { + auto _configuration = configReadInDocTOML!()(_manifest, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); + string _conf_toml = _conf_file_details.config_filename_document_toml; + auto _toml_conf = configTOML!()(_configuration, _conf_toml); + return _toml_conf; + } } #+END_SRC @@ -280,7 +485,7 @@ static template SiSUrawMarkupContent() { <<meta_markup_source_raw_get_insert_source_line_array>> } struct Inserts { - import sdp.meta.defaults; + import sdp.meta.conf_make_meta_sdlang; auto scan_subdoc_source(O)( O _opt_action, char[][] markup_sourcefile_insert_content, @@ -311,7 +516,7 @@ static template SiSUrawMarkupContent() { #+END_SRC ** get markup source, read file :source:markup: -*** [#A] read file, source string :string: +*** read file, source string :string: #+name: meta_markup_source_raw_read_file_source_string #+BEGIN_SRC d @@ -343,12 +548,7 @@ final private string readInMarkupSource(in char[] fn_src) { } #+END_SRC -**** notes -source_txt_str = readText(fn_src); // ok -catch (ErrnoException ex) { -} - -*** [#A] document header & content, array.length == 2 :array: +*** document header & content, array.length == 2 :array: here you split document header and body, an array.length == 2 split is on first match of level A~ (which is required) @@ -599,10 +799,6 @@ if (type["curly_code"] == 1) { insert_file_list ~= to!string(fn_src_insert); auto raw = MarkupRawUnit(); /+ TODO +/ - if (auto ma = line.match(rgx.src_fn_text)) { - /+ .sst when inserted, not used: headers and heading level ^:?A~ so remove +/ - writeln(__LINE__); writeln(ma); - } auto markup_sourcefile_insert_content = raw.getInsertMarkupSourceContentRawLineArray(fn_src_insert, rgx.src_fn_find_inserts); debug(insert_file) { |