From e95c49b76f4ac7bf72c383ee43a0567dfcbf1603 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 10 Sep 2018 18:15:02 -0400 Subject: 0.1.0 renamed doc-reform, doc_reform (& rad) - from sdp --- src/doc_reform/meta/conf_make_meta_toml.d | 77 +++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/doc_reform/meta/conf_make_meta_toml.d (limited to 'src/doc_reform/meta/conf_make_meta_toml.d') diff --git a/src/doc_reform/meta/conf_make_meta_toml.d b/src/doc_reform/meta/conf_make_meta_toml.d new file mode 100644 index 0000000..d308ae4 --- /dev/null +++ b/src/doc_reform/meta/conf_make_meta_toml.d @@ -0,0 +1,77 @@ +/++ + 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" + converting the metadata and make instructions to a common json format used by + program internally. Moved to associative array. ++/ +module doc_reform.meta.conf_make_meta_toml; +static template configParseTOMLreturnJSON() { + import + toml, + toml.json; + auto configParseTOMLreturnJSON(T)( + T _text + ){ + TOMLDocument _doc; + _doc = parseTOML(cast(string)(_text.content)); + auto _doc_json = toJSON(_doc); + return _doc_json; + } +} +static template configParseTOMLreturnSiSUstruct() { + import + toml, + toml.json; + import + doc_reform.meta.conf_make_meta_structs, + doc_reform.meta.conf_make_meta_json; + mixin contentJSONtoSiSUstruct; + auto configParseTOMLreturnSiSUstruct(CCm, T)( + CCm _make_and_meta_struct, + T _document_struct + ){ + TOMLDocument _doc = parseTOML(cast(string)(_document_struct.content)); + auto _doc_json = toJSON(_doc); + _make_and_meta_struct = contentJSONtoSiSUstruct!()(_make_and_meta_struct, _doc_json, _document_struct.filename); // struct from json + return _make_and_meta_struct; + } +} +static template docHeaderMakeAndMetaTupTomlExtractAndConvertToStruct() { + import + std.exception, + std.regex, + std.stdio, + std.traits, + std.typecons, + std.utf, + std.conv : to; + import + toml, + toml.json; + import + doc_reform.meta.conf_make_meta_structs, + doc_reform.meta.conf_make_meta_json, + doc_reform.meta.rgx; + mixin SiSUrgxInit; + mixin contentJSONtoSiSUstruct; + static auto rgx = Rgx(); + auto docHeaderMakeAndMetaTupTomlExtractAndConvertToStruct(CCm, Src)( + CCm _make_and_meta_struct, + Src header_src, + ) { + TOMLDocument _doc; + 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)); + } + auto _doc_json = toJSON(_doc); + auto _header_and_make_and_meta_struct = contentJSONtoSiSUstruct!()(_make_and_meta_struct, _doc_json, "header"); + return _header_and_make_and_meta_struct; + } +} -- cgit v1.2.3