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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
#+TITLE: sdp header extract
#+AUTHOR: Ralph Amissah
#+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
#+DESCRIPTION: documents - structuring, publishing in multiple formats & search
#+KEYWORDS
#+LANGUAGE: en
#+STARTUP: indent content
#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+OPTIONS: author:nil email:nil creator:nil timestamp:nil
#+PROPERTY: header-args :padline no :exports code :noweb yes
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+FILETAGS: :sdp:rel:meta:
#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n)
[[./sdp.org][sdp]] [[./][org/]]
* 0. header extract (native & sdlang) to Struct :module:sdp:meta_conf_make_meta:
** module template
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta.d
/++
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 sdp.meta.conf_make_meta;
static template docHeaderMakeAndMetaTupExtractAndConvertToStruct() {
import
std.exception,
std.regex,
std.stdio,
std.traits,
std.typecons,
std.utf,
std.conv : to;
import sdlang;
import
sdp.meta.conf_make_meta_sdlang,
sdp.meta.rgx;
mixin SiSUrgxInit;
mixin SiSUextractSDLang;
static auto rgx = Rgx();
auto docHeaderMakeAndMetaTupExtractAndConvertToStruct(CCm, Src)(
CCm conf_composite_make,
Src header_src,
) {
auto header_sdlang_tag = (!(header_src.match(rgx.native_header_meta_title)))
? extractSDL().docHeaderSDLtagGet(header_src) // sdlang.ast.Tag
: null;
auto header_make_and_meta_struct = extractSDL().docSDLtoStruct(conf_composite_make, header_sdlang_tag);
return header_make_and_meta_struct;
}
}
#+END_SRC
* A. module sdlang :module:sdp:meta_conf_make_meta_sdlang:
** 0. module template
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_sdlang.d
/++
sdlang headers<BR>
extract sdlang header return sdlang
+/
module sdp.meta.conf_make_meta_sdlang;
static template SiSUextractSDLang() {
import
std.exception,
std.regex,
std.stdio,
std.string,
std.traits,
std.typecons,
std.utf,
std.conv : to;
import
sdp.meta.defaults,
sdp.meta.rgx;
struct extractSDL {
mixin SiSUregisters;
mixin SiSUrgxInit;
static auto rgx = Rgx();
<<meta_conf_make_meta_sdl>>
}
}
#+END_SRC
** 1. sdlang header _extract root Tag_ :sdlang:root:tag:
#+name: meta_conf_make_meta_sdl
#+BEGIN_SRC d
private auto docHeaderSDLtagGet(Hs)(Hs src_header) {
debug(asserts){
static assert(is(typeof(src_header) == char[]));
}
char[][] source_header_arr
= (cast(char[]) src_header).split(rgx.newline_eol_delimiter);
char[] _src_header;
foreach(header_line; source_header_arr) {
if (!match(header_line, rgx.comments)) {
_src_header ~= header_line ~ "\n";
}
}
scope(failure) {
stderr.writefln(
"%s\n%s\n%s:%s failed here:\n _src_header: %s",
__MODULE__, __FUNCTION__,
__FILE__, __LINE__,
_src_header,
);
}
Tag sdl_root_header;
try {
sdl_root_header = parseSource(_src_header.to!string);
}
catch(ParseException e) {
stderr.writeln("SDLang problem with this document header:");
stderr.writeln(_src_header);
// Error messages of the form:
// myFile.sdl(5:28): Error: Invalid integer suffix.
stderr.writeln(e.msg);
}
debug(sdlang) {
writeln("header SDL:");
writeln(__LINE__, ": ", sdl_root_header.toSDLDocument());
writeln(__LINE__, ": ", sdl_root_header.maybe.namespaces);
writeln("header make sdlang: ", sdl_root_header.toSDLDocument());
writeln(__LINE__, ": ", sdl_root_header.getTagValues("title"));
writeln(__LINE__, ": ", sdl_root_header.getTagValues("creator"));
Tag creator = sdl_root_header.getTag("creator");
if (creator !is null) {
if ("author" in creator.maybe.tags) {
writeln(__LINE__, ": ", creator.getTagValues("author"));
} else if ("author" in creator.maybe.attributes) {
writeln(__LINE__, ": ", creator.maybe.attributes["author"][0].value);
}
}
}
return sdl_root_header; // sdlang.ast.Tag
}
#+END_SRC
** 2a. _sdlang to struct_
#+name: meta_conf_make_meta_sdl
#+BEGIN_SRC d
private auto docSDLtoStruct(C,Tag)(C _conf_composite, Tag header_sdlang) {
mixin SiSUregisters;
/+ make +/
if ("make" in header_sdlang.maybe.tags) {
_conf_composite.make_str.bold = _conf_composite.make.bold = extractSDLangTabOrAttrib(header_sdlang, "make", "bold");
_conf_composite.make_str.breaks = _conf_composite.make.breaks = extractSDLangTabOrAttrib(header_sdlang, "make", "breaks");
_conf_composite.make_str.cover_image = _conf_composite.make.cover_image = extractSDLangTabOrAttrib(header_sdlang, "make", "cover_image");
_conf_composite.make_str.css = _conf_composite.make.css = extractSDLangTabOrAttrib(header_sdlang, "make", "css");
_conf_composite.make_str.emphasis = _conf_composite.make.emphasis = extractSDLangTabOrAttrib(header_sdlang, "make", "emphasis");
_conf_composite.make_str.footer = _conf_composite.make.footer = extractSDLangTabOrAttrib(header_sdlang, "make", "footer");
_conf_composite.make_str.headings = _conf_composite.make.headings = extractSDLangTabOrAttrib(header_sdlang, "make", "headings");
_conf_composite.make_str.home_button_image = _conf_composite.make.home_button_image = extractSDLangTabOrAttrib(header_sdlang, "make", "home_button_image");
_conf_composite.make_str.home_button_text = _conf_composite.make.home_button_text = extractSDLangTabOrAttrib(header_sdlang, "make", "home_button_text");
_conf_composite.make_str.italics = _conf_composite.make.italics = extractSDLangTabOrAttrib(header_sdlang, "make", "italics");
_conf_composite.make_str.num_top = _conf_composite.make.num_top = extractSDLangTabOrAttrib(header_sdlang, "make", "num_top");
_conf_composite.make_str.num_depth = _conf_composite.make.num_depth = extractSDLangTabOrAttrib(header_sdlang, "make", "num_depth");
_conf_composite.make_str.substitute = _conf_composite.make.substitute = extractSDLangTabOrAttrib(header_sdlang, "make", "substitute");
_conf_composite.make_str.texpdf_font = _conf_composite.make.texpdf_font = extractSDLangTabOrAttrib(header_sdlang, "make", "texpdf_font");
}
/+ conf +/
if ("webserv" in header_sdlang.maybe.tags) {
_conf_composite.conf.webserv_url_root = extractSDLangTabOrAttrib(header_sdlang, "webserv", "url_root");
_conf_composite.conf.webserv_path = extractSDLangTabOrAttrib(header_sdlang, "webserv", "path");
_conf_composite.conf.webserv_images = extractSDLangTabOrAttrib(header_sdlang, "webserv", "images");
_conf_composite.conf.webserv_cgi = extractSDLangTabOrAttrib(header_sdlang, "webserv", "cgi");
_conf_composite.conf.webserv_cgi_host = extractSDLangTabOrAttrib(header_sdlang, "webserv", "cgi_host");
_conf_composite.conf.webserv_cgi_host_path = extractSDLangTabOrAttrib(header_sdlang, "webserv", "cgi_host_path");
_conf_composite.conf.webserv_cgi_port = extractSDLangTabOrAttrib(header_sdlang, "webserv", "cgi_port");
_conf_composite.conf.webserv_cgi_user = extractSDLangTabOrAttrib(header_sdlang, "webserv", "cgi_user");
_conf_composite.conf.webserv_cgi_file_links = extractSDLangTabOrAttrib(header_sdlang, "webserv", "cgi_file_links");
}
if ("processing" in header_sdlang.maybe.tags) {
_conf_composite.conf.processing_path = extractSDLangTabOrAttrib(header_sdlang, "webserv", "processing_path");
_conf_composite.conf.processing_dir = extractSDLangTabOrAttrib(header_sdlang, "webserv", "processing_dir");
_conf_composite.conf.processing_concord_max = extractSDLangTabOrAttrib(header_sdlang, "webserv", "processing_concord_max");
}
if("flag" in header_sdlang.maybe.tags) {
_conf_composite.conf.flag_act0 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act0");
_conf_composite.conf.flag_act1 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act1");
_conf_composite.conf.flag_act2 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act2");
_conf_composite.conf.flag_act3 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act3");
_conf_composite.conf.flag_act4 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act4");
_conf_composite.conf.flag_act5 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act5");
_conf_composite.conf.flag_act6 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act6");
_conf_composite.conf.flag_act7 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act7");
_conf_composite.conf.flag_act8 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act8");
_conf_composite.conf.flag_act9 = extractSDLangTabOrAttrib(header_sdlang, "flag", "act9");
}
if ("default" in header_sdlang.maybe.tags) {
_conf_composite.conf.default_papersize = extractSDLangTabOrAttrib(header_sdlang, "default", "papersize");
_conf_composite.conf.default_text_wrap = extractSDLangTabOrAttrib(header_sdlang, "default", "text_wrap");
_conf_composite.conf.default_emphasis = extractSDLangTabOrAttrib(header_sdlang, "default", "emphasis");
_conf_composite.conf.default_language = extractSDLangTabOrAttrib(header_sdlang, "default", "language");
_conf_composite.conf.default_digest = extractSDLangTabOrAttrib(header_sdlang, "default", "digest");
}
if ("search" in header_sdlang.maybe.tags) {
_conf_composite.conf.search_flag = extractSDLangTabOrAttrib(header_sdlang, "search", "flag");
_conf_composite.conf.search_action = extractSDLangTabOrAttrib(header_sdlang, "search", "action");
_conf_composite.conf.search_db = extractSDLangTabOrAttrib(header_sdlang, "search", "db");
_conf_composite.conf.search_title = extractSDLangTabOrAttrib(header_sdlang, "search", "title");
}
/+ meta +/
if ("classify" in header_sdlang.maybe.tags) {
_conf_composite.meta.classify_dewey = extractSDLangTabOrAttrib(header_sdlang, "classify", "dewey");
_conf_composite.meta.classify_keywords = extractSDLangTabOrAttrib(header_sdlang, "classify", "keywords");
_conf_composite.meta.classify_loc = extractSDLangTabOrAttrib(header_sdlang, "classify", "loc");
_conf_composite.meta.classify_subject = extractSDLangTabOrAttrib(header_sdlang, "classify", "subject");
_conf_composite.meta.classify_topic_register = extractSDLangTabOrAttrib(header_sdlang, "classify", "topic_register");
}
if ("date" in header_sdlang.maybe.tags) {
_conf_composite.meta.date_added_to_site = extractSDLangTabOrAttrib(header_sdlang, "date", "added_to_site");
_conf_composite.meta.date_available = extractSDLangTabOrAttrib(header_sdlang, "date", "available");
_conf_composite.meta.date_created = extractSDLangTabOrAttrib(header_sdlang, "date", "created");
_conf_composite.meta.date_issued = extractSDLangTabOrAttrib(header_sdlang, "date", "issued");
_conf_composite.meta.date_modified = extractSDLangTabOrAttrib(header_sdlang, "date", "modified");
_conf_composite.meta.date_published = extractSDLangTabOrAttrib(header_sdlang, "date", "published");
_conf_composite.meta.date_valid = extractSDLangTabOrAttrib(header_sdlang, "date", "valid");
}
if("identifier" in header_sdlang.maybe.tags) {
_conf_composite.meta.identifier_isbn = extractSDLangTabOrAttrib(header_sdlang, "identifier", "isbn");
_conf_composite.meta.identifier_oclc = extractSDLangTabOrAttrib(header_sdlang, "identifier", "oclc");
_conf_composite.meta.identifier_pg = extractSDLangTabOrAttrib(header_sdlang, "identifier", "pg");
}
if ("links" in header_sdlang.maybe.tags) {
// _conf_composite.meta.links = extractSDLangTabOrAttrib(header_sdlang, "links", "");
}
if ("notes" in header_sdlang.maybe.tags) {
_conf_composite.meta.notes_abstract = extractSDLangTabOrAttrib(header_sdlang, "notes", "abstract");
_conf_composite.meta.notes_description = extractSDLangTabOrAttrib(header_sdlang, "notes", "description");
}
if ("original" in header_sdlang.maybe.tags) {
_conf_composite.meta.original_language = extractSDLangTabOrAttrib(header_sdlang, "original", "language");
_conf_composite.meta.original_language_char = extractSDLangTabOrAttrib(header_sdlang, "original", "language_char");
_conf_composite.meta.original_source = extractSDLangTabOrAttrib(header_sdlang, "original", "source");
_conf_composite.meta.original_title = extractSDLangTabOrAttrib(header_sdlang, "original", "title");
}
if ("publisher" in header_sdlang.maybe.tags) {
// _conf_composite.meta.publisher = extractSDLangTabOrAttrib(header_sdlang, "publisher", "");
}
if ("rights" in header_sdlang.maybe.tags) {
_conf_composite.meta.rights_copyright = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright");
_conf_composite.meta.rights_copyright_text = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_text");
_conf_composite.meta.rights_copyright_audio = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_audio");
_conf_composite.meta.rights_copyright_cover = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_cover");
_conf_composite.meta.rights_copyright_illustrations = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_illustrations");
_conf_composite.meta.rights_copyright_photographs = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_photographs");
_conf_composite.meta.rights_copyright_translation = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_translation");
_conf_composite.meta.rights_copyright_video = extractSDLangTabOrAttrib(header_sdlang, "rights", "copyright_video");
_conf_composite.meta.rights_license = extractSDLangTabOrAttrib(header_sdlang, "rights", "license");
}
if (_conf_composite.meta.creator_author.empty) {
if ("creator" in header_sdlang.maybe.tags) {
_conf_composite.meta.creator_author = extractSDLangTabOrAttrib(header_sdlang, "creator", "author");
_conf_composite.meta.creator_author_email = extractSDLangTabOrAttrib(header_sdlang, "creator", "author_email");
_conf_composite.meta.creator_illustrator = extractSDLangTabOrAttrib(header_sdlang, "creator", "illustrator");
_conf_composite.meta.creator_translator = extractSDLangTabOrAttrib(header_sdlang, "creator", "translator");
}
// dochead_meta["creator"]["author_raw"] = dochead_meta["creator"]["author"];
string[] authors_arr;
auto authors_raw_arr = _conf_composite.meta.creator_author.split(rgx.arr_delimiter);
foreach (author_raw; authors_raw_arr) {
authors_arr ~= author_raw.replace(rgx.raw_author_munge, "$2 $1");
}
_conf_composite.meta.creator_author = join(authors_arr, ", ").chomp.chomp;
}
if (_conf_composite.meta.title_main.empty) {
if ("title" in header_sdlang.maybe.tags) {
_conf_composite.meta.title_edition = extractSDLangTabOrAttrib(header_sdlang, "title", "edition");
_conf_composite.meta.title_language = extractSDLangTabOrAttrib(header_sdlang, "title", "language");
_conf_composite.meta.title_main = extractSDLangTabOrAttrib(header_sdlang, "title", "main");
_conf_composite.meta.title_note = extractSDLangTabOrAttrib(header_sdlang, "title", "note");
_conf_composite.meta.title_sub = extractSDLangTabOrAttrib(header_sdlang, "title", "sub");
_conf_composite.meta.title_subtitle = extractSDLangTabOrAttrib(header_sdlang, "title", "subtitle");
}
if (_conf_composite.meta.title_main.empty) {
Tag _maintag = header_sdlang.getTag("title");
if (_maintag !is null) {
if ("main" in _maintag.maybe.tags) {
_conf_composite.meta.title_main
= to!string(_maintag.getTagValues("main"));
} else if ("main" !in _maintag.maybe.attributes) {
writeln(_maintag.values[0]); // document title
_conf_composite.meta.title_main
= (_maintag.values[0]).to!string; // test that this exists
}
}
}
if ((!(_conf_composite.meta.title_subtitle.empty))
&& (_conf_composite.meta.title_sub.empty)) {
_conf_composite.meta.title_sub = _conf_composite.meta.title_subtitle;
}
if (_conf_composite.meta.title_sub.empty) {
_conf_composite.meta.title_full = _conf_composite.meta.title_main;
} else {
_conf_composite.meta.title_full = format(
"%s - %s",
_conf_composite.meta.title_main,
_conf_composite.meta.title_sub,
);
}
}
return _conf_composite;
}
#+END_SRC
* C. module conf files make composite
** TODO 0. module template
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_composite.d
/++
return composite make from config files
+/
module sdp.meta.conf_make_meta_composite;
<<meta_conf_make_meta_composite_struct>>
template confFilesSDLtoStruct() {
import
std.exception,
std.regex,
std.stdio,
std.string,
std.traits,
std.typecons,
std.utf,
std.conv : to;
import
sdp.meta.defaults,
sdp.meta.rgx;
<<meta_conf_make_meta_composite>>
}
#+END_SRC
** module template
#+name: meta_conf_make_meta_composite
#+BEGIN_SRC d
auto confFilesSDLtoStruct(S,L)(
S sdl_root_config_share,
L sdl_root_config_local,
){
mixin SiSUregisters;
ConfCompositePlus _conf_composite;
foreach (conf_sdlang; [sdl_root_config_share, sdl_root_config_local]) {
if ("make" in conf_sdlang.maybe.tags) {
_conf_composite.make_str.bold = _conf_composite.make.bold = extractSDLangTabOrAttrib(conf_sdlang, "make", "bold");
_conf_composite.make_str.breaks = _conf_composite.make.breaks = extractSDLangTabOrAttrib(conf_sdlang, "make", "breaks");
_conf_composite.make_str.cover_image = _conf_composite.make.cover_image = extractSDLangTabOrAttrib(conf_sdlang, "make", "cover_image");
_conf_composite.make_str.css = _conf_composite.make.css = extractSDLangTabOrAttrib(conf_sdlang, "make", "css");
_conf_composite.make_str.emphasis = _conf_composite.make.emphasis = extractSDLangTabOrAttrib(conf_sdlang, "make", "emphasis");
_conf_composite.make_str.footer = _conf_composite.make.footer = extractSDLangTabOrAttrib(conf_sdlang, "make", "footer");
_conf_composite.make_str.headings = _conf_composite.make.headings = extractSDLangTabOrAttrib(conf_sdlang, "make", "headings");
_conf_composite.make_str.home_button_image = _conf_composite.make.home_button_image = extractSDLangTabOrAttrib(conf_sdlang, "make", "home_button_image");
_conf_composite.make_str.home_button_text = _conf_composite.make.home_button_text = extractSDLangTabOrAttrib(conf_sdlang, "make", "home_button_text");
_conf_composite.make_str.italics = _conf_composite.make.italics = extractSDLangTabOrAttrib(conf_sdlang, "make", "italics");
_conf_composite.make_str.num_top = _conf_composite.make.num_top = extractSDLangTabOrAttrib(conf_sdlang, "make", "num_top");
_conf_composite.make_str.num_depth = _conf_composite.make.num_depth = extractSDLangTabOrAttrib(conf_sdlang, "make", "num_depth");
_conf_composite.make_str.substitute = _conf_composite.make.substitute = extractSDLangTabOrAttrib(conf_sdlang, "make", "substitute");
_conf_composite.make_str.texpdf_font = _conf_composite.make.texpdf_font = extractSDLangTabOrAttrib(conf_sdlang, "make", "texpdf_font");
}
}
return _conf_composite;
}
#+END_SRC
** initialize / imports
#+name: imports
#+BEGIN_SRC d
import sdp.meta;
import std.array;
#+END_SRC
|