diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sdp/meta/metadoc.d | 35 | ||||
-rw-r--r-- | src/sdp/meta/rgx.d | 7 | ||||
-rw-r--r-- | src/sdp/output/paths_source.d | 125 | ||||
-rw-r--r-- | src/sdp/output/rgx.d | 7 | ||||
-rw-r--r-- | src/sdp/output/source_sisupod.d | 18 | ||||
-rwxr-xr-x | src/sdp/sdp.d | 51 |
6 files changed, 187 insertions, 56 deletions
diff --git a/src/sdp/meta/metadoc.d b/src/sdp/meta/metadoc.d index f36af09..b028f8d 100644 --- a/src/sdp/meta/metadoc.d +++ b/src/sdp/meta/metadoc.d @@ -31,13 +31,13 @@ template SiSUabstraction() { enum makeMeta { make, meta } enum docAbst { doc_abstraction, section_keys, segnames, segnames_0_4, images } static auto rgx = Rgx(); - auto SiSUabstraction(Fn,O,E)( - Fn fn_src, + auto SiSUabstraction(M,O,E)( + M _manifest, O _opt_action, - E env, + E _env, ){ - auto sdl_root_config_share = configRead!()("config_share", env); - auto sdl_root_config_local = configRead!()("config_local", env); + auto sdl_root_config_share = configRead!()("config_share", _env); + auto sdl_root_config_local = configRead!()("config_local", _env); auto conf_files_composite_make = confFilesSDLtoStruct!()(sdl_root_config_share, sdl_root_config_local); /+ ↓ read file (filename with path) +/ /+ ↓ file tuple of header and content +/ @@ -45,7 +45,7 @@ template SiSUabstraction() { writeln(__LINE__, ":", __FILE__, ": step1 commence → (get document header & body & insert files)"); } auto _header_body_inserts = - SiSUrawMarkupContent!()(fn_src); + SiSUrawMarkupContent!()(_manifest.src_fn); static assert(!isTypeTuple!(_header_body_inserts)); static assert(_header_body_inserts.length==3); debug(steps) { @@ -106,25 +106,29 @@ template SiSUabstraction() { return _k; } auto source_filename() { - string _k = fn_src; + string _k = _manifest.src_fn; return _k; } auto src_path_info() { - string _pwd = env["pwd"]; - auto _k = SiSUpathsSRC!()(_pwd, fn_src); + string _pwd = _env["pwd"]; + auto _k = SiSUpathsSRC!()(_pwd, _manifest.src_fn); return _k; } auto opt_action() { + /+ getopt options, commandline instructions, raw + - processing instructions --epub --html etc. + - command line config instructions --output-path + +/ auto _k = _opt_action; return _k; } auto environment() { - auto _k = env; + auto _k = _env; return _k; } auto language() { string _k; - if (auto m = fn_src.match(rgx.language_code_and_filename)) { + if (auto m = (_manifest.src_fn).match(rgx.language_code_and_filename)) { _k = m.captures[1]; } else { _k = "en"; @@ -135,6 +139,15 @@ template SiSUabstraction() { string[] _k = _header_body_inserts[headBody.insert_filelist]; return _k; } + auto pod_manifest() { + /+ extensive information on + - source processing paths + - repetition of opt_action with additional processing, including + - output path if any + +/ + auto _k = _manifest; + return _k; + } auto image_list() { auto _k = _images; return _k; diff --git a/src/sdp/meta/rgx.d b/src/sdp/meta/rgx.d index 70f48bb..73f7bfe 100644 --- a/src/sdp/meta/rgx.d +++ b/src/sdp/meta/rgx.d @@ -197,10 +197,13 @@ static template SiSUrgxInit() { static nbsp_and_space = ctRegex!(` [ ]`, "mg"); static nbsp_char_and_space = ctRegex!(`░[ ]`, "mg"); static src_pth = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])$`); - static src_pth_contents = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+)/sisudoc[.]txt$`); + static src_pth_contents = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+)/sisupod[.]manifest$`); static src_pth_zip = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+[.]zip)$`); static src_pth_unzip_pod = ctRegex!(`^(?P<path>media/text/[a-z]{2}/)*(?P<filename>[a-zA-Z0-9._-]+[.]ss[im])$`); - static src_pth_types = ctRegex!(`^(?P<path>[/]?[a-zA-Z0-9._-]+/)*(?P<gotfile>(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])|(?P<filelist>[a-zA-Z0-9._-]+/sisudoc[.]txt)|(?P<filezip>[a-zA-Z0-9._-]+[.]zip))$`); + static src_pth_types = + ctRegex!(`^(?P<path>[/]?[a-zA-Z0-9._-]+/)*(?P<gotfile>(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])|(?P<filelist>[a-zA-Z0-9._-]+/sisupod[.]manifest)|(?P<filezip>[a-zA-Z0-9._-]+[.]zip))$`); + static pod_content_location = + ctRegex!(`^(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])(?P<languages>(?:\s+[a-z]{2}(?:,|$))+)`, "mg"); static src_fn = ctRegex!(`^([/]?(?:[a-zA-Z0-9._-]+/)*)(?P<fn_src>(?P<fn_base>[a-zA-Z0-9._-]+)[.](?P<fn_src_suffix>ss[tm]))$`); static src_fn_master = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ssm)$`); diff --git a/src/sdp/output/paths_source.d b/src/sdp/output/paths_source.d index de14b23..c22efe0 100644 --- a/src/sdp/output/paths_source.d +++ b/src/sdp/output/paths_source.d @@ -15,11 +15,11 @@ template PodManifest() { mixin SiSUrgxInit; static auto rgx = Rgx(); auto PodManifest(P)( - P _pth, + P _pth = "", ) { struct ManifestFile_ { auto pod_manifest_filename() { - string _manifest_file = "sisudoc.txt"; + string _manifest_file = "sisupod.manifest"; return _manifest_file; } auto pod_manifest_path() { @@ -30,8 +30,7 @@ template PodManifest() { } else if (_pth.match(rgx.src_pth_contents) && (_pth.isFile)) { _manifest_path = dirName(_pth); - } else { - // _manifest_path = ""; + // } else { // _manifest_path = ""; } return _manifest_path; } @@ -43,6 +42,105 @@ template PodManifest() { return ManifestFile_(); } } +template PodManifestAndSrcFile() { + mixin SiSUrgxInit; + static auto rgx = Rgx(); + auto PodManifestAndSrcFile(O,E,P,F)( + O _opt_actions, + E _env, + P _pth = "", + F _fns = "", + char[][] _manifest_fn_list = [[]], + ) { + auto _manifest = PodManifest!()(_pth); + struct ManifestFilePlus_ { + auto pwd() { + return _env["pwd"]; + } + auto home() { + return _env["home"]; + } + auto opt_action() { + return _opt_actions; + } + auto is_pod() { + auto _is_pod = (_manifest.pod_manifest_path.length > 0) ? true : false; + return _is_pod; + } + auto pod_manifest_list_of_filenames() { + return _manifest_fn_list; + } + auto pod_manifest_list_of_languages() { + string[] _lngs; + foreach (filename_; pod_manifest_list_of_filenames) { + string _k = "en"; + if (auto m = (filename_).match(rgx.language_code_and_filename)) { + _k = m.captures[1].to!string; + } + _lngs ~= _k; // all the languages from the manifest list of filenames with paths + } + return _lngs; + } + auto pod_manifest_filename() { + return _manifest.pod_manifest_filename; + } + auto pod_manifest_path() { + return _manifest.pod_manifest_path; + } + auto pod_manifest_file_with_path() { + return _manifest.pod_manifest_file_with_path; + } + auto pod_config_dirs() { // TODO + string[] _config_dirs; + return _config_dirs; + } + auto pod_image_dirs() { // TODO + string[] _image_dirs; + return _image_dirs; + } + auto src_fn() { + return _fns; + } + auto src_lng() { + string _k; + if (auto m = (src_fn).match(rgx.language_code_and_filename)) { + _k = m.captures[1]; + } else { + _k = "en"; + } + return _k; + } + auto output_path() { + auto _output_path = pwd; + if ((_opt_actions.output_dir_set.length > 0) + && isValidPath(_opt_actions.output_dir_set) + ) { + _output_path = asNormalizedPath(_opt_actions.output_dir_set).array; + if (!exists(_output_path)) { + _output_path.mkdirRecurse; + } + assert(_output_path.isDir); + } + return _output_path; + } + auto src_config_dirs() { // TODO + string[] _config_dirs; + if (is_pod) { + } else { + } + return _config_dirs; + } + auto src_image_dirs() { // TODO + string[] _image_dirs; + if (is_pod) { + } else { + } + return _image_dirs; + } + } + return ManifestFilePlus_(); + } +} template ConfigFilePaths() { mixin SiSUrgxInit; static auto rgx = Rgx(); @@ -174,10 +272,7 @@ template SiSUpathsSisupods() { string _base_dir_pod = "sisupod"; string _base_dir_doc = "sisudoc"; string _suffix = ".zip"; - auto SiSUpathsSisupods(Ps,Lng)( - Ps src_pth_info, - Lng lng, - ) { + auto SiSUpathsSisupods()() { struct _PodPaths { string base_filename_(string fn_src) { auto pth = fn_src.baseName.stripExtension; @@ -332,7 +427,7 @@ template SiSUpathsSisupods() { } return _pods(); } - auto doc_lng(string fn_src) { + auto doc_lng(string fn_src, string lng) { auto pod_root_ = pod_root(fn_src); auto pth_1_ = text_root(fn_src).zpod.chainPath(lng).array; auto pth_2_ = text_root(fn_src).filesystem_open_zpod.chainPath(lng).array; @@ -378,10 +473,10 @@ template SiSUpathsSisupods() { } return _pods(); } - auto fn_doc(string fn_src) { + auto fn_doc(string fn_src, string lng) { auto pod_root_ = pod_root(fn_src); - auto pth_1_ = doc_lng(fn_src).zpod.chainPath(fn_src.baseName).array; - auto pth_2_ = doc_lng(fn_src).filesystem_open_zpod.chainPath(fn_src.baseName).array; + auto pth_1_ = doc_lng(fn_src, lng).zpod.chainPath(fn_src.baseName).array; + auto pth_2_ = doc_lng(fn_src, lng).filesystem_open_zpod.chainPath(fn_src.baseName).array; struct _pods { auto zpod() { return pth_1_; @@ -393,10 +488,10 @@ template SiSUpathsSisupods() { } return _pods(); } - auto fn_doc_insert(string fn_src, string fn_insert) { + auto fn_doc_insert(string fn_src, string fn_insert, string lng) { auto pod_root_ = pod_root(fn_src); - auto pth_1_ = doc_lng(fn_src).zpod.chainPath(fn_insert.baseName).array; - auto pth_2_ = doc_lng(fn_src).filesystem_open_zpod.chainPath(fn_insert.baseName).array; + auto pth_1_ = doc_lng(fn_src, lng).zpod.chainPath(fn_insert.baseName).array; + auto pth_2_ = doc_lng(fn_src, lng).filesystem_open_zpod.chainPath(fn_insert.baseName).array; struct _pods { auto zpod() { return pth_1_; diff --git a/src/sdp/output/rgx.d b/src/sdp/output/rgx.d index c9f0175..9daaa3b 100644 --- a/src/sdp/output/rgx.d +++ b/src/sdp/output/rgx.d @@ -16,10 +16,13 @@ static template SiSUoutputRgxInit() { static nbsp_and_space = ctRegex!(` [ ]`, "mg"); static nbsp_char_and_space = ctRegex!(`░[ ]`, "mg"); static src_pth = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])$`); - static src_pth_contents = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+)/sisudoc[.]txt$`); + static src_pth_contents = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+)/sisupod[.]manifest$`); static src_pth_zip = ctRegex!(`^(?P<path>[/]?(?:[a-zA-Z0-9._-]+/)*)(?P<filename>[a-zA-Z0-9._-]+[.]zip)$`); static src_pth_unzip_pod = ctRegex!(`^(?P<path>media/text/[a-z]{2}/)*(?P<filename>[a-zA-Z0-9._-]+[.]ss[im])$`); - static src_pth_types = ctRegex!(`^(?P<path>[/]?[a-zA-Z0-9._-]+/)*(?P<gotfile>(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])|(?P<filelist>[a-zA-Z0-9._-]+/sisudoc[.]txt)|(?P<filezip>[a-zA-Z0-9._-]+[.]zip))$`); + static src_pth_types = + ctRegex!(`^(?P<path>[/]?[a-zA-Z0-9._-]+/)*(?P<gotfile>(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])|(?P<filelist>[a-zA-Z0-9._-]+/sisupod[.]manifest)|(?P<filezip>[a-zA-Z0-9._-]+[.]zip))$`); + static pod_content_location = + ctRegex!(`^(?P<filename>[a-zA-Z0-9._-]+[.]ss[tm])(?P<languages>(?:\s+[a-z]{2}(?:,|$))+)`, "mg"); static src_fn = ctRegex!(`^([/]?(?:[a-zA-Z0-9._-]+/)*)(?P<fn_src>(?P<fn_base>[a-zA-Z0-9._-]+)[.](?P<fn_src_suffix>ss[tm]))$`); static src_fn_master = ctRegex!(`^(?P<path>[a-zA-Z0-9._-]+/)*(?P<filename>[a-zA-Z0-9._-]+[.]ssm)$`); diff --git a/src/sdp/output/source_sisupod.d b/src/sdp/output/source_sisupod.d index 6e06667..106c419 100644 --- a/src/sdp/output/source_sisupod.d +++ b/src/sdp/output/source_sisupod.d @@ -17,9 +17,8 @@ template SiSUpod() { mixin SiSUoutputRgxInit; string pwd = doc_matters.environment["pwd"]; auto src_path_info = doc_matters.src_path_info; - string lng = doc_matters.language; auto pth_sisudoc_src = doc_matters.src_path_info; - auto pths_sisupod = SiSUpathsSisupods!()(src_path_info, lng); + auto pths_sisupod = SiSUpathsSisupods!()(); mixin SiSUlanguageCodes; auto lang = Lang(); static auto rgx = Rgx(); @@ -46,14 +45,14 @@ template SiSUpod() { if (!exists(pths_sisupod.image_root(doc_matters.source_filename).filesystem_open_zpod)) { pths_sisupod.image_root(doc_matters.source_filename).filesystem_open_zpod.mkdirRecurse; } - if (!exists(pths_sisupod.doc_lng(doc_matters.source_filename).filesystem_open_zpod)) { - pths_sisupod.doc_lng(doc_matters.source_filename).filesystem_open_zpod.mkdirRecurse; + if (!exists(pths_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language).filesystem_open_zpod)) { + pths_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language).filesystem_open_zpod.mkdirRecurse; } } debug(sisupod) { writeln(__LINE__, ": ", doc_matters.source_filename, " -> ", - pths_sisupod.fn_doc(doc_matters.source_filename).filesystem_open_zpod + pths_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).filesystem_open_zpod ); } auto zip = new ZipArchive(); @@ -102,9 +101,9 @@ template SiSUpod() { } } { /+ TODO bundle primary file +/ auto fn_src_in = doc_matters.source_filename; - auto fn_src_out_sisupod_zip_base = pths_sisupod.fn_doc(doc_matters.source_filename).zpod.to!string; - auto fn_src_out_filesystem = pths_sisupod.fn_doc(doc_matters.source_filename).filesystem_open_zpod.to!string; // needed without root path: - auto fn_src_out_inside_pod = pths_sisupod.fn_doc(doc_matters.source_filename).zpod.to!string; // needed without root path: + auto fn_src_out_sisupod_zip_base = pths_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).zpod.to!string; + auto fn_src_out_filesystem = pths_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).filesystem_open_zpod.to!string; // needed without root path: + auto fn_src_out_inside_pod = pths_sisupod.fn_doc(doc_matters.source_filename, doc_matters.language).zpod.to!string; // needed without root path: string[] filelist_src_out_sisupod_arr; string[] filelist_src_zpod_arr; if (exists(fn_src_in)) { @@ -135,6 +134,7 @@ template SiSUpod() { pths_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, + doc_matters.language, ).zpod ); } @@ -143,11 +143,13 @@ template SiSUpod() { pths_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, + doc_matters.language, ).zpod.to!string; auto fn_src_out_filesystem = pths_sisupod.fn_doc_insert( doc_matters.source_filename, insert_file, + doc_matters.language, ).filesystem_open_zpod.to!string; if (exists(fn_src_in)) { if (doc_matters.opt_action.source) { diff --git a/src/sdp/sdp.d b/src/sdp/sdp.d index af3a0a0..34f11d9 100755 --- a/src/sdp/sdp.d +++ b/src/sdp/sdp.d @@ -39,7 +39,6 @@ void main(string[] args) { mixin SiSUbiblio; mixin SiSUrgxInitFlags; mixin outputHub; - string[] fns_src; string flag_action; string arg_unrecognized; enum dAM { abstraction, matters } @@ -299,13 +298,21 @@ void main(string[] args) { } } auto _opt_action = OptActions(); + auto _env = [ + "pwd" : environment["PWD"], + "home" : environment["HOME"], + ]; + auto _manifest = PodManifest!()(); + auto _manifest_plus = PodManifestAndSrcFile!()(_opt_action, _env); + auto _manifests = [ _manifest_plus ]; foreach(arg; args[1..$]) { - auto _manifest = PodManifest!()(arg); + _manifest = PodManifest!()(arg); if (arg.match(rgx.flag_action)) { flag_action ~= " " ~ arg; // flags not taken by getopt } else if (arg.match(rgx.src_pth)) { - fns_src ~= arg; // gather input markup source file names for processing + _manifests ~= PodManifestAndSrcFile!()(_opt_action, _env, arg, arg); // gather input markup source file names for processing } else if (_manifest.pod_manifest_file_with_path) { + string contents_location_raw_; string contents_location_; string sisudoc_txt_ = _manifest.pod_manifest_file_with_path; enforce( @@ -315,7 +322,7 @@ void main(string[] args) { ); try { if (exists(sisudoc_txt_)) { - contents_location_ = sisudoc_txt_.readText; + contents_location_raw_ = sisudoc_txt_.readText; } } catch (ErrnoException ex) { @@ -323,6 +330,15 @@ void main(string[] args) { catch (FileException ex) { // Handle errors } + if (contents_location_raw_.match(rgx.pod_content_location)) { // (file name followed by language codes \n)+ + foreach (m; contents_location_raw_.matchAll(rgx.pod_content_location)) { + foreach (n; m.captures[2].matchAll(rgx.language_codes)) { + contents_location_ ~= "media/text/" ~ n.captures[1].to!string ~ "/" ~ m.captures[1].to!string ~ "\n"; + } + } + } else { // (file name with path \n)+ + contents_location_ = contents_location_raw_; + } auto contents_locations_arr = (cast(char[]) contents_location_).split; auto tmp_dir_ = (sisudoc_txt_).dirName.array; @@ -336,7 +352,9 @@ void main(string[] args) { if (_opt_action.languages_set[0] == "all" || (contents_location_pth_).match(lang_rgx_) ) { - fns_src ~= (((tmp_dir_).chainPath(contents_location_pth_)).array).to!(char[]); + auto _fns = (((tmp_dir_).chainPath(contents_location_pth_)).array).to!(string); + _manifest_plus = PodManifestAndSrcFile!()(_opt_action, _env, arg, _fns, contents_locations_arr); + _manifests ~= _manifest_plus; // TODO how to capture? } } } else if (arg.match(rgx.src_pth_zip)) { @@ -345,16 +363,13 @@ void main(string[] args) { arg_unrecognized ~= " " ~ arg; } } - auto env = [ - "pwd" : environment["PWD"], - "home" : environment["HOME"], - ]; + if (!(_opt_action.skip_output)) { outputHubOp!()(_opt_action); } - if (fns_src.length > 0) { - foreach(fn_src; fns_src) { - if (!empty(fn_src)) { + if (_manifests.length > 1) { // _manifests[0] is dummy element used in initialization to be removed + foreach(manifest; _manifests[1..$]) { + if (!empty(manifest.src_fn)) { scope(success) { debug(checkdoc) { writefln( @@ -369,16 +384,16 @@ void main(string[] args) { stderr.writefln( "~ document run failure ~ (%s v%s)\n\t%s", __VENDOR__, __VERSION__, - fn_src + src_fn ); } } enforce( - fn_src.match(rgx.src_pth_types), + manifest.src_fn.match(rgx.src_pth_types), "not a sisu markup filename: «" ~ - fn_src ~ "»" + manifest.src_fn ~ "»" ); - auto t = SiSUabstraction!()(fn_src, _opt_action, env); + auto t = SiSUabstraction!()(manifest, _opt_action, _env); static assert(!isTypeTuple!(t)); static assert(t.length==2); auto doc_abstraction = t[dAM.abstraction]; @@ -401,10 +416,10 @@ void main(string[] args) { debug(checkdoc) { writefln( "processed file: %s", - fn_src + manifest.src_fn ); } - destroy(fn_src); + destroy(manifest); } } else { /+ no recognized filename provided +/ |