aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/doc_reform/meta/conf_make_meta_toml.d
blob: d308ae4fcbd4e8fbac04742388ee0174d5e46767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/++
  extract native/orig header return associative array<BR>

  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;
  }
}