From d61236952f19c1a1107a11cf11874104c0fe1a9b Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 14 Nov 2019 11:16:09 -0500 Subject: 0.8.3 (if exists) get site config & output path - read once & read early: - once per batch processing - early (needed by metadata --harvest) --- src/doc_reform/doc_reform.d | 45 +++++--- src/doc_reform/meta/conf_make_meta_json.d | 2 +- src/doc_reform/meta/conf_make_meta_structs.d | 5 - src/doc_reform/meta/conf_make_meta_yaml.d | 2 +- src/doc_reform/meta/metadoc.d | 13 +-- src/doc_reform/meta/metadoc_harvests_authors.d | 5 +- src/doc_reform/meta/metadoc_harvests_topics.d | 5 +- src/doc_reform/source/paths_source.d | 153 +++++++++++++++---------- src/doc_reform/source/read_config_files.d | 51 +++++---- src/doc_reform/source/read_source_files.d | 6 +- 10 files changed, 165 insertions(+), 122 deletions(-) (limited to 'src') diff --git a/src/doc_reform/doc_reform.d b/src/doc_reform/doc_reform.d index 369c91b..f5b2b86 100755 --- a/src/doc_reform/doc_reform.d +++ b/src/doc_reform/doc_reform.d @@ -532,20 +532,35 @@ void main(string[] args) { ]; auto _manifested = PathMatters!()(_opt_action, _env, ""); auto _manifests = [ _manifested ]; - ConfCompositePlus _make_and_meta_struct_tst; - foreach(arg; args[1..$]) { + ConfComposite _make_and_meta_struct; + if (_opt_action.config_path_set.empty) { + foreach(arg; args[1..$]) { + if (!(arg.match(rgx.flag_action))) { /+ cli markup source path +/ // get first input markup source file names for processing + _manifested = PathMatters!()(_opt_action, _env, arg); + { /+ local site config +/ + auto _config_local_site_struct = readConfigSite!()(_manifested, _env); + if (_config_local_site_struct.filetype == "yaml") { + import doc_reform.meta.conf_make_meta_yaml; + _make_and_meta_struct = _config_local_site_struct.configParseYAMLreturnDocReformStruct!()(_make_and_meta_struct, _manifested); // - get local site config + break; + } + } + } + } + } else { + { /+ local site config +/ + auto _config_local_site_struct = readConfigSite!()(_manifested, _env, _opt_action.config_path_set); + if (_config_local_site_struct.filetype == "yaml") { + import doc_reform.meta.conf_make_meta_yaml; + _make_and_meta_struct = _config_local_site_struct.configParseYAMLreturnDocReformStruct!()(_make_and_meta_struct, _manifested); // - get local site config + } + } + } + foreach(arg; args[1..$]) { // refigure how args relate to _opt_action, need path from _opt_action or args early _manifested too late, work on (search for PathMatters and .harvest, auto _manifest_start = PodManifest!()(arg); if (arg.match(rgx.flag_action)) { /+ cli instruction, flag do +/ flag_action ~= " " ~ arg; // flags not taken by getopt } else { /+ cli, assumed to be path to source files +/ - _manifested = PathMatters!()(_opt_action, _env, arg); // gather input markup source file names for processing - auto _config_local_site_struct = readConfigSite!()(_manifested, _env); - { /+ local site config +/ - if (_config_local_site_struct.filetype == "yaml") { - import doc_reform.meta.conf_make_meta_yaml; - _make_and_meta_struct_tst = _config_local_site_struct.configParseYAMLreturnDocReformStruct!()(_make_and_meta_struct_tst, _manifested); - } - } if ( /+ pod files +/ !(arg.match(rgx.src_pth_sst_or_ssm)) && _manifest_start.pod_manifest_file_with_path @@ -741,7 +756,7 @@ void main(string[] args) { ) { writeln("--->\nstepX commence → (document abstraction)"); } - auto t = DocReformAbstraction!()(_env, program_info, _opt_action, manifest); + auto t = DocReformAbstraction!()(_env, program_info, _opt_action, manifest, _make_and_meta_struct); static assert(!isTypeTuple!(t)); static assert(t.length==2); auto doc_abstraction = t[dAM.abstraction]; @@ -845,7 +860,7 @@ void main(string[] args) { ) { writeln("--->\nstepX commence → (document abstraction)"); } - auto t = DocReformAbstraction!()(_env, program_info, _opt_action, manifest); + auto t = DocReformAbstraction!()(_env, program_info, _opt_action, manifest, _make_and_meta_struct); static assert(!isTypeTuple!(t)); static assert(t.length==2); auto doc_abstraction = t[dAM.abstraction]; @@ -921,14 +936,14 @@ void main(string[] args) { } if (hvst.harvests.length > 0) { if (_opt_action.harvest_topics) { - DocReformMetaDocHarvestsTopics!()(hvst, _opt_action); + DocReformMetaDocHarvestsTopics!()(hvst, _make_and_meta_struct, _opt_action); } if (_opt_action.harvest_authors) { - DocReformMetaDocHarvestsAuthors!()(hvst.harvests, _opt_action); + DocReformMetaDocHarvestsAuthors!()(hvst.harvests, _make_and_meta_struct, _opt_action); } if (!(_opt_action.quiet)) { import doc_reform.output.paths_output; - auto out_pth = DocReformPathsHTML!()(_opt_action.output_dir_set, ""); + auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); if (_opt_action.harvest_authors) { writeln("- ", out_pth.harvest("authors.html")); } diff --git a/src/doc_reform/meta/conf_make_meta_json.d b/src/doc_reform/meta/conf_make_meta_json.d index 3d69a3c..4b3a29c 100644 --- a/src/doc_reform/meta/conf_make_meta_json.d +++ b/src/doc_reform/meta/conf_make_meta_json.d @@ -20,7 +20,7 @@ static template contentJSONtoDocReformStruct() { doc_reform.meta.conf_make_meta_json, doc_reform.meta.defaults, doc_reform.meta.rgx; - ConfCompositePlus _struct_composite; + ConfComposite _struct_composite; auto contentJSONtoDocReformStruct(C,J,M)(C _struct_composite, J _json, M _manifested, string _identifier) { mixin DocReformRgxInit; static auto rgx = Rgx(); diff --git a/src/doc_reform/meta/conf_make_meta_structs.d b/src/doc_reform/meta/conf_make_meta_structs.d index f56141f..6f6ba10 100644 --- a/src/doc_reform/meta/conf_make_meta_structs.d +++ b/src/doc_reform/meta/conf_make_meta_structs.d @@ -231,11 +231,6 @@ struct MetaComposite { string title_subtitle; } struct ConfComposite { - MetaComposite meta; - ConfCompositeMakeInit make; - ConfCompositeSiteLocal conf; -} -struct ConfCompositePlus { MetaComposite meta; ConfCompositeMakeInit make; ConfCompositeMakeStr make_str; diff --git a/src/doc_reform/meta/conf_make_meta_yaml.d b/src/doc_reform/meta/conf_make_meta_yaml.d index a9c4434..aa4d77d 100644 --- a/src/doc_reform/meta/conf_make_meta_yaml.d +++ b/src/doc_reform/meta/conf_make_meta_yaml.d @@ -20,7 +20,7 @@ static template contentYAMLtoDocReformStruct() { doc_reform.meta.conf_make_meta_structs, doc_reform.meta.defaults, doc_reform.meta.rgx; - ConfCompositePlus _struct_composite; + ConfComposite _struct_composite; auto contentYAMLtoDocReformStruct(C,Y,M)( C _struct_composite, Y _yaml, diff --git a/src/doc_reform/meta/metadoc.d b/src/doc_reform/meta/metadoc.d index 69f7142..4fb9677 100644 --- a/src/doc_reform/meta/metadoc.d +++ b/src/doc_reform/meta/metadoc.d @@ -30,13 +30,13 @@ template DocReformAbstraction() { enum makeMeta { make, meta } enum docAbst { doc_abstract_obj, doc_has } static auto rgx = Rgx(); - auto DocReformAbstraction(E,P,O,M)( + auto DocReformAbstraction(E,P,O,M,S)( E _env, P program_info, O _opt_action, - M _manifest + M _manifest, + S _make_and_meta_struct ){ - ConfCompositePlus _make_and_meta_struct; { /+ document config/make file +/ auto _config_document_struct = readConfigDoc!()(_manifest, _env); if (_config_document_struct.filetype == "yaml") { @@ -44,13 +44,6 @@ template DocReformAbstraction() { _make_and_meta_struct = _config_document_struct.configParseYAMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); } } - { /+ local site config +/ - auto _config_local_site_struct = readConfigSite!()(_manifest, _env); - if (_config_local_site_struct.filetype == "yaml") { - import doc_reform.meta.conf_make_meta_yaml; - _make_and_meta_struct = _config_local_site_struct.configParseYAMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); - } - } /+ ↓ read file (filename with path) +/ /+ ↓ file tuple of header and content +/ if ((_opt_action.debug_do) diff --git a/src/doc_reform/meta/metadoc_harvests_authors.d b/src/doc_reform/meta/metadoc_harvests_authors.d index 29fcc72..23707af 100644 --- a/src/doc_reform/meta/metadoc_harvests_authors.d +++ b/src/doc_reform/meta/metadoc_harvests_authors.d @@ -15,8 +15,9 @@ module doc_reform.meta.metadoc_harvests_authors; mixin DocReformRgxInit; template DocReformMetaDocHarvestsAuthors() { auto mkup = InlineMarkup(); - void DocReformMetaDocHarvestsAuthors(H,O)( + void DocReformMetaDocHarvestsAuthors(H,M,O)( H harvests, + M _make_and_meta_struct, O _opt_action, ) { string theme_dark_0 = format(q"┃ @@ -347,7 +348,7 @@ string theme_light_1 = format(q"┃ ┃") ~ "\n"; import doc_reform.output.paths_output; - auto out_pth = DocReformPathsHTML!()(_opt_action.output_dir_set, ""); + auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); try { auto f = File(out_pth.harvest("authors.html"), "w"); foreach (o; authors) { diff --git a/src/doc_reform/meta/metadoc_harvests_topics.d b/src/doc_reform/meta/metadoc_harvests_topics.d index 63e4a79..f8e6514 100644 --- a/src/doc_reform/meta/metadoc_harvests_topics.d +++ b/src/doc_reform/meta/metadoc_harvests_topics.d @@ -15,8 +15,9 @@ module doc_reform.meta.metadoc_harvests_topics; mixin DocReformRgxInit; template DocReformMetaDocHarvestsTopics() { auto mkup = InlineMarkup(); - void DocReformMetaDocHarvestsTopics(H,O)( + void DocReformMetaDocHarvestsTopics(H,M,O)( H hvst, + M _make_and_meta_struct, O _opt_action, ) { auto min_repeat_number = 42; @@ -506,7 +507,7 @@ string theme_light_1 = format(q"┃ ┃") ~ "\n"; import doc_reform.output.paths_output; - auto out_pth = DocReformPathsHTML!()(_opt_action.output_dir_set, ""); + auto out_pth = DocReformPathsHTML!()(_make_and_meta_struct.conf.output_path, ""); try { auto f = File(out_pth.harvest("topics.html"), "w"); foreach (o; topics) { diff --git a/src/doc_reform/source/paths_source.d b/src/doc_reform/source/paths_source.d index f291fb5..e0b844a 100644 --- a/src/doc_reform/source/paths_source.d +++ b/src/doc_reform/source/paths_source.d @@ -163,6 +163,9 @@ template PathMatters() { string pod_name_with_path() { return (is_pod) ? _manifested.pod_manifest_path : ""; } + string pods_collection_root_path() { + return (is_pod) ? _manifested.pods_collection_root_path : ""; + } string pod_name() { return pod_name_with_path.baseName; } @@ -247,6 +250,9 @@ template PathMatters() { string absolute_path_to_src() { return (_env["pwd"].chainPath(path_and_fn)).dirName.array; } + string path_to_doc_root_path_to_lang_and_filename() { + return _env["pwd"].chainPath(path_and_fn).array; + } string base_dir() { string _dir; if ( @@ -359,7 +365,17 @@ template PathMatters() { return SRC_(); } auto output() { - auto _opt_actions = _opt_actions; + /+ + - command line if output path set + - config file if found and set set + - search for and if exists read config + - default paths to config related to: + - source markup path; + - current dir; + - home dir + - get output path if set + - (program) default within current directory? + +/ auto _env = _env; struct Out_ { auto path() { @@ -393,8 +409,9 @@ template ConfigFilePaths() { mixin DocReformRgxInit; static auto rgx = Rgx(); auto ConfigFilePaths(M,E)( - M _manifested, - E _env, + M _manifested, + E _env, + string _cli_config_path_set = "" ) { struct ConfFilePaths { string config_filename_document() { @@ -410,37 +427,43 @@ template ConfigFilePaths() { /+ config local site (file system only, not in pod) +/ /+ return paths +/ string[] _possible_config_path_locations; - if (_manifested.src.is_pod) { - /+ config document in pod +/ - string _dr_doc_conf_pod; - string _dr_doc_conf_pod_text; - _dr_doc_conf_pod = asNormalizedPath(chainPath( - to!string(_env["pwd"]), - _manifested.pod.manifest_path ~ "/conf" - )).array; - _dr_doc_conf_pod_text = asNormalizedPath(chainPath( - to!string(_env["pwd"]), - _manifested.pod.manifest_path ~ "/media/text/" ~ _manifested.src.lng ~ "/conf" - )).array; - /+ return paths +/ - _possible_config_path_locations = [ - _dr_doc_conf_pod_text, - _dr_doc_conf_pod, - ]; + if (_cli_config_path_set.empty) { + if (_manifested.src.is_pod) { + /+ config document in pod +/ + string _dr_doc_conf_pod; + string _dr_doc_conf_pod_text; + _dr_doc_conf_pod = asNormalizedPath(chainPath( + to!string(_env["pwd"]), + _manifested.pod.manifest_path ~ "/conf" + )).array; + _dr_doc_conf_pod_text = asNormalizedPath(chainPath( + to!string(_env["pwd"]), + _manifested.pod.manifest_path ~ "/media/text/" ~ _manifested.src.lng ~ "/conf" + )).array; + /+ return paths +/ + _possible_config_path_locations = [ + _dr_doc_conf_pod_text, + _dr_doc_conf_pod, + ]; + } else { + /+ config document (& or local site) on filesystem +/ + string _dr_doc_conf_pwd = ((chainPath(to!string(_env["pwd"]), "dr_doc/conf")).asNormalizedPath).array; // think about + string _dr_doc_conf_pwd_a = ((chainPath(to!string(_env["pwd"]), "conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_b = ((chainPath(to!string(_env["pwd"]), "../conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_c = ((chainPath(to!string(_env["pwd"]), "../../conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_d = ((chainPath(to!string(_env["pwd"]), "../../../conf")).asNormalizedPath).array; + /+ return paths +/ + _possible_config_path_locations = [ + _dr_doc_conf_pwd, + _dr_doc_conf_pwd_a, + _dr_doc_conf_pwd_b, + _dr_doc_conf_pwd_c, + _dr_doc_conf_pwd_d, + ]; + } } else { - /+ config document (& or local site) on filesystem +/ - string _dr_doc_conf_pwd = ((chainPath(to!string(_env["pwd"]), "dr_doc/conf")).asNormalizedPath).array; // think about - string _dr_doc_conf_pwd_a = ((chainPath(to!string(_env["pwd"]), "conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_b = ((chainPath(to!string(_env["pwd"]), "../conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_c = ((chainPath(to!string(_env["pwd"]), "../../conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_d = ((chainPath(to!string(_env["pwd"]), "../../../conf")).asNormalizedPath).array; - /+ return paths +/ _possible_config_path_locations = [ - _dr_doc_conf_pwd, - _dr_doc_conf_pwd_a, - _dr_doc_conf_pwd_b, - _dr_doc_conf_pwd_c, - _dr_doc_conf_pwd_d, + _cli_config_path_set ]; } /+ FIX clean up conf paths ↑ @@ -451,39 +474,45 @@ template ConfigFilePaths() { string[] config_local_site() { /+ FIX clean up conf paths ↓ +/ /+ config local site (file system only, not in pod) +/ - string _dot_pwd = ((chainPath(to!string(_env["pwd"]), ".dr")).asNormalizedPath).array; - string _underscore_pwd = ((chainPath(to!string(_env["pwd"]), "_dr")).asNormalizedPath).array; - string _dot_home = ((chainPath(to!string(_env["home"]), ".dr")).asNormalizedPath).array; - /+ return paths +/ string[] _possible_config_path_locations; - if (_manifested.src.is_pod) { - string _collection_root_a = ((chainPath(to!string(_manifested.pod.collection_root.to!string), ".dr")).asNormalizedPath).array; - string _collection_root_b = ((chainPath(to!string(_manifested.pod.collection_root.to!string), "_dr")).asNormalizedPath).array; - _possible_config_path_locations = [ - _dot_pwd, - _underscore_pwd, - _dot_home, - "/etc/dr", - _collection_root_a, // set priority higher? - _collection_root_b // set priority higher? - ]; + if (_cli_config_path_set.empty) { + string _dot_pwd = ((chainPath(to!string(_env["pwd"]), ".dr")).asNormalizedPath).array; + string _underscore_pwd = ((chainPath(to!string(_env["pwd"]), "_dr")).asNormalizedPath).array; + string _dot_home = ((chainPath(to!string(_env["home"]), ".dr")).asNormalizedPath).array; + /+ return paths +/ + if (_manifested.src.is_pod) { + string _collection_root_a = ((chainPath(to!string(_manifested.pod.collection_root.to!string), ".dr")).asNormalizedPath).array; + string _collection_root_b = ((chainPath(to!string(_manifested.pod.collection_root.to!string), "_dr")).asNormalizedPath).array; + _possible_config_path_locations = [ + _dot_pwd, + _underscore_pwd, + _dot_home, + "/etc/dr", + _collection_root_a, // set priority higher? + _collection_root_b // set priority higher? + ]; + } else { + /+ config document (& or local site) on filesystem +/ + string _dr_doc_conf_pwd = ((chainPath(to!string(_env["pwd"]), "dr_doc/conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_a = ((chainPath(to!string(_env["pwd"]), "conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_b = ((chainPath(to!string(_env["pwd"]), "../conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_c = ((chainPath(to!string(_env["pwd"]), "../../conf")).asNormalizedPath).array; + string _dr_doc_conf_pwd_d = ((chainPath(to!string(_env["pwd"]), "../../../conf")).asNormalizedPath).array; + _possible_config_path_locations = [ + _dr_doc_conf_pwd, + _dr_doc_conf_pwd_a, + _dr_doc_conf_pwd_b, + _dr_doc_conf_pwd_c, + _dr_doc_conf_pwd_d, + _dot_pwd, + _underscore_pwd, + _dot_home, + "/etc/dr" + ]; + } } else { - /+ config document (& or local site) on filesystem +/ - string _dr_doc_conf_pwd = ((chainPath(to!string(_env["pwd"]), "dr_doc/conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_a = ((chainPath(to!string(_env["pwd"]), "conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_b = ((chainPath(to!string(_env["pwd"]), "../conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_c = ((chainPath(to!string(_env["pwd"]), "../../conf")).asNormalizedPath).array; - string _dr_doc_conf_pwd_d = ((chainPath(to!string(_env["pwd"]), "../../../conf")).asNormalizedPath).array; _possible_config_path_locations = [ - _dr_doc_conf_pwd, - _dr_doc_conf_pwd_a, - _dr_doc_conf_pwd_b, - _dr_doc_conf_pwd_c, - _dr_doc_conf_pwd_d, - _dot_pwd, - _underscore_pwd, - _dot_home, - "/etc/dr" + _cli_config_path_set ]; } /+ FIX clean up conf paths ↑ diff --git a/src/doc_reform/source/read_config_files.d b/src/doc_reform/source/read_config_files.d index 4827fff..2b3e4fb 100644 --- a/src/doc_reform/source/read_config_files.d +++ b/src/doc_reform/source/read_config_files.d @@ -14,30 +14,42 @@ static template readConfigSite() { std.file, std.path; mixin DocReformRgxInit; - final auto readConfigSite(M,E)(M _manifested, E _env) { + final auto readConfigSite(M,E)( + M _manifested, + E _env, + string _cli_config_path_set = "" + ) { static auto rgx = Rgx(); string config_file_str; string conf_filename = "NONE"; - auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); + auto _conf_file_details = ConfigFilePaths!()(_manifested, _env, _cli_config_path_set); string[] possible_config_path_locations = _conf_file_details.possible_config_path_locations.config_local_site; foreach(conf_fn; [_conf_file_details.config_filename_site]) { foreach(pth; possible_config_path_locations) { - char[] conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; + char[] conf_file; 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); + if (exists(pth)) { + auto f_attrib = pth.getLinkAttributes; + if ( + possible_config_path_locations.length == 1 + && f_attrib.attrIsFile + ) { + conf_file = pth.to!(char[]); + conf_filename = pth.baseName; + } else if (f_attrib.attrIsDir) { + conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).array; + conf_filename = conf_fn; + } + try { + if (exists(conf_file)) { + if (conf_file.getLinkAttributes.attrIsFile) { + config_file_str = conf_file.readText; + break; + } } - config_file_str = conf_file.readText; - break; + } catch (ErrnoException ex) { + } catch (FileException ex) { } - } catch (ErrnoException ex) { - } catch (FileException ex) { } } if (config_file_str.length > 0) { break; } @@ -80,16 +92,14 @@ static template readConfigDoc() { auto conf_file = ((chainPath(pth.to!string, conf_fn)).asNormalizedPath).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); + if (conf_file.getLinkAttributes.attrIsFile) { + config_file_str = conf_file.readText; + break; } - config_file_str = conf_file.readText; - break; } } catch (ErrnoException ex) { } catch (FileException ex) { @@ -121,7 +131,6 @@ static template configReadSiteYAML() { doc_reform.source.paths_source, std.file, std.path; - import dyaml; final YAMLDocument configReadSiteYAML(M,E)(M _manifested, E _env) { string _configuration = configReadInSiteYAML!()(_manifested, _env); auto _conf_file_details = ConfigFilePaths!()(_manifested, _env); diff --git a/src/doc_reform/source/read_source_files.d b/src/doc_reform/source/read_source_files.d index 05f6630..f4de5fe 100644 --- a/src/doc_reform/source/read_source_files.d +++ b/src/doc_reform/source/read_source_files.d @@ -85,10 +85,10 @@ static template DocReformRawMarkupContent() { string source_txt_str; try { if (exists(fn_src)) { - debug(io) { - writeln("in src, markup source file found: ", fn_src); + if (fn_src.getLinkAttributes.attrIsFile) { + source_txt_str = fn_src.readText; + } else { } - source_txt_str = fn_src.readText; } } catch (ErrnoException ex) { } catch (UTFException ex) { -- cgit v1.2.3