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 --- src/doc_reform/doc_reform.d | 36 +- src/doc_reform/meta/conf_make_meta_structs.d | 90 --- src/doc_reform/meta/conf_make_meta_toml.d | 14 +- src/doc_reform/meta/conf_make_meta_yaml.d | 818 +++++++++++++++++++++++++++ src/doc_reform/meta/metadoc.d | 49 +- src/doc_reform/meta/rgx.d | 9 +- src/doc_reform/source/paths_source.d | 4 +- src/doc_reform/source/read_config_files.d | 84 ++- src/doc_reform/source/read_source_files.d | 20 +- 9 files changed, 971 insertions(+), 153 deletions(-) create mode 100644 src/doc_reform/meta/conf_make_meta_yaml.d (limited to 'src') diff --git a/src/doc_reform/doc_reform.d b/src/doc_reform/doc_reform.d index 6275963..58c55c8 100755 --- a/src/doc_reform/doc_reform.d +++ b/src/doc_reform/doc_reform.d @@ -65,10 +65,8 @@ import doc_reform.meta.metadoc_harvest, doc_reform.meta.metadoc_harvests_authors, doc_reform.meta.metadoc_harvests_topics, - doc_reform.meta.metadoc_summary, doc_reform.meta.metadoc_from_src, doc_reform.meta.conf_make_meta_structs, - doc_reform.meta.conf_make_meta_toml, doc_reform.meta.conf_make_meta_json, doc_reform.meta.defaults, doc_reform.meta.doc_debugs, @@ -577,8 +575,8 @@ void main(string[] args) { && _manifest_start.pod_manifest_file_with_path && _opt_action.abstraction ) { - string contents_location_raw_; - string contents_location_; + string pod_manifest_root_content_paths_to_markup_location_raw_; + string markup_contents_location_; string sisudoc_txt_ = _manifest_start.pod_manifest_file_with_path; enforce( exists(sisudoc_txt_)!=0, @@ -588,39 +586,39 @@ void main(string[] args) { if (exists(sisudoc_txt_)) { try { if (exists(sisudoc_txt_)) { - contents_location_raw_ = sisudoc_txt_.readText; + pod_manifest_root_content_paths_to_markup_location_raw_ = sisudoc_txt_.readText; } } catch (ErrnoException ex) { } catch (FileException ex) { // Handle errors } - if (contents_location_raw_.match(rgx.pod_content_location)) { // (file name followed by language codes \n)+ - foreach (m; contents_location_raw_.matchAll(rgx.pod_content_location)) { + if (pod_manifest_root_content_paths_to_markup_location_raw_.match(rgx.pod_content_location)) { // (file name followed by language codes \n)+ + foreach (m; pod_manifest_root_content_paths_to_markup_location_raw_.matchAll(rgx.pod_content_location)) { foreach (n; m.captures[2].matchAll(rgx.language_codes)) { - contents_location_ ~= "media/text/" ~ n.captures[1].to!string ~ "/" ~ m.captures[1].to!string ~ "\n"; + markup_contents_location_ ~= "media/text/" ~ n.captures[1].to!string ~ "/" ~ m.captures[1].to!string ~ "\n"; } } - } else { - contents_location_ = contents_location_raw_; + } else { // (file name with path \n)+ + markup_contents_location_ = pod_manifest_root_content_paths_to_markup_location_raw_; } } else { writeln("manifest not found: ", sisudoc_txt_); } - auto contents_locations_arr - = (cast(char[]) contents_location_).split; + auto markup_contents_locations_arr + = (cast(char[]) markup_contents_location_).split; auto tmp_dir_ = (sisudoc_txt_).dirName.array; - foreach (contents_location; contents_locations_arr) { - assert(contents_location.match(rgx.src_pth_sst_or_ssm), + foreach (markup_contents_location; markup_contents_locations_arr) { + assert(markup_contents_location.match(rgx.src_pth_sst_or_ssm), "not a recognised file: «" ~ - contents_location ~ "»" + markup_contents_location ~ "»" ); - auto contents_location_pth_ = (contents_location).to!string; + auto markup_contents_location_pth_ = (markup_contents_location).to!string; Regex!(char) lang_rgx_ = regex(r"/(" ~ _opt_action.languages_set.join("|") ~ ")/"); if (_opt_action.languages_set[0] == "all" - || (contents_location_pth_).match(lang_rgx_) + || (markup_contents_location_pth_).match(lang_rgx_) ) { - auto _fns = (((tmp_dir_).chainPath(contents_location_pth_)).array).to!string; - _manifest_matter = PathMatters!()(_opt_action, _env, arg, _fns, contents_locations_arr); + auto _fns = (((tmp_dir_).chainPath(markup_contents_location_pth_)).array).to!string; + _manifest_matter = PathMatters!()(_opt_action, _env, arg, _fns, markup_contents_locations_arr); _manifests ~= _manifest_matter; } } diff --git a/src/doc_reform/meta/conf_make_meta_structs.d b/src/doc_reform/meta/conf_make_meta_structs.d index 6c230df..4dba388 100644 --- a/src/doc_reform/meta/conf_make_meta_structs.d +++ b/src/doc_reform/meta/conf_make_meta_structs.d @@ -239,95 +239,5 @@ struct ConfCompositePlus { ConfCompositeMakeStr make_str; ConfCompositeSiteLocal conf; } -static string[] ptr_head_main - = [ - "classify", - "creator", - "date", - "identifier", - "links", - "make", - "original", - "notes", - "rights", - "title" - ]; -static string[] ptr_head_sub_classify - = [ - "dewey", - "keywords", - "loc", - "subject", - "topic_register" - ]; -static string[] ptr_head_sub_creator - = [ - "author", - "author_email", - "cover", - "illustrator", - "translator" - ]; -static string[] ptr_head_sub_date - = [ - "added_to_site", - "available", - "created", - "issued", - "modified", - "published", - "valid" - ]; -static string[] ptr_head_sub_identifier - = [ - "isbn", - "oclc", - "pg" - ]; -/+ make +/ -static string[] ptr_head_sub_make - = [ - "cover_image", - "home_button_image", - "home_button_text", - "footer", "headings", - "auto_num_top_at_level", "auto_num_top_lv", "auto_num_depth", - "breaks", - "substitute", - "bold", - "italics", - "emphasis", - "texpdf_font", - "css" - ]; -static string[] ptr_head_sub_notes - = [ - "abstract", - "description" - ]; -static string[] ptr_head_sub_original - = [ - "language", - "source", - "title" - ]; -static string[] ptr_head_sub_publisher - = [ "name" ]; -static string[] ptr_head_sub_rights - = [ - "copyright", - "cover", - "illustrations", - "license" - ]; -static string[] ptr_head_sub_title - = [ - "edition", - "full", - "language", - "main", - "note", - "sub" - ]; JSONValue config_jsonstr = `{ }`; diff --git a/src/doc_reform/meta/conf_make_meta_toml.d b/src/doc_reform/meta/conf_make_meta_toml.d index 6008996..0df63d3 100644 --- a/src/doc_reform/meta/conf_make_meta_toml.d +++ b/src/doc_reform/meta/conf_make_meta_toml.d @@ -2,9 +2,9 @@ extract native/orig header return associative array
the header is passed as text (lopped off top of a sisu markup file until the - required first heading ^A~), determine whether is a native header or sdlang one - with a regex check if whether it contains the "native header" required tag/field - @title: then process accordingly as a "native header" or "sdlang header" + required first heading ^A~), determine whether is a yaml header or toml one + with a regex check if whether it contains the "yaml header" required tag/field + title: then process accordingly as a "yaml header" or "toml header" converting the metadata and make instructions to a common json format used by program internally. Moved to associative array. +/ @@ -62,18 +62,18 @@ static template docHeaderMakeAndMetaTupTomlExtractAndConvertToStruct() { mixin contentJSONtoDocReformStruct; static auto rgx = Rgx(); auto docHeaderMakeAndMetaTupTomlExtractAndConvertToStruct(CCm,Src,M)( - CCm _make_and_meta_struct, Src header_src, + CCm _make_and_meta_struct, M _manifest, ) { - TOMLDocument _doc; + TOMLDocument _doc_toml; if (header_src.match(rgx.toml_header_meta_title)) { debug (json) { writeln(">>> document header is toml, convert to JSON"); } - _doc = parseTOML(cast(string)(header_src)); + _doc_toml = parseTOML(cast(string)(header_src)); } - auto _doc_json = _doc.toJSON; + auto _doc_json = _doc_toml.toJSON; auto _header_and_make_and_meta_struct = contentJSONtoDocReformStruct!()(_make_and_meta_struct, _doc_json, _manifest, "header"); return _header_and_make_and_meta_struct; diff --git a/src/doc_reform/meta/conf_make_meta_yaml.d b/src/doc_reform/meta/conf_make_meta_yaml.d new file mode 100644 index 0000000..bb072a9 --- /dev/null +++ b/src/doc_reform/meta/conf_make_meta_yaml.d @@ -0,0 +1,818 @@ +/++ + yaml headers
+ extract yaml header return struct ++/ +module doc_reform.meta.conf_make_meta_yaml; +static template contentYAMLtoDocReformStruct() { + import + std.algorithm, + std.array, + std.exception, + std.regex, + std.stdio, + std.string, + std.traits, + std.typecons, + std.utf, + std.conv : to; + import + doc_reform.meta.conf_make_meta_structs, + doc_reform.meta.defaults, + doc_reform.meta.rgx; + ConfCompositePlus _struct_composite; + auto contentYAMLtoDocReformStruct(C,Y,M)( + C _struct_composite, + Y _yaml, + M _manifest, + string _identifier + ) { + mixin DocReformRgxInit; + static auto rgx = Rgx(); + debug (yaml) { + writeln(">> --------------------------- >>"); + } + confCompositeMakeBuild _mk; + /+ make ------------------------------------------------------------------- +/ + if ("make" in _yaml + && _yaml["make"].type.sequence + ) { + if (_yaml["make"].type.mapping + && _yaml["make"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("bold" in _yaml["make"] + && _yaml["make"]["bold"].type.string + && _yaml["make"]["bold"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.bold = _yaml["make"]["bold"].get!string; + } + if ("breaks" in _yaml["make"] + && _yaml["make"]["breaks"].type.string + && _yaml["make"]["breaks"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.breaks = _yaml["make"]["breaks"].get!string; + } + if ("cover_image" in _yaml["make"] + && _yaml["make"]["cover_image"].type.string + && _yaml["make"]["cover_image"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.cover_image = _yaml["make"]["cover_image"].get!string; + } + if ("css" in _yaml["make"] + && _yaml["make"]["css"].type.string + && _yaml["make"]["css"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.css = _yaml["make"]["css"].get!string; + } + if ("emphasis" in _yaml["make"] + && _yaml["make"]["emphasis"].type.string + && _yaml["make"]["emphasis"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.emphasis = _yaml["make"]["emphasis"].get!string; + } + if ("footer" in _yaml["make"] + && _yaml["make"]["footer"].type.string + && _yaml["make"]["footer"].tag.match(rgx.yaml_tag_is_str) + ) { + char[][] __match_footer_array + = (cast(char[]) _yaml["make"]["footer"].get!string) + .split(rgx.make_heading_delimiter); + _struct_composite.make_str.footer = __match_footer_array.to!(string[]); + } + if ("headings" in _yaml["make"] + && _yaml["make"]["headings"].type.string + && _yaml["make"]["headings"].tag.match(rgx.yaml_tag_is_str) + ) { + char[][] __match_headings_array + = (cast(char[]) _yaml["make"]["headings"].get!string) + .split(rgx.make_heading_delimiter); + _struct_composite.make_str.headings = __match_headings_array.to!(string[]); + } else if ("headings" in _yaml["make"] + && _yaml["make"]["headings"].type.string + && _yaml["make"]["headings"].tag.match(rgx.yaml_tag_is_seq) + ) { + foreach(string identify_heading_level; _yaml["make"]["headings"]) { + _struct_composite.make_str.headings ~= identify_heading_level; + } + } + if ("home_button_image" in _yaml["make"] + && _yaml["make"]["home_button_image"].type.string + && _yaml["make"]["home_button_image"].tag.match(rgx.yaml_tag_is_str) + ) { + char[][] __match_home_button_image_array + = (cast(char[]) _yaml["make"]["home_button_image"].get!string) + .split(rgx.make_heading_delimiter); + _struct_composite.make_str.home_button_image = __match_home_button_image_array.to!(string[]); + } + if ("home_button_text" in _yaml["make"] + && _yaml["make"]["home_button_text"].type.string + && _yaml["make"]["home_button_text"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.home_button_text = _yaml["make"]["home_button_text"].get!string; + } + if ("italics" in _yaml["make"] + && _yaml["make"]["italics"].type.string + && _yaml["make"]["italics"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.italics = _yaml["make"]["italics"].get!string; + } + if ("auto_num_top_at_level" in _yaml["make"] + && _yaml["make"]["auto_num_top_at_level"].type.string + && _yaml["make"]["auto_num_top_at_level"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.make_str.auto_num_top_at_level = _yaml["make"]["auto_num_top_at_level"].get!string; + switch (_yaml["make"]["auto_num_top_at_level"].get!string) { + case "A": + break; + case "B": _struct_composite.make_str.auto_num_top_lv = 1; + break; + case "C": _struct_composite.make_str.auto_num_top_lv = 2; + break; + case "D": _struct_composite.make_str.auto_num_top_lv = 3; + break; + case "1": _struct_composite.make_str.auto_num_top_lv = 4; + break; + case "2": _struct_composite.make_str.auto_num_top_lv = 5; + break; + case "3": _struct_composite.make_str.auto_num_top_lv = 6; + break; + case "4": _struct_composite.make_str.auto_num_top_lv = 7; + break; + default: + break; + } + } + if ("auto_num_depth" in _yaml["make"] + && _yaml["make"]["auto_num_depth"].type.string + && _yaml["make"]["auto_num_depth"].tag.match(rgx.yaml_tag_is_int) + ) { // not sure implemented for documents + _struct_composite.make_str.auto_num_depth = _yaml["make"]["auto_num_depth"].get!int; + } else if ("auto_num_depth" in _yaml["make"] + && _yaml["make"]["auto_num_depth"].type.string + && _yaml["make"]["auto_num_depth"].tag.match(rgx.yaml_tag_is_str) + ) { // not sure implemented for documents + _struct_composite.make_str.auto_num_depth = _yaml["make"]["auto_num_depth"].get!int; + } + if ("texpdf_font" in _yaml["make"] + && _yaml["make"]["texpdf_font"].type.string + ) { + _struct_composite.make_str.texpdf_font = _yaml["make"]["texpdf_font"].get!string; + } + } + _struct_composite.make.bold = _mk.bold(_struct_composite.make_str.bold); + _struct_composite.make.breaks = _mk.breaks(_struct_composite.make_str.breaks); + _struct_composite.make.cover_image = _mk.cover_image(_struct_composite.make_str.cover_image); + _struct_composite.make.css = _mk.css(_struct_composite.make_str.css); + _struct_composite.make.emphasis = _mk.emphasis(_struct_composite.make_str.emphasis); + _struct_composite.make.footer = _mk.footer(_struct_composite.make_str.footer); + _struct_composite.make.headings = _mk.headings(_struct_composite.make_str.headings); + _struct_composite.make.home_button_image = _mk.home_button_image(_struct_composite.make_str.home_button_image); + _struct_composite.make.home_button_text = _mk.home_button_text(_struct_composite.make_str.home_button_text); + _struct_composite.make.italics = _mk.italics(_struct_composite.make_str.italics); + _struct_composite.make.auto_num_top_at_level = _mk.auto_num_top_at_level(_struct_composite.make_str.auto_num_top_at_level); + _struct_composite.make.auto_num_top_lv = _mk.auto_num_top_lv(_struct_composite.make_str.auto_num_top_lv); + _struct_composite.make.auto_num_depth = _mk.auto_num_depth(_struct_composite.make_str.auto_num_depth); + _struct_composite.make.substitute = _mk.substitute(_struct_composite.make_str.substitute); + _struct_composite.make.texpdf_font = _mk.texpdf_font(_struct_composite.make_str.texpdf_font); + } + + /+ conf ------------------------------------------------------------------- +/ + if ("webserv" in _yaml + && _yaml["webserv"].type.sequence + ) { + if (_yaml["webserv"].type.mapping + && _yaml["webserv"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("url_root" in _yaml["webserv"] + && _yaml["webserv"]["url_root"].type.string + && _yaml["webserv"]["url_root"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_url_doc_root = _yaml["webserv"]["url_root"].get!string; + if (auto m = _struct_composite.conf.webserv_url_doc_root.match(rgx.webserv_url_doc_root)) { + _struct_composite.conf.webserv_url_domain = m.captures[2].to!string; + _struct_composite.conf.webserv_url_doc_path = m.captures[3].to!string; + } + } + if ("images" in _yaml["webserv"] + && _yaml["webserv"]["images"].type.string + && _yaml["webserv"]["images"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_images = _yaml["webserv"]["images"].get!string; + } + if ("cgi" in _yaml["webserv"] + && _yaml["webserv"]["cgi"].type.string + && _yaml["webserv"]["cgi"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_cgi = _yaml["webserv"]["cgi"].get!string; + } + if ("cgi_host" in _yaml["webserv"] + && _yaml["webserv"]["cgi_host"].type.string + && _yaml["webserv"]["cgi_host"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_cgi_host = _yaml["webserv"]["cgi_host"].get!string; + } + if ("cgi_host_path" in _yaml["webserv"] + && _yaml["webserv"]["cgi_host_path"].type.string + && _yaml["webserv"]["cgi_host_path"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_cgi_host_path = _yaml["webserv"]["cgi_host_path"].get!string; + } + if ("cgi_port" in _yaml["webserv"] + && _yaml["webserv"]["cgi_port"].type.string + && _yaml["webserv"]["cgi_port"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_cgi_port = _yaml["webserv"]["cgi_port"].get!string; + } + if ("cgi_user" in _yaml["webserv"] + && _yaml["webserv"]["cgi_user"].type.string + && _yaml["webserv"]["cgi_user"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_cgi_user = _yaml["webserv"]["cgi_user"].get!string; + } + if ("cgi_file_links" in _yaml["webserv"] + && _yaml["webserv"]["cgi_file_links"].type.string + && _yaml["webserv"]["cgi_file_links"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.webserv_cgi_file_links = _yaml["webserv"]["cgi_file_links"].get!string; + } + } + } + if ("processing" in _yaml + && _yaml["processing"].type.sequence + ) { + if (_yaml["processing"].type.mapping + && _yaml["processing"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("path" in _yaml["processing"] + && _yaml["processing"]["path"].type.string + && _yaml["processing"]["path"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.processing_path = _yaml["processing"]["path"].get!string; + } + if ("dir" in _yaml["processing"] + && _yaml["processing"]["dir"].type.string + && _yaml["processing"]["dir"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.processing_dir = _yaml["processing"]["dir"].get!string; + } + if ("concord_max" in _yaml["processing"] + && _yaml["processing"]["concord_max"].type.string + && _yaml["processing"]["concord_max"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.processing_concord_max = _yaml["processing"]["concord_max"].get!string; + } + } + } + if ("flag" in _yaml + && _yaml["flag"].type.sequence + ) { + if (_yaml["flag"].type.mapping + && _yaml["flag"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("act1" in _yaml["flag"] + && _yaml["flag"]["act1"].type.string + && _yaml["flag"]["act1"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act1 = _yaml["flag"]["act1"].get!string; + } + if ("act0" in _yaml["flag"] + && _yaml["flag"]["act0"].type.string + && _yaml["flag"]["act0"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act0 = _yaml["flag"]["act0"].get!string; + } + if ("act2" in _yaml["flag"] + && _yaml["flag"]["act2"].type.string + && _yaml["flag"]["act2"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act2 = _yaml["flag"]["act2"].get!string; + } + if ("act3" in _yaml["flag"] + && _yaml["flag"]["act3"].type.string + && _yaml["flag"]["act3"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act3 = _yaml["flag"]["act3"].get!string; + } + if ("act4" in _yaml["flag"] + && _yaml["flag"]["act4"].type.string + && _yaml["flag"]["act4"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act4 = _yaml["flag"]["act4"].get!string; + } + if ("act5" in _yaml["flag"] + && _yaml["flag"]["act5"].type.string + && _yaml["flag"]["act5"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act5 = _yaml["flag"]["act5"].get!string; + } + if ("act6" in _yaml["flag"] + && _yaml["flag"]["act6"].type.string + && _yaml["flag"]["act6"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act6 = _yaml["flag"]["act6"].get!string; + } + if ("act7" in _yaml["flag"] + && _yaml["flag"]["act7"].type.string + && _yaml["flag"]["act7"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act7 = _yaml["flag"]["act7"].get!string; + } + if ("act8" in _yaml["flag"] + && _yaml["flag"]["act8"].type.string + && _yaml["flag"]["act8"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act8 = _yaml["flag"]["act8"].get!string; + } + if ("act9" in _yaml["flag"] + && _yaml["flag"]["act9"].type.string + && _yaml["flag"]["act9"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.flag_act9 = _yaml["flag"]["act9"].get!string; + } + } + } + if ("default" in _yaml + && _yaml["default"].type.sequence + ) { + if (_yaml["default"].type.mapping + && _yaml["default"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("papersize" in _yaml["default"] + && _yaml["default"]["papersize"].type.string + && _yaml["default"]["papersize"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.default_papersize = _yaml["default"]["papersize"].get!string; + } + if ("text_wrap" in _yaml["default"] + && _yaml["default"]["text_wrap"].type.string + && _yaml["default"]["text_wrap"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.default_text_wrap = _yaml["default"]["text_wrap"].get!string; + } + if ("emphasis" in _yaml["default"] + && _yaml["default"]["emphasis"].type.string + && _yaml["default"]["emphasis"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.default_emphasis = _yaml["default"]["emphasis"].get!string; + } + if ("language" in _yaml["default"] + && _yaml["default"]["language"].type.string + && _yaml["default"]["language"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.default_language = _yaml["default"]["language"].get!string; + } + if ("digest" in _yaml["default"] + && _yaml["default"]["digest"].type.string + && _yaml["default"]["digest"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.default_digest = _yaml["default"]["digest"].get!string; + } + } + } + if ("search" in _yaml + && _yaml["search"].type.sequence + ) { + if (_yaml["search"].type.mapping + && _yaml["search"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("flag" in _yaml["search"] + && _yaml["search"]["flag"].type.string + && _yaml["search"]["flag"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.search_flag = _yaml["search"]["flag"].get!string; + } + if ("action" in _yaml["search"] + && _yaml["search"]["action"].type.string + && _yaml["search"]["action"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.search_action = _yaml["search"]["action"].get!string; + } + if ("db" in _yaml["search"] + && _yaml["search"]["db"].type.string + && _yaml["search"]["db"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.search_db = _yaml["search"]["db"].get!string; + } + if ("title" in _yaml["search"] + && _yaml["search"]["title"].type.string + && _yaml["search"]["title"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.conf.search_title = _yaml["search"]["title"].get!string; + } + } + } + /+ meta ------------------------------------------------------------------- +/ + if (_struct_composite.meta.creator_author.empty) { + if ("creator" in _yaml + && _yaml["creator"].type.sequence + ) { + if (_yaml["creator"].type.mapping + && _yaml["creator"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("author" in _yaml["creator"] + && _yaml["creator"]["author"].type.string + && _yaml["creator"]["author"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.creator_author = _yaml["creator"]["author"].get!string; + } + if ("email" in _yaml["creator"] + && _yaml["creator"]["email"].type.string + && _yaml["creator"]["email"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.creator_author_email = _yaml["creator"]["email"].get!string; + } + if ("illustrator" in _yaml["creator"] + && _yaml["creator"]["illustrator"].type.string + && _yaml["creator"]["illustrator"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.creator_illustrator = _yaml["creator"]["illustrator"].get!string; + } + if ("translator" in _yaml["creator"] + && _yaml["creator"]["translator"].type.string + && _yaml["creator"]["translator"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.creator_translator = _yaml["creator"]["translator"].get!string; + } + } else if (_yaml["creator"].type.string + && _yaml["creator"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.creator_author = _yaml["creator"].get!string; + } + } + string[] author_arr; + string[][string] authors_hash_arr = [ "first" : [], "last" : [], "full" : [], "last_first" : [], "as_input" : [] ]; + string[] authors_raw_arr + = _struct_composite.meta.creator_author.split(rgx.arr_delimiter); + auto _lastname = appender!(char[])(); + foreach (author_raw; authors_raw_arr) { + author_arr ~= author_raw.replace(rgx.raw_author_munge, "$2 $1"); + authors_hash_arr["first"] ~= author_raw.replace(rgx.raw_author_munge, "$2"); + authors_hash_arr["last"] ~= author_raw.replace(rgx.raw_author_munge, "$1"); + authors_hash_arr["full"] ~= author_raw.replace(rgx.raw_author_munge, "$2 $1"); + authors_hash_arr["as_input"] ~= author_raw; + if (auto m = author_raw.match(rgx.raw_author_munge)) { + (m.captures[1]).map!toUpper.copy(_lastname); + authors_hash_arr["last_first"] ~= _lastname.data.to!string ~ ", " ~ m.captures[2]; + _lastname = appender!(char[])(); + } + } + _struct_composite.meta.creator_author_arr = author_arr; + _struct_composite.meta.creator_author = author_arr.join(", ").chomp.chomp; + _struct_composite.meta.creator_author_surname = authors_hash_arr["last"][0]; + string _author_name_last_first = authors_hash_arr["last_first"].join("; ").chomp.chomp; + _struct_composite.meta.creator_author_surname_fn = (_author_name_last_first.length > 0) + ? _author_name_last_first + : authors_hash_arr["as_input"].join("; ").chomp.chomp; + } + if (_struct_composite.meta.title_main.empty) { + if ("title" in _yaml + && _yaml["title"].type.sequence + ) { + if (_yaml["title"].type.mapping + && _yaml["title"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("main" in _yaml["title"] + && _yaml["title"]["main"].type.string + && _yaml["title"]["main"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_main = _yaml["title"]["main"].get!string; + } else if ("title" in _yaml["title"] + && _yaml["title"]["title"].type.string + && _yaml["title"]["title"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_main = _yaml["title"]["title"].get!string; + } + if ("edition" in _yaml["title"] + && _yaml["title"]["edition"].type.string + && _yaml["title"]["edition"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_edition = _yaml["title"]["edition"].get!string; + } + if ("full" in _yaml["title"] + && _yaml["title"]["full"].type.string + && _yaml["title"]["full"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_full = _yaml["title"]["full"].get!string; + } + if ("language" in _yaml["title"] + && _yaml["title"]["language"].type.string + && _yaml["title"]["language"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_language = _yaml["title"]["language"].get!string; + } + if ("note" in _yaml["title"] + && _yaml["title"]["note"].type.string + && _yaml["title"]["note"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_note = _yaml["title"]["note"].get!string; + } + if ("subtitle" in _yaml["title"] + && _yaml["title"]["subtitle"].type.string + && _yaml["title"]["subtitle"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_subtitle = _yaml["title"]["subtitle"].get!string; + } else if ("sub" in _yaml["title"] + && _yaml["title"]["sub"].type.string + && _yaml["title"]["sub"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_subtitle = _yaml["title"]["sub"].get!string; + } + } else if ( + _yaml["title"].type.string + && _yaml["title"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.title_main = _yaml["title"].get!string; + } + } + _struct_composite.meta.title_sub = _struct_composite.meta.title_subtitle; + if ((!(_struct_composite.meta.title_subtitle.empty)) + && (_struct_composite.meta.title_sub.empty)) { + _struct_composite.meta.title_sub = _struct_composite.meta.title_subtitle; + } + _struct_composite.meta.title_full = (_struct_composite.meta.title_subtitle.empty) + ? _struct_composite.meta.title_main + : format( + "%s - %s", + _struct_composite.meta.title_main, + _struct_composite.meta.title_subtitle, + ); + } + if ("classify" in _yaml + && _yaml["classify"].type.sequence + ) { + if (_yaml["classify"].type.mapping + && _yaml["classify"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("dewey" in _yaml["classify"] + && _yaml["classify"]["dewey"].type.string + && _yaml["classify"]["dewey"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.classify_dewey = _yaml["classify"]["dewey"].get!string; + } + if ("loc" in _yaml["classify"] + && _yaml["classify"]["loc"].type.string + && _yaml["classify"]["loc"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.classify_loc = _yaml["classify"]["loc"].get!string; + } + if ("keywords" in _yaml["classify"] + && _yaml["classify"]["keywords"].type.string + && _yaml["classify"]["keywords"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.classify_keywords = _yaml["classify"]["keywords"].get!string; + } + if ("topic_register" in _yaml["classify"] + && _yaml["classify"]["topic_register"].type.string + && _yaml["classify"]["topic_register"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.classify_topic_register = _yaml["classify"]["topic_register"].get!string; + string[] main_topics_ = _struct_composite.meta.classify_topic_register.strip.split(rgx.topic_register_main_terms_split); + string[] topics; + string topics_tmp; + string[] multiple_sub_terms; + foreach (mt; main_topics_) { + topics_tmp = mt.replaceAll(rgx.topic_register_main_term_plus_rest_split, mkup.sep); + if (auto m = topics_tmp.match(rgx.topic_register_multiple_sub_terms_split)) { + multiple_sub_terms = m.captures[1].split(rgx.topic_register_sub_terms_split); + foreach (subterm; multiple_sub_terms) { + topics ~= m.captures.pre ~ mkup.sep ~ subterm; + } + } else { + topics ~= topics_tmp; + } + } + // writeln("--> ", topics); + _struct_composite.meta.classify_topic_register_arr = topics; + } + } + } + if ("date" in _yaml + && _yaml["date"].type.sequence + ) { + if (_yaml["date"].type.mapping + && _yaml["date"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("added_to_site" in _yaml["date"] + && _yaml["date"]["added_to_site"].type.string + && _yaml["date"]["added_to_site"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_added_to_site = _yaml["date"]["added_to_site"].get!string; + } + if ("available" in _yaml["date"] + && _yaml["date"]["available"].type.string + && _yaml["date"]["available"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_available = _yaml["date"]["available"].get!string; + } + if ("created" in _yaml["date"] + && _yaml["date"]["created"].type.string + && _yaml["date"]["created"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_created = _yaml["date"]["created"].get!string; + } + if ("issued" in _yaml["date"] + && _yaml["date"]["issued"].type.string + && _yaml["date"]["issued"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_issued = _yaml["date"]["issued"].get!string; + } + if ("modified" in _yaml["date"] + && _yaml["date"]["modified"].type.string + && _yaml["date"]["modified"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_modified = _yaml["date"]["modified"].get!string; + } + if ("published" in _yaml["date"] + && _yaml["date"]["published"].type.string + && _yaml["date"]["published"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_published = _yaml["date"]["published"].get!string; + } + if ("valid" in _yaml["date"] + && _yaml["date"]["valid"].type.string + && _yaml["date"]["valid"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.date_valid = _yaml["date"]["valid"].get!string; + } + } + } + _struct_composite.meta.language_document_char = _manifest.src.language; // move + if ("links" in _yaml) { + // if ("" in _yaml["links"]) { + // _struct_composite.meta.links_ = _yaml["links"][""].str; + // } + } + if ("notes" in _yaml + && _yaml["notes"].type.sequence + ) { + if (_yaml["notes"].type.mapping + && _yaml["notes"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("abstract" in _yaml["notes"] + && _yaml["notes"]["abstract"].type.string + && _yaml["notes"]["abstract"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.notes_abstract = _yaml["notes"]["abstract"].get!string; + } + if ("description" in _yaml["notes"] + && _yaml["notes"]["description"].type.string + && _yaml["notes"]["description"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.notes_description = _yaml["notes"]["description"].get!string; + } + } + } + if ("original" in _yaml + && _yaml["original"].type.sequence + ) { + if (_yaml["original"].type.mapping + && _yaml["original"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("language" in _yaml["original"] + && _yaml["original"]["language"].type.string + && _yaml["original"]["language"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.original_language = _yaml["original"]["language"].get!string; + } + if ("language_char" in _yaml["original"] + && _yaml["original"]["language_char"].type.string + && _yaml["original"]["language_char"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.original_language_char = _yaml["original"]["language_char"].get!string; + } + if ("source" in _yaml["original"] + && _yaml["original"]["source"].type.string + && _yaml["original"]["source"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.original_source = _yaml["original"]["source"].get!string; + } + if ("title" in _yaml["original"] + && _yaml["original"]["title"].type.string + && _yaml["original"]["title"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.original_title = _yaml["original"]["title"].get!string; + } + } + } + if ("publisher" in _yaml) { + // if ("" in _yaml["publisher"]) { + // _struct_composite.meta.publisher = _yaml["publisher"][""].str; + // } + } + if ("rights" in _yaml + && _yaml["rights"].type.sequence + ) { + if (_yaml["rights"].type.mapping + && _yaml["rights"].tag.match(rgx.yaml_tag_is_map) + ) { + if ("copyright" in _yaml["rights"] + && _yaml["rights"]["copyright"].type.string + && _yaml["rights"]["copyright"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright = _yaml["rights"]["copyright"].get!string; + } + if ("copyright_text" in _yaml["rights"] + && _yaml["rights"]["copyright_text"].type.string + && _yaml["rights"]["copyright_text"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_text = _yaml["rights"]["copyright_text"].get!string; + } + if ("copyright_audio" in _yaml["rights"] + && _yaml["rights"]["copyright_audio"].type.string + && _yaml["rights"]["copyright_audio"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_audio = _yaml["rights"]["copyright_audio"].get!string; + } + if ("copyright_cover" in _yaml["rights"] + && _yaml["rights"]["copyright_cover"].type.string + && _yaml["rights"]["copyright_cover"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_cover = _yaml["rights"]["copyright_cover"].get!string; + } + if ("copyright_illustrations" in _yaml["rights"] + && _yaml["rights"]["copyright_illustrations"].type.string + && _yaml["rights"]["copyright_illustrations"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_illustrations = _yaml["rights"]["copyright_illustrations"].get!string; + } + if ("copyright_photographs" in _yaml["rights"] + && _yaml["rights"]["copyright_photographs"].type.string + && _yaml["rights"]["copyright_photographs"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_photographs = _yaml["rights"]["copyright_photographs"].get!string; + } + if ("copyright_translation" in _yaml["rights"] + && _yaml["rights"]["copyright_translation"].type.string + && _yaml["rights"]["copyright_translation"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_translation = _yaml["rights"]["copyright_translation"].get!string; + } + if ("copyright_video" in _yaml["rights"] + && _yaml["rights"]["copyright_video"].type.string + && _yaml["rights"]["copyright_video"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_copyright_video = _yaml["rights"]["copyright_video"].get!string; + } + if ("license" in _yaml["rights"] + && _yaml["rights"]["license"].type.string + && _yaml["rights"]["license"].tag.match(rgx.yaml_tag_is_str) + ) { + _struct_composite.meta.rights_license = _yaml["rights"]["license"].get!string; + } + } + } + return _struct_composite; + } +} +static template configParseYAMLreturnDocReformStruct() { + import dyaml; + import + doc_reform.meta.conf_make_meta_structs, + doc_reform.meta.conf_make_meta_json; + mixin contentYAMLtoDocReformStruct; + auto configParseYAMLreturnDocReformStruct(T,CCm,M)( + T _document_struct, + CCm _make_and_meta_struct, + M _manifest + ){ + Node yaml_root = Loader.fromString(_document_struct.content).load(); + _make_and_meta_struct + = contentYAMLtoDocReformStruct!()(_make_and_meta_struct, yaml_root, _manifest, _document_struct.filename); // struct from yaml + return _make_and_meta_struct; + } +} +static template docHeaderMakeAndMetaTupYamlExtractAndConvertToStruct() { + import + std.exception, + std.regex, + std.stdio, + std.traits, + std.typecons, + std.utf, + std.conv : to; + import + dyaml; + import + doc_reform.meta.conf_make_meta_structs, + doc_reform.meta.conf_make_meta_json, + doc_reform.meta.rgx; + mixin DocReformRgxInit; + mixin contentJSONtoDocReformStruct; + static auto rgx = Rgx(); + auto docHeaderMakeAndMetaTupYamlExtractAndConvertToStruct(CCm,Src,M)( + Src header_src, + CCm _make_and_meta_struct, + M _manifest, + ) { + Node _yaml_root; + if (header_src.match(rgx.yaml_header_meta_title)) { + debug (yaml) { + writeln(">>> document header is yaml, consider converting to JSON"); + } + import dyaml; + _yaml_root = Loader.fromString(header_src).load(); + } + auto _header_and_make_and_meta_struct + = contentYAMLtoDocReformStruct!()(_make_and_meta_struct, _yaml_root, _manifest, "header"); + return _header_and_make_and_meta_struct; + } +} diff --git a/src/doc_reform/meta/metadoc.d b/src/doc_reform/meta/metadoc.d index c597963..9adc0c2 100644 --- a/src/doc_reform/meta/metadoc.d +++ b/src/doc_reform/meta/metadoc.d @@ -11,10 +11,8 @@ template DocReformAbstraction() { doc_reform.meta.metadoc_harvest, doc_reform.meta.metadoc_harvests_authors, doc_reform.meta.metadoc_harvests_topics, - doc_reform.meta.metadoc_summary, doc_reform.meta.metadoc_from_src, doc_reform.meta.conf_make_meta_structs, - doc_reform.meta.conf_make_meta_toml, doc_reform.meta.conf_make_meta_json, doc_reform.meta.defaults, doc_reform.meta.doc_debugs, @@ -28,7 +26,7 @@ template DocReformAbstraction() { mixin DocReformBiblio; mixin DocReformRgxInitFlags; mixin outputHub; - enum headBody { header, body_content, insert_file_list, image_list } + enum headBody { header, body_content, header_type, insert_file_list, image_list } enum makeMeta { make, meta } enum docAbst { doc_abstract_obj, doc_has } static auto rgx = Rgx(); @@ -41,11 +39,23 @@ template DocReformAbstraction() { ConfCompositePlus _make_and_meta_struct; { /+ document config file +/ auto _config_document_struct = readConfigDoc!()(_manifest, _env); - _make_and_meta_struct = _config_document_struct.configParseTOMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); + if (_config_document_struct.filetype == "yaml") { + import doc_reform.meta.conf_make_meta_yaml; + _make_and_meta_struct = _config_document_struct.configParseYAMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); + } else if (_config_document_struct.filetype == "toml") { + import doc_reform.meta.conf_make_meta_toml; + _make_and_meta_struct = _config_document_struct.configParseTOMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); + } } { /+ local site config +/ auto _config_local_site_struct = readConfigSite!()(_manifest, _env); - _make_and_meta_struct = _config_local_site_struct.configParseTOMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); + 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); + } else if (_config_local_site_struct.filetype == "toml") { + import doc_reform.meta.conf_make_meta_toml; + _make_and_meta_struct = _config_local_site_struct.configParseTOMLreturnDocReformStruct!()(_make_and_meta_struct, _manifest); + } } /+ ↓ read file (filename with path) +/ /+ ↓ file tuple of header and content +/ @@ -58,7 +68,7 @@ template DocReformAbstraction() { auto _header_body_insertfilelist_imagelist = DocReformRawMarkupContent!()(_opt_action, _manifest.src.path_and_fn); static assert(!isTypeTuple!(_header_body_insertfilelist_imagelist)); - static assert(_header_body_insertfilelist_imagelist.length==4); + static assert(_header_body_insertfilelist_imagelist.length==5); if ((_opt_action.debug_do) || (_opt_action.very_verbose) ) { @@ -73,14 +83,25 @@ template DocReformAbstraction() { if ((_opt_action.debug_do) || (_opt_action.very_verbose) ) { - writeln("step2 commence → (read document header - toml, return struct)"); + writeln("step2 commence → (read document header - yaml or toml, return struct)"); + } + if (_header_body_insertfilelist_imagelist[headBody.header_type] == "toml") { + import doc_reform.meta.conf_make_meta_toml; + _make_and_meta_struct = + docHeaderMakeAndMetaTupTomlExtractAndConvertToStruct!()( + _header_body_insertfilelist_imagelist[headBody.header], + _make_and_meta_struct, + _manifest, + ); + } else if (_header_body_insertfilelist_imagelist[headBody.header_type] == "yaml") { + import doc_reform.meta.conf_make_meta_yaml; + _make_and_meta_struct = + docHeaderMakeAndMetaTupYamlExtractAndConvertToStruct!()( + _header_body_insertfilelist_imagelist[headBody.header], + _make_and_meta_struct, + _manifest, + ); } - _make_and_meta_struct = - docHeaderMakeAndMetaTupTomlExtractAndConvertToStruct!()( - _make_and_meta_struct, - _header_body_insertfilelist_imagelist[headBody.header], - _manifest, - ); if ((_opt_action.debug_do) || (_opt_action.very_verbose) ) { @@ -117,7 +138,7 @@ template DocReformAbstraction() { auto generator_program() { struct Prog_ { string project_name() { - return program_info.project; + return "DocReform"; } string name() { return program_info.name; diff --git a/src/doc_reform/meta/rgx.d b/src/doc_reform/meta/rgx.d index 926f2c6..bad5b52 100644 --- a/src/doc_reform/meta/rgx.d +++ b/src/doc_reform/meta/rgx.d @@ -11,6 +11,10 @@ static template DocReformRgxInit() { static flag_action = ctRegex!(`^(--[a-z][a-z0-9-]+)$`); static flag_action_str = ctRegex!(` (--[a-z][a-z0-9-]+)`); static within_quotes = ctRegex!(`"(.+?)"`, "m"); + static yaml_tag_is_str = ctRegex!(`:str$`); + static yaml_tag_is_int = ctRegex!(`:int$`); + static yaml_tag_is_map = ctRegex!(`:map$`); + static yaml_tag_is_seq = ctRegex!(`:seq$`); static make_heading_delimiter = ctRegex!(`[;][ ]*`); static arr_delimiter = ctRegex!(`[ ]*[;][ ]*`); static name_delimiter = ctRegex!(`^([^,]+)[ ]*,[ ]+(.+?)$`); @@ -45,7 +49,10 @@ static template DocReformRgxInit() { static variable_doc_title = ctRegex!(`@title`); static variable_doc_author = ctRegex!(`@author|@creator`); static raw_author_munge = ctRegex!(`(?P\S.+?),\s+(?P.+)`,"i"); - static toml_header_meta_title = ctRegex!(`^\s*(title\s*=\s*"|\[title\])`, "m"); + static toml_header_meta_title = ctRegex!(`^\s*(?:title\s*=\s*"|\[title\])`, "m"); + static yaml_header_meta_title = ctRegex!(`^\s*(?:title\s*:\s*(?:"?\w|$))`, "m"); + static toml_config = ctRegex!(`^\s*(?:[a-z]+\s*=\s*"|\[\w+?\])`, "m"); + static yaml_config = ctRegex!(`^[a-z]+\s*:\s*(?:"?\w|$)`, "m"); /+ heading & paragraph operators +/ static heading_a = ctRegex!(`^:?[A][~] `, "m"); static heading = ctRegex!(`^:?([A-D1-4])[~]([a-z0-9_.-]*[?]?)\s+`,"i"); diff --git a/src/doc_reform/source/paths_source.d b/src/doc_reform/source/paths_source.d index d02eae2..1bf3af1 100644 --- a/src/doc_reform/source/paths_source.d +++ b/src/doc_reform/source/paths_source.d @@ -397,10 +397,10 @@ template ConfigFilePaths() { E _env, ) { struct ConfFilePaths { - string config_filename_document_toml() { + string config_filename_document() { return "dr_document_make"; } - string config_filename_site_toml() { + string config_filename_site() { return "config_local_site"; } auto possible_config_path_locations() { diff --git a/src/doc_reform/source/read_config_files.d b/src/doc_reform/source/read_config_files.d index 0855eab..96f604b 100644 --- a/src/doc_reform/source/read_config_files.d +++ b/src/doc_reform/source/read_config_files.d @@ -4,15 +4,15 @@ meta_config_files.d +/ module doc_reform.source.read_config_files; -static template configReadInSiteTOML() { +static template configReadInSiteSTR() { import doc_reform.meta, doc_reform.source.paths_source, std.file, std.path; - 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) { @@ -39,15 +39,15 @@ static template configReadInSiteTOML() { return config_file_str; } } -static template configReadInDocTOML() { +static template configReadInDocSTR() { import doc_reform.meta, doc_reform.source.paths_source, std.file, std.path; - 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) { @@ -93,17 +93,21 @@ static template configTOML() { } } static template readConfigSite() { + import + doc_reform.meta.rgx; import doc_reform.meta, doc_reform.source.paths_source, std.file, std.path; + 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; @@ -130,7 +134,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; @@ -140,17 +150,21 @@ static template readConfigSite() { } } static template readConfigDoc() { + import + doc_reform.meta.rgx; import doc_reform.meta, doc_reform.source.paths_source, std.file, std.path; + 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; @@ -176,16 +190,52 @@ 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(); } } +static template configReadSiteYAML() { + import + doc_reform.meta, + doc_reform.source.paths_source, + std.file, + std.path; + 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 + doc_reform.meta, + doc_reform.source.paths_source, + std.file, + std.path; + 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; + } +} static template configReadSiteTOML() { import doc_reform.meta, @@ -194,9 +244,9 @@ static template configReadSiteTOML() { std.path; 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; } @@ -209,9 +259,9 @@ static template configReadDocTOML() { std.path; 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; } diff --git a/src/doc_reform/source/read_source_files.d b/src/doc_reform/source/read_source_files.d index b19582d..753612e 100644 --- a/src/doc_reform/source/read_source_files.d +++ b/src/doc_reform/source/read_source_files.d @@ -59,13 +59,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; } } @@ -125,13 +132,20 @@ static template DocReformRawMarkupContent() { 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