From 1c73ddf3894085c646b55d63e61a2483e03a3b4d Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 9 Feb 2018 22:03:10 -0500 Subject: 0.24.0 toml or sdlang for configuration --- src/sdp/meta/conf_make_meta_toml.d | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/sdp/meta/conf_make_meta_toml.d (limited to 'src/sdp/meta/conf_make_meta_toml.d') diff --git a/src/sdp/meta/conf_make_meta_toml.d b/src/sdp/meta/conf_make_meta_toml.d new file mode 100644 index 0000000..4390c5c --- /dev/null +++ b/src/sdp/meta/conf_make_meta_toml.d @@ -0,0 +1,79 @@ +/++ + 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 sdp.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 + sdp.meta.conf_make_meta_structs, + sdp.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 + sdp.meta.conf_make_meta_structs, + sdp.meta.conf_make_meta_json, + sdp.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.sdlang_header_meta_title)) { + writeln("WARNING >>> document header is sdlang (in wrong location JSON)"); + } else 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