From b243ba3e00bf6cd5e9298903bc69d8efc7a03414 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 1 Mar 2018 12:51:58 -0500 Subject: conf, make, meta, init and tidy substitution --- src/sdp/meta/conf_make_meta_json.d | 6 +- src/sdp/meta/conf_make_meta_structs.d | 275 +++++++++++++++------------------- src/sdp/meta/metadoc_from_src.d | 63 ++++---- 3 files changed, 155 insertions(+), 189 deletions(-) (limited to 'src') diff --git a/src/sdp/meta/conf_make_meta_json.d b/src/sdp/meta/conf_make_meta_json.d index 916dd33..abb9b46 100644 --- a/src/sdp/meta/conf_make_meta_json.d +++ b/src/sdp/meta/conf_make_meta_json.d @@ -137,16 +137,16 @@ static template contentJSONtoSiSUstruct() { ) { _struct_composite.make_str.texpdf_font = _json.object["make"]["texpdf_font"].str; } - _struct_composite.make.bold_rgxmatch = _mk.bold_rgxmatch(_struct_composite.make_str.bold); + _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_rgxmatch = _mk.emphasis_rgxmatch(_struct_composite.make_str.emphasis); + _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_rgxmatch = _mk.italics_rgxmatch(_struct_composite.make_str.italics); + _struct_composite.make.italics = _mk.italics(_struct_composite.make_str.italics); _struct_composite.make.num_top = _mk.num_top(_struct_composite.make_str.num_top); _struct_composite.make.num_depth = _mk.num_depth(_struct_composite.make_str.num_depth); _struct_composite.make.substitute = _mk.substitute(_struct_composite.make_str.substitute); diff --git a/src/sdp/meta/conf_make_meta_structs.d b/src/sdp/meta/conf_make_meta_structs.d index d46b462..add72d6 100644 --- a/src/sdp/meta/conf_make_meta_structs.d +++ b/src/sdp/meta/conf_make_meta_structs.d @@ -10,36 +10,28 @@ import std.utf, std.conv : to; struct ConfCompositeMakeStr { - string bold = ""; - string breaks = ""; - string cover_image = ""; - string css = ""; - string emphasis = ""; - string footer = ""; + string bold; + string breaks; + string cover_image; + string css; + string emphasis; + string footer; string[] headings; - string home_button_image = ""; - string home_button_text = ""; - string italics = ""; - string num_top = ""; - string num_depth = ""; + string home_button_image; + string home_button_text; + string italics; + string num_top; + string num_depth; string[][] substitute; - string texpdf_font = ""; + string texpdf_font; } struct confCompositeMakeBuild { - auto bold_rgxmatch(string _mk) { - auto _rgxtxt = (_mk.empty) - ? `=NULL` - : `(` ~ _mk.dup ~ `)`; - return (cast(char[]) (_rgxtxt)); - } - auto bold_substitute_abstract() { - return "*{$1}*"; - } - auto bold_substitute_sisu_markup() { - return "*{$1}*"; - } - auto bold_substitute_html() { - return "$1"; + auto bold(string _mk) { + string[] _out; + if (_mk) { + _out = [ (cast(string) (`(` ~ _mk.dup ~ `)`)), "*{$1}*", "$1"]; + } + return _out; } auto breaks(string _mk) { return _mk; @@ -50,20 +42,12 @@ struct confCompositeMakeBuild { auto css(string _mk) { return _mk; } - auto emphasis_rgxmatch(string _mk) { - auto _rgxtxt = (_mk.empty) - ? `=NULL` - : `(` ~ _mk.dup ~ `)`; - return (cast(char[]) (_rgxtxt)); - } - auto emphasis_substitute_abstract() { - return "!{$1}!"; - } - auto emphasis_substitute_sisu_markup() { - return "!{$1}!"; - } - auto emphasis_substitute_html() { - return "$1"; + auto emphasis(string _mk) { + string[] _out; + if (_mk) { + _out = [ (cast(string) (`(` ~ _mk.dup ~ `)`)), "!{$1}!", "$1" ]; + } + return _out; } auto footer(string _mk) { return _mk; @@ -77,20 +61,12 @@ struct confCompositeMakeBuild { auto home_button_text(string _mk) { return _mk; } - auto italics_rgxmatch(string _mk) { - auto _rgxtxt = (_mk.empty) - ? `=NULL` - : `(` ~ _mk.dup ~ `)`; - return (cast(char[]) (_rgxtxt)); - } - auto italics_substitute_abstract() { - return "/{$1}/"; - } - auto italics_substitute_sisu_markup() { - return "/{$1}/"; - } - auto italics_substitute_html() { - return "$1"; + auto italics(string _mk) { + string[] _out; + if (_mk) { + _out = [ (cast(string) (`(` ~ _mk.dup ~ `)`)), "/{$1}/", "$1" ]; + } + return _out; } auto num_top(string _mk) { return _mk; @@ -106,112 +82,103 @@ struct confCompositeMakeBuild { } } struct ConfCompositeMakeInit { - char[] bold_rgxmatch = `=NULL`.dup; - auto bold_substitute_abstract = "*{$1}*"; - auto bold_substitute_sisu_markup = "*{$1}*"; - auto bold_substitute_html = "$1"; - string breaks = ""; - string cover_image = ""; - string css = ""; - char[] emphasis_rgxmatch = `=NULL`.dup; - auto emphasis_substitute_abstract = "!{$1}!"; - auto emphasis_substitute_sisu_markup = "!{$1}!"; - auto emphasis_substitute_html = "$1"; - string footer = ""; + string[] bold; + string breaks; + string cover_image; + string css; + string[] emphasis; + string footer; string[] headings; - string home_button_image = ""; - string home_button_text = ""; - char[] italics_rgxmatch = `=NULL`.dup; - auto italics_substitute_abstract = "/{$1}/"; - auto italics_substitute_sisu_markup = "/{$1}/"; - auto italics_substitute_html = "$1"; - string num_top = ""; - string num_depth = ""; + string home_button_image; + string home_button_text; + string[] italics; + string num_top; + string num_depth; string[][] substitute; - string texpdf_font = ""; + string texpdf_font; } struct ConfCompositeSiteLocal { - string webserv_url_root = ""; - string webserv_path = ""; - string webserv_images = ""; - string webserv_cgi = ""; - string webserv_cgi_host = ""; - string webserv_cgi_host_path = ""; - string webserv_cgi_port = ""; - string webserv_cgi_user = ""; - string webserv_cgi_file_links = ""; - string processing_path = ""; - string processing_dir = ""; - string processing_concord_max = ""; - string flag_act0 = ""; - string flag_act1 = ""; - string flag_act2 = ""; - string flag_act3 = ""; - string flag_act4 = ""; - string flag_act5 = ""; - string flag_act6 = ""; - string flag_act7 = ""; - string flag_act8 = ""; - string flag_act9 = ""; - string default_papersize = ""; - string default_text_wrap = ""; - string default_emphasis = ""; - string default_language = ""; - string default_digest = ""; - string permission_share_source = ""; - string search_flag = ""; - string search_action = ""; - string search_db = ""; - string search_title = ""; + string webserv_url_root; + string webserv_path; + string webserv_images; + string webserv_cgi; + string webserv_cgi_host; + string webserv_cgi_host_path; + string webserv_cgi_port; + string webserv_cgi_user; + string webserv_cgi_file_links; + string processing_path; + string processing_dir; + string processing_concord_max; + string flag_act0; + string flag_act1; + string flag_act2; + string flag_act3; + string flag_act4; + string flag_act5; + string flag_act6; + string flag_act7; + string flag_act8; + string flag_act9; + string default_papersize; + string default_text_wrap; + string default_emphasis; + string default_language; + string default_digest; + string permission_share_source; + string search_flag; + string search_action; + string search_db; + string search_title; } struct MetaComposite { - string classify_dewey = ""; - string classify_keywords = ""; - string classify_loc = ""; - string classify_subject = ""; - string classify_topic_register = ""; - string creator_author = ""; - string creator_author_email = ""; - string creator_illustrator = ""; - string creator_translator = ""; - string date_added_to_site = ""; - string date_available = ""; - string date_created = ""; - string date_issued = ""; - string date_modified = ""; - string date_published = ""; - string date_valid = ""; - string identifier_isbn = ""; - string identifier_oclc = ""; - string identifier_pg = ""; - string language_document = ""; - string language_document_char = ""; - string links = ""; - string notes_abstract = ""; - string notes_description = ""; - string original_language = ""; - string original_language_char = ""; - string original_publisher = ""; - string original_source = ""; - string original_title = ""; - string publisher = ""; - string rights_copyright = ""; - string rights_copyright_audio = ""; - string rights_copyright_cover = ""; - string rights_copyright_illustrations = ""; - string rights_copyright_photographs = ""; - string rights_copyright_text = ""; - string rights_copyright_translation = ""; - string rights_copyright_video = ""; - string rights_license = ""; - string title_edition = ""; - string title_full = ""; - string title_language = ""; - string title_main = ""; - string title_note = ""; - string title_short = ""; - string title_sub = ""; - string title_subtitle = ""; + string classify_dewey; + string classify_keywords; + string classify_loc; + string classify_subject; + string classify_topic_register; + string creator_author; + string creator_author_email; + string creator_illustrator; + string creator_translator; + string date_added_to_site; + string date_available; + string date_created; + string date_issued; + string date_modified; + string date_published; + string date_valid; + string identifier_isbn; + string identifier_oclc; + string identifier_pg; + string language_document; + string language_document_char; + string links; + string notes_abstract; + string notes_description; + string original_language; + string original_language_char; + string original_publisher; + string original_source; + string original_title; + string publisher; + string rights_copyright; + string rights_copyright_audio; + string rights_copyright_cover; + string rights_copyright_illustrations; + string rights_copyright_photographs; + string rights_copyright_text; + string rights_copyright_translation; + string rights_copyright_video; + string rights_license; + string title_edition; + string title_full; + string title_language; + string title_main; + string title_note; + string title_short; + string title_sub; + string title_subtitle; } struct ConfComposite { MetaComposite meta; diff --git a/src/sdp/meta/metadoc_from_src.d b/src/sdp/meta/metadoc_from_src.d index 54bedfe..627b37a 100644 --- a/src/sdp/meta/metadoc_from_src.d +++ b/src/sdp/meta/metadoc_from_src.d @@ -358,6 +358,7 @@ template SiSUdocAbstraction() { string[] html_segnames=["toc"]; int cnt1 = 1; int cnt2 = 1; int cnt3 = 1; /+ abstraction init ↑ +/ + enum Substitute { match, markup, } debug (substitutions) { writeln(__LINE__, ":", __FILE__, ": DEBUG substitutions:"); if (!(conf_make_meta.make.headings.empty)) { @@ -365,21 +366,21 @@ template SiSUdocAbstraction() { } if (conf_make_meta.make.substitute) { foreach(substitution_pair; conf_make_meta.make.substitute) { - writeln("regex to match: ", substitution_pair[0]); - writeln("substitution to make: ", substitution_pair[1]); + writeln("regex to match: ", substitution_pair[Substitute.match]); + writeln("substitution to make: ", substitution_pair[Substitute.markup]); } } - if (!(conf_make_meta.make.bold_rgxmatch == "=NULL" || conf_make_meta.make.bold_rgxmatch.empty)) { - writeln("regex to match: ", conf_make_meta.make.bold_rgxmatch); - writeln("substitution to make: ", conf_make_meta.make.bold_substitute_html); + if (conf_make_meta.make.bold) { + writeln("regex to match: ", conf_make_meta.make.bold[Substitute.match]); + writeln("substitution to make: ", conf_make_meta.make.bold[Substitute.markup]); } - if (!(conf_make_meta.make.emphasis_rgxmatch == "=NULL" || conf_make_meta.make.emphasis_rgxmatch.empty)) { - writeln("regex to match: ", conf_make_meta.make.emphasis_rgxmatch); - writeln("substitution to make: ", conf_make_meta.make.emphasis_substitute_html); + if (conf_make_meta.make.emphasis) { + writeln("regex to match: ", conf_make_meta.make.emphasis[Substitute.match]); + writeln("substitution to make: ", conf_make_meta.make.emphasis[Substitute.markup]); } - if (!(conf_make_meta.make.italics_rgxmatch == "=NULL" || conf_make_meta.make.italics_rgxmatch.empty)) { - writeln("regex to match: ", conf_make_meta.make.italics_rgxmatch); - writeln("substitution to make: ", conf_make_meta.make.italics_substitute_html); + if (conf_make_meta.make.italics) { + writeln("regex to match: ", conf_make_meta.make.italics[Substitute.match]); + writeln("substitution to make: ", conf_make_meta.make.italics[Substitute.markup]); } } /+ ↓ loop markup document/text line by line +/ @@ -626,12 +627,14 @@ template SiSUdocAbstraction() { continue; } else if (obj_type_status["quote"] == TriState.on) { /+ within block object: quote +/ + line = _doc_header_and_make_substitutions_(line, conf_make_meta); line = _doc_header_and_make_substitutions_fontface_(line, conf_make_meta); _quote_block_(line, an_object, obj_type_status); continue; /+ within block object: group +/ } else if (obj_type_status["group"] == TriState.on) { /+ within block object: group +/ + line = _doc_header_and_make_substitutions_(line, conf_make_meta); line = _doc_header_and_make_substitutions_fontface_(line, conf_make_meta); line = (line) .replaceAll(rgx.para_delimiter, mkup.br_paragraph ~ "$1"); @@ -639,6 +642,7 @@ template SiSUdocAbstraction() { continue; } else if (obj_type_status["block"] == TriState.on) { /+ within block object: block +/ + line = _doc_header_and_make_substitutions_(line, conf_make_meta); line = _doc_header_and_make_substitutions_fontface_(line, conf_make_meta); if (auto m = line.match(rgx.spaces_line_start)) { line = (line) @@ -673,7 +677,6 @@ template SiSUdocAbstraction() { processing.remove("verse"); obj_cite_number_poem["start"] = obj_cite_digits.on.to!string; } - line = _doc_header_and_make_substitutions_fontface_(line, conf_make_meta); _start_block_(line, obj_type_status, obj_cite_number_poem); continue; } else if (!line.empty) { @@ -751,10 +754,12 @@ template SiSUdocAbstraction() { +/ if (line.matchFirst(rgx.heading)) { /+ heading match +/ + line = _doc_header_and_make_substitutions_(line, conf_make_meta); _heading_matched_(line, line_occur, an_object, an_object_key, lv, collapsed_lev, obj_type_status, conf_make_meta); } else if (line_occur["para"] == State.off) { /+ para match +/ an_object_key="body_nugget"; + line = _doc_header_and_make_substitutions_(line, conf_make_meta); line = _doc_header_and_make_substitutions_fontface_(line, conf_make_meta); _para_match_(line, an_object, an_object_key, indent, bullet, obj_type_status, line_occur); } @@ -770,6 +775,7 @@ template SiSUdocAbstraction() { debug(para) { writeln(an_object_key, "-> ", line); } + line = _doc_header_and_make_substitutions_(line, conf_make_meta); line = _doc_header_and_make_substitutions_fontface_(line, conf_make_meta); an_object[an_object_key] ~= " " ~ line; ++line_occur["para"]; @@ -1955,11 +1961,12 @@ template SiSUdocAbstraction() { debug(asserts) { static assert(is(typeof(line) == char[])); } + enum Substitute { match, markup, } if (conf_make_meta.make.substitute) { foreach(substitution_pair; conf_make_meta.make.substitute) { line = line.replaceAll( - regex(substitution_pair[0]), - substitution_pair[1] + regex(substitution_pair[Substitute.match]), + substitution_pair[Substitute.markup] ); } } @@ -1972,31 +1979,23 @@ template SiSUdocAbstraction() { debug(asserts) { static assert(is(typeof(line) == char[])); } - if (!( - conf_make_meta.make.bold_rgxmatch == "=NULL" - || conf_make_meta.make.bold_rgxmatch.empty - )) { + enum Substitute { match, markup, } + if ( conf_make_meta.make.bold) { line = line.replaceAll( - regex(conf_make_meta.make.bold_rgxmatch), - conf_make_meta.make.bold_substitute_sisu_markup + regex(conf_make_meta.make.bold[Substitute.match]), + conf_make_meta.make.bold[Substitute.markup] ); } - if (!( - conf_make_meta.make.emphasis_rgxmatch == "=NULL" - || conf_make_meta.make.emphasis_rgxmatch.empty - )) { + if (conf_make_meta.make.emphasis) { line = line.replaceAll( - regex(conf_make_meta.make.emphasis_rgxmatch), - conf_make_meta.make.emphasis_substitute_sisu_markup + regex(conf_make_meta.make.emphasis[Substitute.match]), + conf_make_meta.make.emphasis[Substitute.markup] ); } - if (!( - conf_make_meta.make.italics_rgxmatch == "=NULL" - || conf_make_meta.make.italics_rgxmatch.empty - )) { + if (conf_make_meta.make.italics) { line = line.replaceAll( - regex(conf_make_meta.make.italics_rgxmatch), - conf_make_meta.make.italics_substitute_sisu_markup + regex(conf_make_meta.make.italics[Substitute.match]), + conf_make_meta.make.italics[Substitute.markup] ); } return line; -- cgit v1.2.3