From d43281245f1732941228d79663c8e8d3280a972c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 24 Sep 2019 11:13:42 -0400 Subject: document headers & config: yaml introduced - as toml alternative - both toml & yaml (meta, conf, make) work --- org/source_files_read.org | 124 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 103 insertions(+), 21 deletions(-) (limited to 'org/source_files_read.org') diff --git a/org/source_files_read.org b/org/source_files_read.org index e7eb02a..02e31e0 100644 --- a/org/source_files_read.org +++ b/org/source_files_read.org @@ -42,19 +42,23 @@ module doc_reform.source.read_config_files; <> #+END_SRC -*** 0. read config files (config_local_site & dr_document_make) toml +*** 0. read config files (config_local_site & dr_document_make) (yaml or toml) **** 1. site configuration #+name: meta_config_file_hub #+BEGIN_SRC d static template readConfigSite() { + import + doc_reform.meta.rgx; <> + mixin DocReformRgxInit; final auto readConfigSite(M,E)(M _manifest, E _env) { + static auto rgx = Rgx(); string config_file_str; string conf_filename = "NONE"; auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site; - foreach(conf_fn; [_conf_file_details.config_filename_site_toml]) { + foreach(conf_fn; [_conf_file_details.config_filename_site]) { foreach(pth; possible_config_path_locations) { char[] conf_file = asNormalizedPath(chainPath(pth.to!string, conf_fn)).array; conf_filename = conf_fn; @@ -81,7 +85,13 @@ static template readConfigSite() { return conf_filename; } string filetype() { - return conf_filename.extension.chompPrefix("."); + string _ft = ""; + if (content.match(rgx.yaml_config)) { + _ft = "yaml"; + } else if (content.match(rgx.toml_config)) { + _ft = "toml"; + } + return _ft; } string content() { return config_file_str; @@ -97,13 +107,17 @@ static template readConfigSite() { #+name: meta_config_file_hub #+BEGIN_SRC d static template readConfigDoc() { + import + doc_reform.meta.rgx; <> + mixin DocReformRgxInit; final auto readConfigDoc(M,E)(M _manifest, E _env) { + static auto rgx = Rgx(); string config_file_str; string conf_filename = "NONE"; auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.dr_document_make; - foreach(conf_fn; [_conf_file_details.config_filename_document_toml]) { + foreach(conf_fn; [_conf_file_details.config_filename_document]) { foreach(pth; possible_config_path_locations) { auto conf_file = asNormalizedPath(chainPath(pth.to!string, conf_fn)).array; conf_filename = conf_fn; @@ -129,12 +143,18 @@ static template readConfigDoc() { string filename() { return conf_filename; } - string filetype() { - return conf_filename.extension.chompPrefix("."); - } - auto content() { + string content() { return config_file_str; } + string filetype() { + string _ft = ""; + if (content.match(rgx.yaml_config)) { + _ft = "yaml"; + } else if (content.match(rgx.toml_config)) { + _ft = "toml"; + } + return _ft; + } } return _ConfContent(); } @@ -147,11 +167,11 @@ static template readConfigDoc() { #+name: meta_config_file_in #+BEGIN_SRC d -static template configReadInSiteTOML() { +static template configReadInSiteSTR() { <> - final string configReadInSiteTOML(M,E)(M manifest, E env) { + final string configReadInSiteSTR(M,E)(M manifest, E env) { auto conf_file_details = ConfigFilePaths!()(manifest, env); - string conf_toml = conf_file_details.config_filename_site_toml; + string conf_toml = conf_file_details.config_filename_site; string[] possible_config_path_locations = conf_file_details.possible_config_path_locations.config_local_site; string config_file_str; debug(io) { @@ -184,11 +204,11 @@ static template configReadInSiteTOML() { #+name: meta_config_file_in #+BEGIN_SRC d -static template configReadInDocTOML() { +static template configReadInDocSTR() { <> - final string configReadInDocTOML(M,E)(M manifest, E env) { + final string configReadInDocSTR(M,E)(M manifest, E env) { auto conf_file_details = ConfigFilePaths!()(manifest, env); - string conf_toml = conf_file_details.config_filename_document_toml; + string conf_toml = conf_file_details.config_filename_document; string[] possible_config_path_locations = conf_file_details.possible_config_path_locations.dr_document_make; string config_file_str; debug(io) { @@ -217,6 +237,54 @@ static template configReadInDocTOML() { } #+END_SRC +*** 2. YAML config files get + +#+name: meta_config_file_yaml +#+BEGIN_SRC d +static template configYAML() { + import dyaml; // + <> + YAMLDocument configYAML(string configuration, string conf_yaml_filename) { + Node _yaml_conf; + try { + _yaml_conf = Loader.fromString(configuration).load() + } catch(ErrnoException e) { + stderr.writeln("Yaml problem with content for ", conf_yaml_filename); + stderr.writeln(e.msg); + } + return _yaml_conf; + } +} +#+END_SRC + +*** 3. YAML config (config_local_site & dr_document_make) :file:config:hub: + +#+name: meta_config_file_hub +#+BEGIN_SRC d +static template configReadSiteYAML() { + <> + import dyaml; + final YAMLDocument configReadSiteYAML(M,E)(M _manifest, E _env) { + string _configuration = configReadInSiteYAML!()(_manifest, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); + string _conf_yaml = _conf_file_details.config_filename_site; + YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml); + return _yaml_conf; + } +} +static template configReadDocYAML() { + <> + import yaml; + final YAMLDocument configReadDocYAML(M,E)(M _manifest, E _env) { + string _configuration = configReadInDocYAML!()(_manifest, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); + string _conf_yaml = _conf_file_details.config_filename_document; + YAMLDocument _yaml_conf = configYAML!()(_configuration, _conf_yaml); + return _yaml_conf; + } +} +#+END_SRC + *** 2. TOML config files get #+name: meta_config_file_toml @@ -245,9 +313,9 @@ static template configReadSiteTOML() { <> import toml; final TOMLDocument configReadSiteTOML(M,E)(M _manifest, E _env) { - string _configuration = configReadInSiteTOML!()(_manifest, _env); + string _configuration = configReadInSiteSTR!()(_manifest, _env); auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); - string _conf_toml = _conf_file_details.config_filename_site_toml; + string _conf_toml = _conf_file_details.config_filename_site; TOMLDocument _toml_conf = configTOML!()(_configuration, _conf_toml); return _toml_conf; } @@ -256,9 +324,9 @@ static template configReadDocTOML() { <> import toml; final TOMLDocument configReadDocTOML(M,E)(M _manifest, E _env) { - string _configuration = configReadInDocTOML!()(_manifest, _env); + string _configuration = configReadInDocSTR!()(_manifest, _env); auto _conf_file_details = ConfigFilePaths!()(_manifest, _env); - string _conf_toml = _conf_file_details.config_filename_document_toml; + string _conf_toml = _conf_file_details.config_filename_document; TOMLDocument _toml_conf = configTOML!()(_configuration, _conf_toml); return _toml_conf; } @@ -326,13 +394,20 @@ static template DocReformRawMarkupContent() { static assert(!isTypeTuple!(tu)); images_list = tu[2].dup; } + string header_type = ""; + if (header_raw.match(rgx.yaml_config)) { + header_type = "yaml"; + } else if (header_raw.match(rgx.toml_config)) { + header_type = "toml"; + } t = tuple( header_raw, sourcefile_body_content, + header_type, insert_file_list, images_list ); - static assert(t.length==4); + static assert(t.length==5); return t; } } @@ -470,13 +545,20 @@ auto markupSourceReadIn(in string fn_src) { auto markupSourceHeaderContentRawLineTupleArray(in string source_txt_str) { string[] file_insert_list = []; string[] images_list = []; - auto hc = header0Content1(source_txt_str); - auto header = hc[0]; + char[][] hc = header0Content1(source_txt_str); + char[] header = hc[0]; char[] source_txt = hc[1]; auto source_line_arr = markupSourceLineArray(source_txt); + string header_type = ""; + if (header.match(rgx.yaml_config)) { + header_type = "yaml"; + } else if (header.match(rgx.toml_config)) { + header_type = "toml"; + } auto t = tuple( header, source_line_arr, + header_type, file_insert_list, images_list ); -- cgit v1.2.3