aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sdp/abstraction.d
blob: 77a5512b872ae28bc6bf5b477dc57f5cd8d49e01 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
template SiSUabstraction() {
  /+ sdp: sisu document parser, see http://sisudoc.org +/
  import
    abstraction_summary,
    ao_abstract_doc_source,
    ao_conf_make_meta,
    ao_conf_make_meta_native,
    ao_conf_make_meta_sdlang,
    ao_defaults,
    ao_doc_debugs,
    ao_read_config_files,
    ao_read_source_files,
    ao_rgx,
    output_hub;
  /+ sdlang http://sdlang.org +/
  import sdlang;                            // sdlang.d
  /+ std +/
  private import
    std.array,
    std.exception,
    std.getopt,
    std.process,
    std.stdio,
    std.regex,
    std.string,
    std.traits,
    std.typecons,
    std.utf,
    std.conv : to;
  mixin SiSUrgxInit;
  mixin SiSUregisters;
  mixin SiSUheaderExtractSDLang;
  mixin SiSUnode;
  mixin SiSUbiblio;
  mixin SiSUrgxInitFlags;
  mixin outputHub;
  enum headBody { header, body_content, insert_filelist }
  enum makeMeta { make, meta }
  enum docAbst  { doc_abstraction, section_keys, segnames, images }
  auto rgx = Rgx();
  auto SiSUabstraction(Fn,O,E)(Fn fn_src, O opts, E env){
    auto sdl_root_configuration = ConfigHub!()("conf.sdl", env);
    auto sdl_root_doc_make = ConfigHub!()("sisu_document_make", env);
    auto confsdl = HeaderExtractSDL();
    auto conf_settings_aa = confsdl.configSettingsSDLangToAAmake(sdl_root_configuration);
    auto conf_doc_make_aa = confsdl.documentMakeSDLangToAAmake(sdl_root_doc_make);
    /+ ↓ read file (filename with path) +/
    /+ ↓ file tuple of header and content +/
    auto _header_body_inserts =
      SiSUrawMarkupContent!()(fn_src);
    static assert(!isTypeTuple!(_header_body_inserts));
    static assert(_header_body_inserts.length==3);
    debug(header_and_body) {
      writeln(header);
      writeln(_header_body_inserts.length);
      writeln(_header_body_inserts.length[headBody.body_content][0]);
    }
    /+ ↓ split header into make and meta +/
    auto _make_and_meta =
      SiSUheaderExtractHub!()(_header_body_inserts[headBody.header], conf_doc_make_aa);
    static assert(!isTypeTuple!(_make_and_meta));
    static assert(_make_and_meta.length==2);
    /+ ↓ document abstraction: process document, return abstraction as tuple +/
    auto da = SiSUdocAbstraction!()(
      (_header_body_inserts[headBody.body_content]),
      (_make_and_meta[makeMeta.make]),
      (_make_and_meta[makeMeta.meta]),
      opts
    );
    static assert(!isTypeTuple!(da));
    static assert(da.length==4);
    auto doc_abstraction = da[docAbst.doc_abstraction]; // head ~ toc ~ body ~ endnotes_seg ~ glossary ~ bibliography ~ bookindex ~blurb;
    string[][string] _document_section_keys_sequenced = da[docAbst.section_keys];
    string[] _doc_html_segnames = da[docAbst.segnames];
    auto _images = da[docAbst.images];
    struct DocumentMatters {
      string[] keys_seq_seg() {
        string[] _k = _document_section_keys_sequenced["seg"];
        return _k;
      }
      string[] keys_seq_scroll() {
        string[] _k = _document_section_keys_sequenced["scroll"];
        return _k;
      }
      string[] segnames() {
        string[] _k = _doc_html_segnames;
        return _k;
      }
      auto dochead_make() {
        string[string][string] _k = _make_and_meta[makeMeta.make];
        return _k;
      }
      auto dochead_meta() {
        string[string][string] _k = _make_and_meta[makeMeta.meta];
        return _k;
      }
      auto source_filename() {
        string _k = fn_src;
        return _k;
      }
      auto language() {
        string _k;
        if (auto m = match(fn_src, rgx.language_code_and_filename)) {
          _k = m.captures[1];
        } else {
          _k = "en";
        }
        return _k;
      }
      auto file_insert_list() {
        string[] _k = _header_body_inserts[headBody.insert_filelist];
        return _k;
      }
      auto image_list() {
        auto _k = _images;
        return _k;
      }
      auto opt_action_bool() {
        bool[string] _k = opts;
        return _k;
      }
      auto environment() {
        auto _k = env;
        return _k;
      }
    }
    auto doc_matters = DocumentMatters();
    auto t = tuple(doc_abstraction, doc_matters);
    static assert(t.length==2);
    return t;
  }
}