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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
|
#+TITLE: sdp config & header (make & meta) 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. generic
** imports
#+name: meta_defaults_imports
#+BEGIN_SRC d
import
std.algorithm,
std.array,
std.container,
std.exception,
std.file,
std.getopt,
std.json,
std.path,
std.process,
std.range,
std.regex,
std.stdio,
std.string,
std.traits,
std.typecons,
std.uni,
std.utf,
std.conv : to;
import sdp.meta.conf_make_meta_structs;
#+END_SRC
** struct ConfComposite
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_structs.d
module sdp.meta.conf_make_meta_structs;
import
std.exception,
std.json,
std.regex,
std.stdio,
std.string,
std.traits,
std.typecons,
std.utf,
std.conv : to;
<<meta_defaults_template_structs>>
#+END_SRC
** struct Generic ConfComposite
#+name: meta_defaults_template_structs
#+BEGIN_SRC d
struct ConfCompositeMakeStr {
string bold = "";
string breaks = "";
string cover_image = "";
string css = "";
string emphasis = "";
string footer = "";
string headings = "";
string home_button_image = "";
string home_button_text = "";
string italics = "";
string num_top = "";
string num_depth = "";
JSONValue substitute = JSONValue( ["", ""] );
string texpdf_font = "";
}
struct confCompositeMakeBuild {
auto bold_rgxmatch(string _mk) {
auto _rgxtxt = (_mk.empty)
? `=NULL`
: `(` ~ _mk.dup ~ `)`;
return (cast(char[]) (_rgxtxt));
}
auto bold_substitute_abstract() {
return "*{$1}*";
}
auto bold_substitute_sisu_markup() {
return "*{$1}*";
}
auto bold_substitute_html() {
return "<b>$1</b>";
}
auto breaks(string _mk) {
return _mk;
}
auto cover_image(string _mk) {
return _mk;
}
auto css(string _mk) {
return _mk;
}
auto emphasis_rgxmatch(string _mk) {
auto _rgxtxt = (_mk.empty)
? `=NULL`
: `(` ~ _mk.dup ~ `)`;
return (cast(char[]) (_rgxtxt));
}
auto emphasis_substitute_abstract() {
return "!{$1}!";
}
auto emphasis_substitute_sisu_markup() {
return "!{$1}!";
}
auto emphasis_substitute_html() {
return "<em>$1</em>";
}
auto footer(string _mk) {
return _mk;
}
auto headings(string _mk) {
return _mk;
}
auto home_button_image(string _mk) {
return _mk;
}
auto home_button_text(string _mk) {
return _mk;
}
auto italics_rgxmatch(string _mk) {
auto _rgxtxt = (_mk.empty)
? `=NULL`
: `(` ~ _mk.dup ~ `)`;
return (cast(char[]) (_rgxtxt));
}
auto italics_substitute_abstract() {
return "/{$1}/";
}
auto italics_substitute_sisu_markup() {
return "/{$1}/";
}
auto italics_substitute_html() {
return "<i>$1</i>";
}
auto num_top(string _mk) {
return _mk;
}
auto num_depth(string _mk) {
return _mk;
}
auto substitute(JSONValue _mk) {
return _mk;
}
auto texpdf_font(string _mk) {
return _mk;
}
}
#+END_SRC
** initialize make & meta
*** composite make
#+name: meta_defaults_template_structs
#+BEGIN_SRC d
struct ConfCompositeMakeInit {
char[] bold_rgxmatch = `=NULL`.dup;
auto bold_substitute_abstract = "*{$1}*";
auto bold_substitute_sisu_markup = "*{$1}*";
auto bold_substitute_html = "<b>$1</b>";
string breaks = "";
string cover_image = "";
string css = "";
char[] emphasis_rgxmatch = `=NULL`.dup;
auto emphasis_substitute_abstract = "!{$1}!";
auto emphasis_substitute_sisu_markup = "!{$1}!";
auto emphasis_substitute_html = "<em>$1</em>";
string footer = "";
string headings = "";
string home_button_image = "";
string home_button_text = "";
char[] italics_rgxmatch = `=NULL`.dup;
auto italics_substitute_abstract = "/{$1}/";
auto italics_substitute_sisu_markup = "/{$1}/";
auto italics_substitute_html = "<i>$1</i>";
string num_top = "";
string num_depth = "";
auto substitute = JSONValue(["", ""]);
string texpdf_font = "";
}
#+END_SRC
*** conf site local
#+name: meta_defaults_template_structs
#+BEGIN_SRC d
struct ConfCompositeSiteLocal {
string webserv_url_root = "";
string webserv_path = "";
string webserv_images = "";
string webserv_cgi = "";
string webserv_cgi_host = "";
string webserv_cgi_host_path = "";
string webserv_cgi_port = "";
string webserv_cgi_user = "";
string webserv_cgi_file_links = "";
string processing_path = "";
string processing_dir = "";
string processing_concord_max = "";
string flag_act0 = "";
string flag_act1 = "";
string flag_act2 = "";
string flag_act3 = "";
string flag_act4 = "";
string flag_act5 = "";
string flag_act6 = "";
string flag_act7 = "";
string flag_act8 = "";
string flag_act9 = "";
string default_papersize = "";
string default_text_wrap = "";
string default_emphasis = "";
string default_language = "";
string default_digest = "";
string permission_share_source = "";
string search_flag = "";
string search_action = "";
string search_db = "";
string search_title = "";
}
#+END_SRC
*** composite meta
#+name: meta_defaults_template_structs
#+BEGIN_SRC d
struct MetaComposite {
string classify_dewey = "";
string classify_keywords = "";
string classify_loc = "";
string classify_subject = "";
string classify_topic_register = "";
string creator_author = "";
string creator_author_email = "";
string creator_illustrator = "";
string creator_translator = "";
string date_added_to_site = "";
string date_available = "";
string date_created = "";
string date_issued = "";
string date_modified = "";
string date_published = "";
string date_valid = "";
string identifier_isbn = "";
string identifier_oclc = "";
string identifier_pg = "";
string language_document = "";
string language_document_char = "";
string links = "";
string notes_abstract = "";
string notes_description = "";
string original_language = "";
string original_language_char = "";
string original_publisher = "";
string original_source = "";
string original_title = "";
string publisher = "";
string rights_copyright = "";
string rights_copyright_audio = "";
string rights_copyright_cover = "";
string rights_copyright_illustrations = "";
string rights_copyright_photographs = "";
string rights_copyright_text = "";
string rights_copyright_translation = "";
string rights_copyright_video = "";
string rights_license = "";
string title_edition = "";
string title_full = "";
string title_language = "";
string title_main = "";
string title_note = "";
string title_short = "";
string title_sub = "";
string title_subtitle = "";
}
#+END_SRC
*** composite structs
#+name: meta_defaults_template_structs
#+BEGIN_SRC d
struct ConfComposite {
MetaComposite meta;
ConfCompositeMakeInit make;
ConfCompositeSiteLocal conf;
}
struct ConfCompositePlus {
MetaComposite meta;
ConfCompositeMakeInit make;
ConfCompositeMakeStr make_str;
ConfCompositeSiteLocal conf;
}
#+END_SRC
*** metadata associative array indexes :header:
#+name: meta_defaults_template_structs
#+BEGIN_SRC d
static auto ptr_head_main
= [
"classify",
"creator",
"date",
"identifier",
"links",
"make",
"original",
"notes",
"rights",
"title"
];
static auto ptr_head_sub_classify
= [
"dewey",
"keywords",
"loc",
"subject",
"topic_register"
];
static auto ptr_head_sub_creator
= [
"author",
"author_email",
"cover",
"illustrator",
"translator"
];
static auto ptr_head_sub_date
= [
"added_to_site",
"available",
"created",
"issued",
"modified",
"published",
"valid"
];
static auto ptr_head_sub_identifier
= [
"isbn",
"oclc",
"pg"
];
/+ make +/
static auto ptr_head_sub_make
= [
"cover_image",
"home_button_image",
"home_button_text",
"footer", "headings",
"num_top", "num_depth",
"breaks",
"substitute",
"bold",
"italics",
"emphasis",
"texpdf_font",
"css"
];
static auto ptr_head_sub_notes
= [
"abstract",
"description"
];
static auto ptr_head_sub_original
= [
"language",
"source",
"title"
];
static auto ptr_head_sub_publisher
= [ "name" ];
static auto ptr_head_sub_rights
= [
"copyright",
"cover",
"illustrations",
"license"
];
static auto ptr_head_sub_title
= [
"edition",
"full",
"language",
"main",
"note",
"sub"
];
auto config_jsonstr = `{
}`;
#+END_SRC
* 1. JSON to SiSUstruct
** 1. module json :module:sdp:meta_conf_make_meta_json:
*** 0. module template
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_json.d
/++
json headers<BR>
extract json header return json
+/
module sdp.meta.conf_make_meta_json;
static template contentJSONtoSiSUstruct() {
import
std.exception,
std.regex,
std.stdio,
std.string,
std.traits,
std.typecons,
std.utf,
std.conv : to;
import
sdp.meta.conf_make_meta_structs,
sdp.meta.conf_make_meta_json,
sdp.meta.rgx;
ConfCompositePlus _struct_composite;
auto contentJSONtoSiSUstruct(C, J)(C _struct_composite, J _json, string _identifier) {
mixin SiSUrgxInit;
static auto _rgx = Rgx();
debug (json) {
writeln(">> --------------------------- >>");
foreach (tag0; _json.object.byKeyValue) {
if (tag0.value.stringof == "string") {
writeln(tag0.key, ": ", tag0.value);
} else {
// writeln(tag0.key, ":");
foreach (tag1; tag0.value.object.byKeyValue) {
writeln(tag0.key, ":", tag1.key, ": ", tag1.value);
}
}
}
writeln("<< --------------------------- <<");
}
confCompositeMakeBuild _mk;
<<json_objects>>
return _struct_composite;
}
}
#+END_SRC
*** make
#+name: json_objects
#+BEGIN_SRC d
/+ make ------------------------------------------------------------------- +/
if ("make" in _json.object) {
if ("bold" in _json.object["make"]) {
_struct_composite.make_str.bold = _json.object["make"]["bold"].str;
}
if ("breaks" in _json.object["make"]) {
_struct_composite.make_str.breaks = _json.object["make"]["breaks"].str;
}
if ("cover_image" in _json.object["make"]) {
_struct_composite.make_str.cover_image = _json.object["make"]["cover_image"].str;
}
if ("css" in _json.object["make"]) {
_struct_composite.make_str.css = _json.object["make"]["css"].str;
}
if ("emphasis" in _json.object["make"]) {
_struct_composite.make_str.emphasis = _json.object["make"]["emphasis"].str;
}
if ("footer" in _json.object["make"]) {
_struct_composite.make_str.footer = _json.object["make"]["footer"].str;
}
if ("headings" in _json.object["make"]) {
_struct_composite.make_str.headings = _json.object["make"]["headings"].str;
}
if ("home_button_image" in _json.object["make"]) {
_struct_composite.make_str.home_button_image = _json.object["make"]["home_button_image"].str;
}
if ("home_button_text" in _json.object["make"]) {
_struct_composite.make_str.home_button_text = _json.object["make"]["home_button_text"].str;
}
if ("italics" in _json.object["make"]) {
_struct_composite.make_str.italics = _json.object["make"]["italics"].str;
}
if ("num_top" in _json.object["make"]) {
_struct_composite.make_str.num_top = _json.object["make"]["num_top"].str;
}
if ("num_depth" in _json.object["make"]) {
_struct_composite.make_str.num_depth = _json.object["num_depth"][""].str;
}
if ("substitute" in _json.object["make"]) {
_struct_composite.make_str.substitute = _json.object["make"]["substitute"].arrayNoRef;
}
if ("texpdf_font" in _json.object["make"]) {
_struct_composite.make_str.texpdf_font = _json.object["make"]["texpdf_font"].str;
}
_struct_composite.make.bold_rgxmatch = _mk.bold_rgxmatch(_struct_composite.make_str.bold);
_struct_composite.make.breaks = _mk.breaks(_struct_composite.make_str.breaks);
_struct_composite.make.cover_image = _mk.cover_image(_struct_composite.make_str.cover_image);
_struct_composite.make.css = _mk.css(_struct_composite.make_str.css);
_struct_composite.make.emphasis_rgxmatch = _mk.emphasis_rgxmatch(_struct_composite.make_str.emphasis);
_struct_composite.make.footer = _mk.footer(_struct_composite.make_str.footer);
_struct_composite.make.headings = _mk.headings(_struct_composite.make_str.headings);
_struct_composite.make.home_button_image = _mk.home_button_image(_struct_composite.make_str.home_button_image);
_struct_composite.make.home_button_text = _mk.home_button_text(_struct_composite.make_str.home_button_text);
_struct_composite.make.italics_rgxmatch = _mk.italics_rgxmatch(_struct_composite.make_str.italics);
_struct_composite.make.num_top = _mk.num_top(_struct_composite.make_str.num_top);
_struct_composite.make.num_depth = _mk.num_depth(_struct_composite.make_str.num_depth);
_struct_composite.make.substitute = _mk.substitute(_struct_composite.make_str.substitute);
_struct_composite.make.texpdf_font = _mk.texpdf_font(_struct_composite.make_str.texpdf_font);
}
#+END_SRC
*** conf
#+name: json_objects
#+BEGIN_SRC d
/+ conf ------------------------------------------------------------------- +/
if ("webserv" in _json.object) {
if ("url_root" in _json.object["webserv"]) {
_struct_composite.conf.webserv_url_root = _json.object["webserv"]["url_root"].str;
}
if ("path" in _json.object["webserv"]) {
_struct_composite.conf.webserv_path = _json.object["webserv"]["path"].str;
}
if ("images" in _json.object["webserv"]) {
_struct_composite.conf.webserv_images = _json.object["webserv"]["images"].str;
}
if ("cgi" in _json.object["webserv"]) {
_struct_composite.conf.webserv_cgi = _json.object["webserv"]["cgi"].str;
}
if ("cgi_host" in _json.object["webserv"]) {
_struct_composite.conf.webserv_cgi_host = _json.object["webserv"]["cgi_host"].str;
}
if ("cgi_host_path" in _json.object["webserv"]) {
_struct_composite.conf.webserv_cgi_host_path = _json.object["webserv"]["cgi_host_path"].str;
}
if ("cgi_port" in _json.object["webserv"]) {
_struct_composite.conf.webserv_cgi_port = _json.object["webserv"]["cgi_port"].str;
}
if ("cgi_user" in _json.object["webserv"]) {
_struct_composite.conf.webserv_cgi_user = _json.object["webserv"]["cgi_user"].str;
}
if ("cgi_file_links" in _json.object["webserv"]) {
_struct_composite.conf.webserv_cgi_file_links = _json.object["webserv"]["cgi_file_links"].str;
}
}
if ("processing" in _json.object) { // TODO check & match logic with sdlang
if ("path" in _json.object["processing"]) {
_struct_composite.conf.processing_path = _json.object["processing"]["path"].str;
}
if ("dir" in _json.object["processing"]) {
_struct_composite.conf.processing_dir = _json.object["processing"]["dir"].str;
}
if ("concord_max" in _json.object["processing"]) {
_struct_composite.conf.processing_concord_max = _json.object["processing"]["concord_max"].str;
}
}
if ("flag" in _json.object) {
if ("act0" in _json.object["flag"]) {
_struct_composite.conf.flag_act0 = _json.object["flag"]["act0"].str;
}
if ("act1" in _json.object["flag"]) {
_struct_composite.conf.flag_act1 = _json.object["flag"]["act1"].str;
}
if ("act2" in _json.object["flag"]) {
_struct_composite.conf.flag_act2 = _json.object["flag"]["act2"].str;
}
if ("act3" in _json.object["flag"]) {
_struct_composite.conf.flag_act3 = _json.object["flag"]["act3"].str;
}
if ("act4" in _json.object["flag"]) {
_struct_composite.conf.flag_act4 = _json.object["flag"]["act4"].str;
}
if ("act5" in _json.object["flag"]) {
_struct_composite.conf.flag_act5 = _json.object["flag"]["act5"].str;
}
if ("act6" in _json.object["flag"]) {
_struct_composite.conf.flag_act6 = _json.object["flag"]["act6"].str;
}
if ("act7" in _json.object["flag"]) {
_struct_composite.conf.flag_act7 = _json.object["flag"]["act7"].str;
}
if ("act8" in _json.object["flag"]) {
_struct_composite.conf.flag_act8 = _json.object["flag"]["act8"].str;
}
if ("act9" in _json.object["flag"]) {
_struct_composite.conf.flag_act9 = _json.object["flag"]["act9"].str;
}
}
if ("default" in _json.object) {
if ("papersize" in _json.object["default"]) {
_struct_composite.conf.default_papersize = _json.object["default"]["papersize"].str;
}
if ("text_wrap" in _json.object["default"]) {
_struct_composite.conf.default_text_wrap = _json.object["default"]["text_wrap"].str;
}
if ("emphasis" in _json.object["default"]) {
_struct_composite.conf.default_emphasis = _json.object["default"]["emphasis"].str;
}
if ("language" in _json.object["default"]) {
_struct_composite.conf.default_language = _json.object["default"]["language"].str;
}
if ("digest" in _json.object["default"]) {
_struct_composite.conf.default_digest = _json.object["default"]["digest"].str;
}
}
if ("search" in _json.object) {
if ("flag" in _json.object["search"]) {
_struct_composite.conf.search_flag = _json.object["search"]["flag"].str;
}
if ("action" in _json.object["search"]) {
_struct_composite.conf.search_action = _json.object["search"]["action"].str;
}
if ("db" in _json.object["search"]) {
_struct_composite.conf.search_db = _json.object["search"]["db"].str;
}
if ("title" in _json.object["search"]) {
_struct_composite.conf.search_title = _json.object["search"]["title"].str;
}
}
#+END_SRC
*** meta
#+name: json_objects
#+BEGIN_SRC d
/+ meta ------------------------------------------------------------------- +/
if ("classify" in _json.object) {
if ("dewey" in _json.object["classify"]) {
_struct_composite.meta.classify_dewey = _json.object["classify"]["dewey"].str;
}
if ("keywords" in _json.object["classify"]) {
_struct_composite.meta.classify_keywords = _json.object["classify"]["keywords"].str;
}
if ("loc" in _json.object["classify"]) {
_struct_composite.meta.classify_loc = _json.object["classify"]["loc"].str;
}
if ("subject" in _json.object["classify"]) {
_struct_composite.meta.classify_subject = _json.object["classify"]["subject"].str;
}
if ("topic_register" in _json.object["classify"]) {
_struct_composite.meta.classify_topic_register = _json.object["classify"]["topic_register"].str;
}
}
if ("date" in _json.object) {
if ("added_to_site" in _json.object["date"]) {
_struct_composite.meta.date_added_to_site = _json.object["date"]["added_to_site"].str;
}
if ("available" in _json.object["date"]) {
_struct_composite.meta.date_available = _json.object["date"]["available"].str;
}
if ("created" in _json.object["date"]) {
_struct_composite.meta.date_created = _json.object["date"]["created"].str;
}
if ("issued" in _json.object["date"]) {
_struct_composite.meta.date_issued = _json.object["date"]["issued"].str;
}
if ("modified" in _json.object["date"]) {
_struct_composite.meta.date_modified = _json.object["date"]["modified"].str;
}
if ("published" in _json.object["date"]) {
_struct_composite.meta.date_published = _json.object["date"]["published"].str;
}
if ("valid" in _json.object["date"]) {
_struct_composite.meta.date_valid = _json.object["date"]["valid"].str;
}
}
if ("links" in _json.object) {
// if ("" in _json.object["links"]) {
// _struct_composite.meta.links_ = _json.object["links"][""].str;
// }
}
if ("notes" in _json.object) {
if ("abstract" in _json.object["notes"]) {
_struct_composite.meta.notes_abstract = _json.object["notes"]["abstract"].str;
}
if ("description" in _json.object["notes"]) {
_struct_composite.meta.notes_description = _json.object["notes"]["description"].str;
}
}
if ("original" in _json.object) {
if ("language" in _json.object["original"]) {
_struct_composite.meta.original_language = _json.object["original"]["language"].str;
}
if ("language_char" in _json.object["original"]) {
_struct_composite.meta.original_language_char = _json.object["original"]["language_char"].str;
}
if ("source" in _json.object["original"]) {
_struct_composite.meta.original_source = _json.object["original"]["source"].str;
}
if ("title" in _json.object["original"]) {
_struct_composite.meta.original_title = _json.object["original"]["title"].str;
}
}
if ("publisher" in _json.object) {
// if ("" in _json.object["publisher"]) {
// _struct_composite.meta.publisher = _json.object["publisher"][""].str;
// }
}
if ("rights" in _json.object) {
if ("copyright" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright = _json.object["rights"]["copyright"].str;
}
if ("copyright_text" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_text = _json.object["rights"]["copyright_text"].str;
}
if ("copyright_audio" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_audio = _json.object["rights"]["copyright_audio"].str;
}
if ("copyright_cover" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_cover = _json.object["rights"]["copyright_cover"].str;
}
if ("copyright_illustrations" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_illustrations = _json.object["rights"]["copyright_illustrations"].str;
}
if ("copyright_photographs" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_photographs = _json.object["rights"]["copyright_photographs"].str;
}
if ("copyright_translation" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_translation = _json.object["rights"]["copyright_translation"].str;
}
if ("copyright_video" in _json.object["rights"]) {
_struct_composite.meta.rights_copyright_video = _json.object["rights"]["copyright_video"].str;
}
if ("license" in _json.object["rights"]) {
_struct_composite.meta.rights_license = _json.object["rights"]["license"].str;
}
}
if (_struct_composite.meta.creator_author.empty) {
if ("creator" in _json.object) {
if ("author" in _json.object["creator"]) {
_struct_composite.meta.creator_author = _json.object["creator"]["author"].str;
}
if ("email" in _json.object["creator"]) {
_struct_composite.meta.creator_author_email = _json.object["creator"]["email"].str;
}
if ("illustrator" in _json.object["creator"]) {
_struct_composite.meta.creator_illustrator = _json.object["creator"]["illustrator"].str;
}
if ("translator" in _json.object["creator"]) {
_struct_composite.meta.creator_translator = _json.object["creator"]["translator"].str;
}
}
// dochead_meta["creator"]["author_raw"] = dochead_meta["creator"]["author"];
string[] authors_arr;
auto authors_raw_arr = _struct_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");
}
_struct_composite.meta.creator_author = join(authors_arr, ", ").chomp.chomp;
}
if (_struct_composite.meta.title_main.empty) {
if ("title" in _json.object) {
if ((_json.object["title"].type().to!string) == "STRING") {
_struct_composite.meta.title_main = _json.object["title"].str;
} else {
if ("edition" in _json.object["title"]) {
_struct_composite.meta.title_edition = _json.object["title"]["edition"].str;
}
if ("full" in _json.object["title"]) {
// _struct_composite.meta.title_full = _json.object["title"]["full"].str;
}
if ("language" in _json.object["title"]) {
_struct_composite.meta.title_language = _json.object["title"]["language"].str;
}
if ("main" in _json.object["title"]) {
_struct_composite.meta.title_main = _json.object["title"]["main"].str;
}
if ("note" in _json.object["title"]) {
_struct_composite.meta.title_note = _json.object["title"]["note"].str;
}
if ("sub" in _json.object["title"]) {
_struct_composite.meta.title_sub = _json.object["title"]["sub"].str;
}
if ("subtitle" in _json.object["title"]) {
_struct_composite.meta.title_subtitle = _json.object["title"]["subtitle"].str;
}
}
}
if ((!(_struct_composite.meta.title_subtitle.empty))
&& (_struct_composite.meta.title_sub.empty)) {
_struct_composite.meta.title_sub = _struct_composite.meta.title_subtitle;
}
_struct_composite.meta.title_full = (_struct_composite.meta.title_sub.empty)
? _struct_composite.meta.title_main
: format(
"%s - %s",
_struct_composite.meta.title_main,
_struct_composite.meta.title_sub,
);
}
#+END_SRC
* 2. TOML returns SiSUstruct (via JSON) :module:sdp:meta_conf_make_meta:
** 0. parse TOML config return JSON
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_toml.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_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;
}
}
#+END_SRC
** 1. parse TOML config to JSON return SiSUstruct
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_toml.d
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;
}
}
#+END_SRC
** 2. parse TOML header to JSON then Struct
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_toml.d
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;
}
}
#+END_SRC
* 3. SDLang to SiSUstruct
** 1. header extract (sdlang) to Struct :module:sdp:meta_conf_make_meta:
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_sdlang.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_sdlang;
static template docHeaderMakeAndMetaTupSDLangExtractAndConvertToStruct() {
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 docHeaderMakeAndMetaTupSDLangExtractAndConvertToStruct(CCm, Src)(
CCm conf_composite_make,
Src header_src,
) {
auto header_sdlang_tag = (header_src.match(rgx.sdlang_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
** 2. module sdlang :module:sdp:meta_conf_make_meta_sdlang:
*** 0. module template
**** 1. extract sdlang
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_sdlang.d
/++
sdlang headers<BR>
extract sdlang header return 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.conf_make_meta_structs,
sdp.meta.rgx;
struct extractSDL {
mixin SiSUmakeMetaStructsSDLang;
mixin SiSUrgxInit;
static auto rgx = Rgx();
<<meta_conf_make_meta_sdl_extract>>
private auto docSDLtoStruct(C,Tag)(C _conf_composite, Tag header_sdlang) { // work on
<<meta_conf_make_meta_sdl>>
return _conf_composite;
}
}
}
#+END_SRC
**** 2. extract sdlang
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_sdlang.d
static template parseSDLangConfig() {
import
std.exception,
std.regex,
std.stdio,
std.string,
std.traits,
std.typecons,
std.utf,
std.conv : to;
import sdlang;
<<meta_config_file_sdlang_test>>
}
#+END_SRC
*** 1. sdlang root tag _extract root Tag_ :sdlang:root:tag:
**** 1. header
#+name: meta_conf_make_meta_sdl_extract
#+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
**** 2. conf & make
#+name: meta_config_file_sdlang_test
#+BEGIN_SRC d
auto parseSDLangConfig(string configuration, string conf_sdl_filename) {
Tag sdl_root_conf;
try {
sdl_root_conf = parseSource(configuration);
}
catch(ParseException e) {
stderr.writeln("SDLang problem with content for ", conf_sdl_filename);
stderr.writeln(e.msg);
}
return sdl_root_conf;
}
#+END_SRC
*** 2. _sdlang to struct_
**** make
#+name: meta_conf_make_meta_sdl
#+BEGIN_SRC d
/+ make ------------------------------------------------------------------- +/
if ("make" in header_sdlang.maybe.tags) {
confCompositeMakeBuild _mk;
_conf_composite.make_str.bold = extractSDLangTabOrAttrib(header_sdlang, "make", "bold"); // TODO
_conf_composite.make_str.breaks = extractSDLangTabOrAttrib(header_sdlang, "make", "breaks");
_conf_composite.make_str.cover_image = extractSDLangTabOrAttrib(header_sdlang, "make", "cover_image");
_conf_composite.make_str.css = extractSDLangTabOrAttrib(header_sdlang, "make", "css");
_conf_composite.make_str.emphasis = extractSDLangTabOrAttrib(header_sdlang, "make", "emphasis"); // TODO
_conf_composite.make_str.footer = extractSDLangTabOrAttrib(header_sdlang, "make", "footer");
_conf_composite.make_str.headings = extractSDLangTabOrAttrib(header_sdlang, "make", "headings");
_conf_composite.make_str.home_button_image = extractSDLangTabOrAttrib(header_sdlang, "make", "home_button_image");
_conf_composite.make_str.home_button_text = extractSDLangTabOrAttrib(header_sdlang, "make", "home_button_text");
_conf_composite.make_str.italics = extractSDLangTabOrAttrib(header_sdlang, "make", "italics"); // TODO
_conf_composite.make_str.num_top = extractSDLangTabOrAttrib(header_sdlang, "make", "num_top");
_conf_composite.make_str.num_depth = extractSDLangTabOrAttrib(header_sdlang, "make", "num_depth");
_conf_composite.make_str.substitute = extractSDLangTabOrAttrib(header_sdlang, "make", "substitute"); // TODO
_conf_composite.make_str.texpdf_font = extractSDLangTabOrAttrib(header_sdlang, "make", "texpdf_font");
_conf_composite.make.bold_rgxmatch = _mk.bold_rgxmatch(_conf_composite.make_str.bold);
_conf_composite.make.breaks = _mk.breaks(_conf_composite.make_str.breaks);
_conf_composite.make.cover_image = _mk.cover_image(_conf_composite.make_str.cover_image);
_conf_composite.make.css = _mk.css(_conf_composite.make_str.css);
_conf_composite.make.emphasis_rgxmatch = _mk.emphasis_rgxmatch(_conf_composite.make_str.emphasis);
_conf_composite.make.footer = _mk.footer(_conf_composite.make_str.footer);
_conf_composite.make.headings = _mk.headings(_conf_composite.make_str.headings);
_conf_composite.make.home_button_image = _mk.home_button_image(_conf_composite.make_str.home_button_image);
_conf_composite.make.home_button_text = _mk.home_button_text(_conf_composite.make_str.home_button_text);
_conf_composite.make.italics_rgxmatch = _mk.italics_rgxmatch(_conf_composite.make_str.italics);
_conf_composite.make.num_top = _mk.num_top(_conf_composite.make_str.num_top);
_conf_composite.make.num_depth = _mk.num_depth(_conf_composite.make_str.num_depth);
_conf_composite.make.substitute = _mk.substitute(_conf_composite.make_str.substitute);
_conf_composite.make.texpdf_font = _mk.texpdf_font(_conf_composite.make_str.texpdf_font);
}
#+END_SRC
**** conf
#+name: meta_conf_make_meta_sdl
#+BEGIN_SRC d
/+ 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");
}
#+END_SRC
**** meta
#+name: meta_conf_make_meta_sdl
#+BEGIN_SRC d
/+ 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_full = extractSDLangTabOrAttrib(header_sdlang, "title", "full");
_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) {
_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;
}
_conf_composite.meta.title_full = (_conf_composite.meta.title_sub.empty)
? _conf_composite.meta.title_main
: format(
"%s - %s",
_conf_composite.meta.title_main,
_conf_composite.meta.title_sub,
);
}
#+END_SRC
** 3. module conf files make composite
*** TODO 0. module template
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_sdlang.d
/++
return composite make from config files
+/
<<meta_conf_make_meta_sdl_to_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.conf_make_meta_structs,
sdp.meta.rgx;
<<meta_conf_make_meta_sdl_to_composite>>
}
#+END_SRC
*** _sdlang to parse_ composite make
#+name: meta_conf_make_meta_sdl_to_composite
#+BEGIN_SRC d
auto configParseSDL(T)(
T _text
){
Tag sdl_root;
try {
sdl_root = parseSource(_text.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.toSDLDocument());
writeln(__LINE__, ": ", sdl_root.maybe.namespaces);
writeln("header make sdlang: ", sdl_root.toSDLDocument());
writeln(__LINE__, ": ", sdl_root.getTagValues("title"));
writeln(__LINE__, ": ", sdl_root.getTagValues("creator"));
Tag creator = sdl_root.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; // sdlang.ast.Tag
}
#+END_SRC
*** _sdlang to struct_ composite make
#+name: meta_conf_make_meta_sdl_to_composite
#+BEGIN_SRC d
auto confFilesSDLtoStruct(S,L)(
S sdl_root_config_share,
L sdl_root_config_local,
){
mixin SiSUmakeMetaStructsSDLang;
ConfCompositePlus _conf_composite;
foreach (conf_sdlang; [sdl_root_config_share, sdl_root_config_local]) {
if ("make" in conf_sdlang.maybe.tags) {
confCompositeMakeBuild _mk;
_conf_composite.make_str.bold = extractSDLangTabOrAttrib(conf_sdlang, "make", "bold"); // TODO
_conf_composite.make_str.breaks = extractSDLangTabOrAttrib(conf_sdlang, "make", "breaks");
_conf_composite.make_str.cover_image = extractSDLangTabOrAttrib(conf_sdlang, "make", "cover_image");
_conf_composite.make_str.css = extractSDLangTabOrAttrib(conf_sdlang, "make", "css");
_conf_composite.make_str.emphasis = extractSDLangTabOrAttrib(conf_sdlang, "make", "emphasis"); // TODO
_conf_composite.make_str.footer = extractSDLangTabOrAttrib(conf_sdlang, "make", "footer");
_conf_composite.make_str.headings = extractSDLangTabOrAttrib(conf_sdlang, "make", "headings");
_conf_composite.make_str.home_button_image = extractSDLangTabOrAttrib(conf_sdlang, "make", "home_button_image");
_conf_composite.make_str.home_button_text = extractSDLangTabOrAttrib(conf_sdlang, "make", "home_button_text");
_conf_composite.make_str.italics = extractSDLangTabOrAttrib(conf_sdlang, "make", "italics"); // TODO
_conf_composite.make_str.num_top = extractSDLangTabOrAttrib(conf_sdlang, "make", "num_top");
_conf_composite.make_str.num_depth = extractSDLangTabOrAttrib(conf_sdlang, "make", "num_depth");
_conf_composite.make_str.substitute = extractSDLangTabOrAttrib(conf_sdlang, "make", "substitute"); // TODO
_conf_composite.make_str.texpdf_font = extractSDLangTabOrAttrib(conf_sdlang, "make", "texpdf_font");
_conf_composite.make.bold_rgxmatch = _mk.bold_rgxmatch(_conf_composite.make_str.bold); //
_conf_composite.make.breaks = _mk.breaks(_conf_composite.make_str.breaks);
_conf_composite.make.cover_image = _mk.cover_image(_conf_composite.make_str.cover_image);
_conf_composite.make.css = _mk.css(_conf_composite.make_str.css);
_conf_composite.make.emphasis_rgxmatch = _mk.emphasis_rgxmatch(_conf_composite.make_str.emphasis);
_conf_composite.make.footer = _mk.footer(_conf_composite.make_str.footer);
_conf_composite.make.headings = _mk.headings(_conf_composite.make_str.headings);
_conf_composite.make.home_button_image = _mk.home_button_image(_conf_composite.make_str.home_button_image);
_conf_composite.make.home_button_text = _mk.home_button_text(_conf_composite.make_str.home_button_text);
_conf_composite.make.italics_rgxmatch = _mk.italics_rgxmatch(_conf_composite.make_str.italics);
_conf_composite.make.num_top = _mk.num_top(_conf_composite.make_str.num_top);
_conf_composite.make.num_depth = _mk.num_depth(_conf_composite.make_str.num_depth);
_conf_composite.make.substitute = _mk.substitute(_conf_composite.make_str.substitute); // TODO
_conf_composite.make.texpdf_font = _mk.texpdf_font(_conf_composite.make_str.texpdf_font);
}
}
return _conf_composite;
}
#+END_SRC
** 4. SDLang default make meta structs :module:sdp:meta_defaults:
#+name: tangle_defaults
#+BEGIN_SRC d :tangle ../src/sdp/meta/conf_make_meta_sdlang.d
/++
default settings
+/
template SiSUmakeMetaStructsSDLang() {
<<meta_defaults_imports>>
string extractSDLangTabOrAttrib(S)(
S conf_sdlang,
string maintab,
string atab
) {
string _conf_composite_string = "";
if (maintab in conf_sdlang.maybe.tags) {
auto _maintag = conf_sdlang.getTag(maintab);
if (
(atab in _maintag.maybe.tags)
&& (_maintag.getTagValues(atab).length > 0)
) {
debug(configsdlang) {
writeln(
" ", __LINE__,
": sdl tag, ",
maintab, ":", atab, ": ",
_maintag.getTagValues(atab)[0]
);
}
if (_maintag.getTagValues(atab).length == 1) {
writeln((_maintag.getTagValues(atab)[0]).to!string);
_conf_composite_string
= (_maintag.getTagValues(atab)[0]).to!string;
} else if (_maintag.getTagValues(atab).length > 1) {
string _tmp = "";
foreach (st; _maintag.getTagValues(atab)) {
writeln(st.to!string, ";");
_tmp ~= st.to!string ~ ";";
}
_conf_composite_string = _tmp;
}
} else if (
(atab in _maintag.maybe.attributes)
&& (_maintag.attributes[atab][0].value.length > 0)
) {
debug(configsdlang) {
writeln(
" ", __LINE__,
": sdl attrib, ",
maintab, ":", atab, ": ",
_maintag.attributes[atab][0].value
);
}
_conf_composite_string
= (_maintag.attributes[atab][0].value).to!string;
}
}
return _conf_composite_string;
}
}
#+END_SRC
* __END__
** notes headers
#+BEGIN_SRC d
/+
/+
unify internal representation of header info for native & sdlang document headers
represent either using struct, hashes or possibly json
sdp internal representation should be identical for native & sdlang variants
+/
header.
├── make // make instructions
│ ├── bold
│ ├── breaks
│ ├── cover_image
│ ├── css
│ ├── emphasis
│ ├── footer
│ ├── headings
│ ├── home_button_image
│ ├── home_button_text
│ ├── italics
│ ├── num_top
│ ├── substitute
│ └── texpdf_font
└── meta // metadata
├── author // move author to creator:author
├── classify
│ ├── dewey
│ ├── keyword
│ ├── loc
│ ├── subject
│ └── topic_register
├── creator
│ ├── author
│ │ ├── [ [first_name: x0, last_name: y0], [first_name: x1, last_name: y1] ]
│ │ └── [ full_name0, full_name1 ]
│ ├── author_email
│ ├── illustrator
│ └── translator
├── date
│ ├── added_to_site
│ ├── available
│ ├── created
│ ├── issued
│ ├── modified
│ ├── published
│ └── valid
├── identifier
│ ├── isbn
│ ├── oclc
│ └── pg
├── links
├── notes
│ ├── abstract
│ └── description
├── original
│ ├── language
│ ├── source
│ └── title
├── publisher
│ └── name
├── rights
│ ├── copyright
│ ├── cover
│ ├── illustrations
│ └── license
└── title // move title: to title:main
├── edition
├── [ full (main + sub) ]
├── language
├── main
├── note
├── sub
└── subtitle // move title:subtitle to title:sub
61 leaves
+/
#+END_SRC
** dlang rgx example
#+BEGIN_SRC d
import std.conv, std.regex, std.range, std.file, std.stdio;
import std.string : format;
void main(string[] argv) {
immutable ratio = 1.5824; // UK pounds to US dollar as of this writing
auto toDollars(Captures!string price) {
real value = to!real(price["integer"]);
if (!price["fraction"].empty)
value += 0.01*to!real(price["fraction"]);
return format("$%.2f",value * ratio);
}
string text = std.file.readText(argv[1]);
auto converted = replaceAll!toDollars(text,
regex(r"£\s*(?P<integer>[0-9]+)(\.(?P<fraction>[0-9]{2}))?","g"));
write(converted);
}
#+END_SRC
|