diff options
| author | Ralph Amissah <ralph@amissah.com> | 2017-02-10 16:51:55 -0500 | 
|---|---|---|
| committer | Ralph Amissah <ralph@amissah.com> | 2019-04-10 15:14:14 -0400 | 
| commit | c98283e3919f39c093e1eb51f80e6f259a7fd103 (patch) | |
| tree | 77cfd266466f8cab3ecf54f81716a9d2a85f87f8 | |
| parent | 0.13.0 batch processing, reset values for each document (footnotes, bookindex... (diff) | |
output, sisupod & a few switches
| -rw-r--r-- | org/ao_defaults.org | 24 | ||||
| -rw-r--r-- | org/output.org | 689 | ||||
| -rw-r--r-- | org/sdp.org | 9 | ||||
| -rw-r--r-- | src/sdp/abstraction.d | 9 | ||||
| -rw-r--r-- | src/sdp/ao_defaults.d | 13 | ||||
| -rw-r--r-- | src/sdp/ao_rgx.d | 5 | ||||
| -rw-r--r-- | src/sdp/output_epub.d | 187 | ||||
| -rw-r--r-- | src/sdp/output_html.d | 286 | ||||
| -rw-r--r-- | src/sdp/source_sisupod.d | 69 | 
9 files changed, 738 insertions, 553 deletions
| diff --git a/org/ao_defaults.org b/org/ao_defaults.org index 2cb0eee..fbf4495 100644 --- a/org/ao_defaults.org +++ b/org/ao_defaults.org @@ -645,18 +645,21 @@ template SiSUpaths() {      string doc_lng(string fn_src, string lng) {        return chainPath(doc(fn_src), lng).array;      } -    string image(string fn_src) { -      return chainPath(base(fn_src), "image").array; -    }      string conf(string fn_src) { -      return chainPath(base(fn_src), "conf").array; +      return chainPath(doc(fn_src), "_sisu").array; +    } +    string image(string fn_src) { +      return chainPath(conf(fn_src), "image").array;      }      string css(string fn_src) { -      return chainPath(base(fn_src), "css").array; +      return chainPath(conf(fn_src), "css").array;      }      string fn_doc(string fn_src, string lng) {        return chainPath((doc_lng(fn_src, lng)), baseName(fn_src)).array;      } +    string fn_doc_insert(string fn_src, string fn_insert, string lng) { +      return chainPath((doc_lng(fn_src, lng)), baseName(fn_insert)).array; +    }    }    struct HtmlPaths {      string base_filename(string fn_src) { @@ -1090,6 +1093,17 @@ static bi_sub_terms_plus_obj_cite_number_offset_split = ctRegex!(`\s*\|\s*`);  static bi_term_and_obj_cite_numbers_match             = ctRegex!(`^(.+?)\+(\d+)`);  #+END_SRC +** language codes                                         :language:codes: + +#+name: ao_rgx +#+BEGIN_SRC d +/+ language codes +/ +auto language_codes                                    = +   ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)"); +auto language_code_and_filename                                    = +   ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$"); +#+END_SRC +  * +set colors for terminal+ (unused)                          :colors:terminal:  #+name: ao_ansi_colors diff --git a/org/output.org b/org/output.org index 054937e..903b6ed 100644 --- a/org/output.org +++ b/org/output.org @@ -143,108 +143,111 @@ import  #+BEGIN_SRC d :tangle ../src/sdp/source_sisupod.d  template SiSUpod() {    <<output_imports>> -  <<source_sisupod_mkdirs>> -  <<source_sisupod_config>> -  <<source_sisupod_text>> -  <<source_sisupod_images>> +  void SiSUpod(T)(T doc_matters) { +    <<source_sisupod_init>> +    try { +      <<source_sisupod_mkdirs>> +      <<source_sisupod_copy>> +    } +    catch (ErrnoException ex) { +      // Handle error +    } +  }  }  #+END_SRC -*** TODO output files +*** mkdir -#+name: source_sisupod_config +#+name: source_sisupod_init  #+BEGIN_SRC d -void SiSUpod(T)(T doc_matters) { -  debug(asserts){ -  } -  mixin SiSUrgxInit; -  mixin SiSUpaths; -  auto pth_sisupod = SiSUpodPaths(); -  mixin SiSUlanguageCodes; -  auto lang = Lang(); -  auto rgx = Rgx(); -  /+ -    dir structure -    /tmp/_sisu_processing_/ralph/sisupod -      ├── conf -      ├── css (unless should be within conf?) -      ├── doc -      │   ├── en -      │   ├── es -      │   ├── fr -      │   └── zh -      └── image +debug(asserts){ +  // static assert(is(typeof(doc_matters) == tuple)); +} +mixin SiSUrgxInit; +mixin SiSUpaths; +auto pth_sisupod = SiSUpodPaths(); +mixin SiSUlanguageCodes; +auto lang = Lang(); +auto rgx = Rgx(); +assert (match(doc_matters.source_filename, rgx.src_fn)); +#+END_SRC -    - tasks -      - create directory structure -      - map other language directories -        - check for corresponding files within -  +/ -  assert (match(doc_matters.source_filename, rgx.src_fn)); -  try { -    /+ create directory structure +/ -    if (!exists(pth_sisupod.doc(doc_matters.source_filename))) { -      mkdirRecurse(pth_sisupod.doc(doc_matters.source_filename)); -    } -    if (!exists(pth_sisupod.conf(doc_matters.source_filename))) { -      mkdirRecurse(pth_sisupod.conf(doc_matters.source_filename)); -    } -    if (!exists(pth_sisupod.css(doc_matters.source_filename))) { -      mkdirRecurse(pth_sisupod.css(doc_matters.source_filename)); -    } -    if (!exists(pth_sisupod.image(doc_matters.source_filename))) { -      mkdirRecurse(pth_sisupod.image(doc_matters.source_filename)); -    } -    /+ copy relevant files +/ +#+name: source_sisupod_mkdirs +#+BEGIN_SRC d +/+ create directory structure +/ +if (!exists(pth_sisupod.doc(doc_matters.source_filename))) { +  mkdirRecurse(pth_sisupod.doc(doc_matters.source_filename)); +} +if (!exists(pth_sisupod.conf(doc_matters.source_filename))) { +  mkdirRecurse(pth_sisupod.conf(doc_matters.source_filename)); +} +if (!exists(pth_sisupod.css(doc_matters.source_filename))) { +  mkdirRecurse(pth_sisupod.css(doc_matters.source_filename)); +} +if (!exists(pth_sisupod.image(doc_matters.source_filename))) { +  mkdirRecurse(pth_sisupod.image(doc_matters.source_filename)); +} +if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language))) { +  mkdirRecurse(pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language)); +} +#+END_SRC + +*** copy + +#+name: source_sisupod_copy +#+BEGIN_SRC d +debug(sisupod) { +  writeln(__LINE__, ": ", +    // doc_matters.environment["pwd"], "/", +      doc_matters.source_filename, " -> ", +    // doc_matters.environment["pwd"], "/", +      pth_sisupod.fn_doc( +        doc_matters.source_filename, +        doc_matters.language +  )); +} +if (exists(doc_matters.source_filename)) { +  copy( +    doc_matters.source_filename, +    pth_sisupod.fn_doc( +      doc_matters.source_filename, +      doc_matters.language +  )); +} +if (doc_matters.file_insert_list.length > 0) { +  foreach (insert_file; doc_matters.file_insert_list) {      debug(sisupod) { -      writeln(__LINE__, ": ", -        // doc_matters.environment["pwd"], "/", -          doc_matters.source_filename, " -> ", -        // doc_matters.environment["pwd"], "/", -          pth_sisupod.fn_doc(doc_matters.source_filename, "en") -      ); -    } -    // need to extract language code directories (from directory structure or filenames & have a default) -    if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, "en"))) { -      mkdirRecurse(pth_sisupod.doc_lng(doc_matters.source_filename, "en")); -    } -    if (exists(doc_matters.source_filename)) { -      copy(doc_matters.source_filename, -        pth_sisupod.fn_doc(doc_matters.source_filename, "en")); -    } -    if (doc_matters.file_insert_list.length > 0) { -      foreach (insert_file; doc_matters.file_insert_list) { -        debug(sisupod) { -          writeln( -            // doc_matters.environment["pwd"], "/", -              insert_file, " -> ", -            // doc_matters.environment["pwd"], "/", -              pth_sisupod.fn_doc(doc_matters.source_filename, "en") -          ); -        } -        if (exists(insert_file)) { -          copy(insert_file, -            pth_sisupod.fn_doc(doc_matters.source_filename, "en")); -        } -      } +      writeln( +          insert_file, " -> ", +          pth_sisupod.fn_doc_insert( +            doc_matters.source_filename, +            insert_file, +            doc_matters.language +      ));      } -    foreach (image; doc_matters.image_list) { -      debug(sisupod) { -        writeln( -          // doc_matters.environment["pwd"], "/", -            "_sisu/image/", image, " -> ", -          // doc_matters.environment["pwd"], "/", -            pth_sisupod.image(doc_matters.source_filename), "/", image -        ); -      } -      if (exists("_sisu/image/"~ image)) { -        copy(("_sisu/image/"~ image), -          (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image)); -      } +    if (exists(insert_file)) { +      copy( +        insert_file, +        pth_sisupod.fn_doc_insert( +          doc_matters.source_filename, +          insert_file, +          doc_matters.language +      ));      }    } -  catch (ErrnoException ex) { -    // Handle error +} +foreach (image; doc_matters.image_list) { +  debug(sisupod) { +    writeln( +        "_sisu/image/", image, " -> ", +        pth_sisupod.image(doc_matters.source_filename), "/", image +    ); +  } +  if (exists("_sisu/image/"~ image)) { +    copy( +      ("_sisu/image/"~ image), +      (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image) +    );    }  }  #+END_SRC @@ -601,42 +604,13 @@ template outputHTML() {  #+END_SRC  **** scroll                                                       :scroll: -***** output file +***** switch (sections & objects) format html output  #+name: output_html_scroll  #+BEGIN_SRC d -void scroll_write_output_file(Fn,C)( -  Fn fn_src, -  C doc, -) { -  debug(asserts){ -    static assert(is(typeof(fn_src) == string)); -    static assert(is(typeof(doc)    == string[])); -  } -  mixin SiSUpaths; -  auto pth_html = HtmlPaths(); -  try { -    if (!exists(pth_html.base)) { -      mkdirRecurse(pth_html.base); -    } -    auto f = File(pth_html.fn_scroll(fn_src), "w"); -    foreach (o; doc) { -      f.writeln(o); -    } -  } -  catch (ErrnoException ex) { -    // Handle error -  } -} -#+END_SRC - -***** (sections & objects) switch (for html output format) - -#+name: output_html_scroll -#+BEGIN_SRC d -void scroll(C,T)( -  auto ref const C         contents, -  auto ref T               doc_matters, +void scroll(D,I)( +  auto ref const D         doc_abstraction, +  auto ref I               doc_matters,  ) {    mixin SiSUrgxInit;    auto xhtml_format = outputXHTMLs(); @@ -644,8 +618,9 @@ void scroll(C,T)(    string[] doc_html;    string[] doc;    foreach (part; doc_matters.keys_seq_scroll) { -    foreach (obj; contents[part]) { -      if (obj.use == "frontmatter") { +    foreach (obj; doc_abstraction[part]) { +      switch (obj.use) { +      case "frontmatter":          switch (obj.is_of) {          case "para":            switch (obj.is_a) { @@ -664,11 +639,12 @@ void scroll(C,T)(            break;          default:            if ((doc_matters.opt_action_bool["debug"])) { -            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);            }            break;          } -      } else if (obj.use == "body") { +        break; +      case "body":          switch (obj.is_of) {          case "para":            switch (obj.is_a) { @@ -720,7 +696,8 @@ void scroll(C,T)(            }            break;          } -      } else if (obj.use == "backmatter") { +        break; +      case "backmatter":          switch (obj.is_of) {          case "para":            switch (obj.is_a) { @@ -751,61 +728,63 @@ void scroll(C,T)(            break;          default:            if ((doc_matters.opt_action_bool["debug"])) { -            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);            }            break;          } +        break; +      case "comment": +        break; +      default: +        if ((doc_matters.opt_action_bool["debug"])) { +          writeln(__FILE__, ":", __LINE__, ": ", obj.use); +        } +        break;        }      }    }    doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail; -  scroll_write_output_file(doc_matters.source_filename, doc); +  scroll_write_output(doc_matters.source_filename, doc);  }  #+END_SRC -**** seg                                                             :seg: -***** output files +***** write output file -#+name: output_html_seg +#+name: output_html_scroll  #+BEGIN_SRC d -void seg_write_output_files(M,C)( -  M doc_matters, -  C doc_html, +void scroll_write_output(Fn,C)( +  Fn fn_src, +  C doc,  ) {    debug(asserts){ -    static assert(is(typeof(doc_html)      == string[][string])); +    static assert(is(typeof(fn_src) == string)); +    static assert(is(typeof(doc)    == string[]));    } -  mixin SiSUrgxInit; -  auto rgx = Rgx();    mixin SiSUpaths;    auto pth_html = HtmlPaths(); -  auto xhtml_format = outputXHTMLs(); -  auto m = matchFirst(doc_matters.source_filename, rgx.src_fn);    try { -    if (!exists(pth_html.seg(doc_matters.source_filename))) { -      mkdirRecurse(pth_html.seg(doc_matters.source_filename)); +    if (!exists(pth_html.base)) { +      mkdirRecurse(pth_html.base);      } -    foreach (seg_filename; doc_matters.segnames) { -      auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); -      foreach (docseg; doc_html[seg_filename]) { -        f.writeln(docseg); -      } -      f.writeln(xhtml_format.tail); // needed for each lev4 +    auto f = File(pth_html.fn_scroll(fn_src), "w"); +    foreach (o; doc) { +      f.writeln(o);      }    }    catch (ErrnoException ex) { -    // handle error +    // Handle error    }  }  #+END_SRC -***** (sections & objects) switch (for html output format) +**** seg                                                             :seg: +***** switch (sections & objects) format html output  #+name: output_html_seg  #+BEGIN_SRC d -void seg(C,M)( -  auto ref const C         contents, -  auto ref M               doc_matters, +void seg(D,I)( +  auto ref const D         doc_abstraction, +  auto ref I               doc_matters,  ) {    mixin SiSUrgxInit;    auto rgx = Rgx(); @@ -815,7 +794,7 @@ void seg(C,M)(    string segment_filename;    string[] top_level_headings = ["","","",""];    foreach (part; doc_matters.keys_seq_seg) { -    foreach (obj; contents[part]) { +    foreach (obj; doc_abstraction[part]) {        if (obj.is_a == "heading") {                            // all headings: frontmatter, body & backmatter          switch (obj.heading_lev_markup) {          case 0: .. case 3: @@ -840,13 +819,13 @@ void seg(C,M)(              top_level_headings[3] = "";              goto default;            default: -            top_level_headings[obj.heading_lev_markup] = xhtml_format.heading(obj); // should probably have different css tagging (fontsize etc) +            top_level_headings[obj.heading_lev_markup] = xhtml_format.heading(obj);              break;            }            break;          case 4:            segment_filename = obj.segment_anchor_tag; -          doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); // consider placing seg_head here as can more easily populate it with lev4 info +          doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta);            foreach (top_level_heading; top_level_headings) {              doc_html[segment_filename] ~= top_level_heading;            } @@ -855,107 +834,171 @@ void seg(C,M)(          case 5: .. case 7:            doc_html[segment_filename] ~= xhtml_format.heading(obj);            break; -        default: +        case 8: .. case 9: // unused numbers, if remain check            if ((doc_matters.opt_action_bool["debug"])) { -            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -          } -          break; -        } -      } else if (obj.use == "frontmatter") { -        switch (obj.is_of) { -        case "para": -          switch (obj.is_a) { -          case "toc": -              doc_html[segment_filename] ~= xhtml_format.toc(obj); -          break; -          default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -            break; +            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +            writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check            }            break;          default: -          // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +          if ((doc_matters.opt_action_bool["debug"])) { +            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +          }            break;          } -      } else if (obj.use == "body") { -        switch (obj.is_of) { -        case "para": -          switch (obj.is_a) { +      } else { +        switch (obj.use) { +        case "frontmatter": +          switch (obj.is_of) {            case "para": -            doc_html[segment_filename] ~= xhtml_format.para(obj); +            switch (obj.is_a) { +            case "toc": +              doc_html[segment_filename] ~= xhtml_format.toc(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            if ((doc_matters.opt_action_bool["debug"])) { +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            }              break;            }            break; -        case "block": -          switch (obj.is_a) { -          case "poem":                        // double check why both poem & verse -            break; -          case "verse": -            doc_html[segment_filename] ~= xhtml_format.nugget(obj); -            break; -          case "group": -            doc_html[segment_filename] ~= xhtml_format.nugget(obj); +        case "body": +          switch (obj.is_of) { +          case "para": +            switch (obj.is_a) { +            case "para": +              doc_html[segment_filename] ~= xhtml_format.para(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            case "block": -            doc_html[segment_filename] ~= xhtml_format.nugget(obj); -            break; -          case "quote": -            doc_html[segment_filename] ~= xhtml_format.nugget(obj); -            break; -          case "table": -            doc_html[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "code": -            doc_html[segment_filename] ~= xhtml_format.code(obj); +            switch (obj.is_a) { +            case "poem": +              break; +            case "verse": +              doc_html[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "group": +              doc_html[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "block": +              doc_html[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "quote": +              doc_html[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "table": +              doc_html[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "code": +              doc_html[segment_filename] ~= xhtml_format.code(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            default:              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);              }              break;            }            break; -        default: -          // writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); -          break; -        } -      } else if (obj.use == "backmatter") { -        switch (obj.is_of) { -        case "para": -          switch (obj.is_a) { -          case "endnote": -            doc_html[segment_filename] ~= xhtml_format.endnote(obj); -            break; -          case "glossary": -            doc_html[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "bibliography": -            doc_html[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "bookindex": -            doc_html[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "blurb": -            doc_html[segment_filename] ~= xhtml_format.para(obj); +        case "backmatter": +          switch (obj.is_of) { +          case "para": +            switch (obj.is_a) { +            case "endnote": +              doc_html[segment_filename] ~= xhtml_format.endnote(obj); +              break; +            case "glossary": +              doc_html[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "bibliography": +              doc_html[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "bookindex": +              doc_html[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "blurb": +              doc_html[segment_filename] ~= xhtml_format.para(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            if ((doc_matters.opt_action_bool["debug"])) { +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); +            }              break;            }            break; +        case "comment": +          break;          default:            if ((doc_matters.opt_action_bool["debug"])) { -            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            writeln(__FILE__, ":", __LINE__, ": ", obj.use);            }            break;          }        }      }    } -  seg_write_output_files(doc_matters, doc_html); +  seg_write_output(doc_matters, doc_html); +} +#+END_SRC + +***** write output files + +#+name: output_html_seg +#+BEGIN_SRC d +void seg_write_output(M,C)( +  M doc_matters, +  C doc_html, +) { +  debug(asserts){ +    static assert(is(typeof(doc_html)      == string[][string])); +  } +  mixin SiSUrgxInit; +  auto rgx = Rgx(); +  mixin SiSUpaths; +  auto pth_html = HtmlPaths(); +  auto xhtml_format = outputXHTMLs(); +  auto m = matchFirst(doc_matters.source_filename, rgx.src_fn); +  try { +    if (!exists(pth_html.seg(doc_matters.source_filename))) { +      mkdirRecurse(pth_html.seg(doc_matters.source_filename)); +    } +    foreach (seg_filename; doc_matters.segnames) { +      auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); +      foreach (docseg; doc_html[seg_filename]) { +        f.writeln(docseg); +      } +      f.writeln(xhtml_format.tail); // needed for each lev4 +    } +  } +  catch (ErrnoException ex) { +    // handle error +  }  }  #+END_SRC @@ -2287,7 +2330,7 @@ template outputEPub() {  #+END_SRC  **** epub special files                                           :format: -***** fixed +***** static  ****** mimetype (file)  #+name: output_epub_fixed @@ -2322,7 +2365,7 @@ string epub_container_xml() {  #+name: output_epub_constructs  #+BEGIN_SRC d -string epub_oebps_content(C,M)(C contents, M doc_matters) { +string epub_oebps_content(D,I)(D doc_abstraction, I doc_matters) {    string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere    string content = format(q"¶<?xml version='1.0' encoding='utf-8'?>  <?xml version='1.0' encoding='utf-8'?> @@ -2357,7 +2400,7 @@ string epub_oebps_content(C,M)(C contents, M doc_matters) {      uuid,    );    foreach (sect; doc_matters.keys_seq_seg) { -    foreach (obj; contents[sect]) { +    foreach (obj; doc_abstraction[sect]) {      }    }    return content; @@ -2368,7 +2411,7 @@ string epub_oebps_content(C,M)(C contents, M doc_matters) {  #+name: output_epub_constructs  #+BEGIN_SRC d -string epub_oebps_toc(C,M)(C contents, M doc_matters) { +string epub_oebps_toc(D,I)(D doc_abstraction, I doc_matters) {    int counter = 0;    string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere    auto markup = InlineMarkup(); @@ -2401,7 +2444,7 @@ string epub_oebps_toc(C,M)(C contents, M doc_matters) {      (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : doc_matters.dochead_meta["creator"]["author"],          // author    );    foreach (sect; doc_matters.keys_seq_seg) { -    foreach (obj; contents[sect]) { +    foreach (obj; doc_abstraction[sect]) {        if (obj.is_a == "heading") {          foreach_reverse (k; 0 .. 7) {            switch (obj.dom_markedup[k]) { @@ -2446,13 +2489,14 @@ obj.segment_anchor_tag,   // lev < 4 [no link]; lev == 4 [filename] markup.xhtml  }  #+END_SRC -**** build (sections & objects) switch (for epub xhtml output format) +**** seg                                                             :seg: +***** switch (sections & objects) format epub xhtml output  #+name: output_epub_xhtml_seg  #+BEGIN_SRC d -void outputEPub(C,T)( -  auto ref const C         contents, -  auto ref T               doc_matters, +void outputEPub(D,I)( +  auto ref const D         doc_abstraction, +  auto ref I               doc_matters,  ) {    mixin SiSUrgxInit;    auto xhtml_format = outputXHTMLs(); @@ -2464,10 +2508,10 @@ void outputEPub(C,T)(    string[] top_level_headings = ["","","",""];    auto mimetypes = epub_mimetypes;    auto meta_inf_container_xml = epub_container_xml; -  auto oebps_toc_ncx = epub_oebps_toc(contents, doc_matters); -  auto oebps_content_opf = epub_oebps_content(contents, doc_matters); +  auto oebps_toc_ncx = epub_oebps_toc(doc_abstraction, doc_matters); +  auto oebps_content_opf = epub_oebps_content(doc_abstraction, doc_matters);    foreach (part; doc_matters.keys_seq_seg) { -    foreach (obj; contents[part]) { +    foreach (obj; doc_abstraction[part]) {        if (obj.is_a == "heading") {          switch (obj.heading_lev_markup) {          case 0: .. case 3: @@ -2507,100 +2551,129 @@ void outputEPub(C,T)(          case 5: .. case 7:            doc_epub[segment_filename] ~= xhtml_format.heading(obj);            break; -        default: +        case 8: .. case 9: // unused numbers, if remain check            if ((doc_matters.opt_action_bool["debug"])) { -            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -          } -          break; -        } -      } else if (obj.use == "frontmatter") { -        switch (obj.is_of) { -        case "para": -          switch (obj.is_a) { -          case "toc": -              doc_epub[segment_filename] ~= xhtml_format.toc(obj); -          break; -          default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -            break; +            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +            writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check            }            break;          default: -          // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +          if ((doc_matters.opt_action_bool["debug"])) { +            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +          }            break;          } -      } else if (obj.use == "body") { -        switch (obj.is_of) { -        case "para": -          switch (obj.is_a) { +      } else { +        switch (obj.use) { +        case "frontmatter": +          switch (obj.is_of) {            case "para": -            doc_epub[segment_filename] ~= xhtml_format.para(obj); +            switch (obj.is_a) { +            case "toc": +              doc_epub[segment_filename] ~= xhtml_format.toc(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            if ((doc_matters.opt_action_bool["debug"])) { +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); +            }              break;            }            break; -        case "block": -          switch (obj.is_a) { -          case "poem":                        // double check why both poem & verse -            break; -          case "verse": -            doc_epub[segment_filename] ~= xhtml_format.nugget(obj); -            break; -          case "group": -            doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +        case "body": +          switch (obj.is_of) { +          case "para": +            switch (obj.is_a) { +            case "para": +              doc_epub[segment_filename] ~= xhtml_format.para(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            case "block": -            doc_epub[segment_filename] ~= xhtml_format.nugget(obj); -            break; -          case "quote": -            doc_epub[segment_filename] ~= xhtml_format.nugget(obj); -            break; -          case "table": -            doc_epub[segment_filename] ~= xhtml_format.para(obj); // -            break; -          case "code": -            doc_epub[segment_filename] ~= xhtml_format.code(obj); +            switch (obj.is_a) { +            case "poem":                        // double check why both poem & verse +              break; +            case "verse": +              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "group": +              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "block": +              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "quote": +              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +              break; +            case "table": +              doc_epub[segment_filename] ~= xhtml_format.para(obj); // +              break; +            case "code": +              doc_epub[segment_filename] ~= xhtml_format.code(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            default:              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);              }              break;            }            break; -        default: -          // writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); -          break; -        } -      } else if (obj.use == "backmatter") { -        switch (obj.is_of) { -        case "para": -          switch (obj.is_a) { -          case "endnote": -            doc_epub[segment_filename] ~= xhtml_format.endnote(obj); -            break; -          case "glossary": -            doc_epub[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "bibliography": -            doc_epub[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "bookindex": -            doc_epub[segment_filename] ~= xhtml_format.para(obj); -            break; -          case "blurb": -            doc_epub[segment_filename] ~= xhtml_format.para(obj); +        case "backmatter": +          switch (obj.is_of) { +          case "para": +            switch (obj.is_a) { +            case "endnote": +              doc_epub[segment_filename] ~= xhtml_format.endnote(obj); +              break; +            case "glossary": +              doc_epub[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "bibliography": +              doc_epub[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "bookindex": +              doc_epub[segment_filename] ~= xhtml_format.para(obj); +              break; +            case "blurb": +              doc_epub[segment_filename] ~= xhtml_format.para(obj); +              break; +            default: +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              } +              break; +            }              break;            default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            if ((doc_matters.opt_action_bool["debug"])) { +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); +            }              break;            }            break; +        case "comment": +          break;          default:            if ((doc_matters.opt_action_bool["debug"])) { -            writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            writeln(__FILE__, ":", __LINE__, ": ", obj.use);            }            break;          } @@ -2618,7 +2691,7 @@ void outputEPub(C,T)(  }  #+END_SRC -**** output files +**** write output files  #+name: output_epub_xhtml_seg  #+BEGIN_SRC d @@ -2671,6 +2744,12 @@ void epub_write_output_files(C,EpD,Mt,Mic,Ot,Oc)(      /+ OEBPS/content.opf +/      f = File(pth_epub.fn_oebps_content_opf(doc_matters.source_filename), "w");      f.writeln(oebps_content_opf); +    foreach (image; doc_matters.image_list) { +      if (exists("_sisu/image/"~ image)) { +        copy(("_sisu/image/"~ image), +          ((pth_epub.doc_oebps_image(doc_matters.source_filename)) ~ "/" ~ image)); +      } +    }    }    catch (ErrnoException ex) {      // Handle error diff --git a/org/sdp.org b/org/sdp.org index 032709f..46bd97a 100644 --- a/org/sdp.org +++ b/org/sdp.org @@ -575,6 +575,15 @@ struct DocumentMatters {      string _k = fn_src;      return _k;    } +  auto language() { +    string _k; +    if (auto m = match(fn_src, rgx.language_code_and_filename)) { +      _k = m.captures[1]; +    } else { +      _k = "en"; +    } +    return _k; +  }    auto file_insert_list() {      string[] _k = _0_header_1_body_content_2_insert_filelist_tuple[2];      return _k; diff --git a/src/sdp/abstraction.d b/src/sdp/abstraction.d index c1907f7..380be1d 100644 --- a/src/sdp/abstraction.d +++ b/src/sdp/abstraction.d @@ -100,6 +100,15 @@ template SiSUabstraction() {          string _k = fn_src;          return _k;        } +      auto language() { +        string _k; +        if (auto m = match(fn_src, rgx.language_code_and_filename)) { +          _k = m.captures[1]; +        } else { +          _k = "en"; +        } +        return _k; +      }        auto file_insert_list() {          string[] _k = _0_header_1_body_content_2_insert_filelist_tuple[2];          return _k; diff --git a/src/sdp/ao_defaults.d b/src/sdp/ao_defaults.d index 346c0c7..269b8c0 100644 --- a/src/sdp/ao_defaults.d +++ b/src/sdp/ao_defaults.d @@ -402,18 +402,21 @@ template SiSUpaths() {      string doc_lng(string fn_src, string lng) {        return chainPath(doc(fn_src), lng).array;      } -    string image(string fn_src) { -      return chainPath(base(fn_src), "image").array; -    }      string conf(string fn_src) { -      return chainPath(base(fn_src), "conf").array; +      return chainPath(doc(fn_src), "_sisu").array; +    } +    string image(string fn_src) { +      return chainPath(conf(fn_src), "image").array;      }      string css(string fn_src) { -      return chainPath(base(fn_src), "css").array; +      return chainPath(conf(fn_src), "css").array;      }      string fn_doc(string fn_src, string lng) {        return chainPath((doc_lng(fn_src, lng)), baseName(fn_src)).array;      } +    string fn_doc_insert(string fn_src, string fn_insert, string lng) { +      return chainPath((doc_lng(fn_src, lng)), baseName(fn_insert)).array; +    }    }    struct HtmlPaths {      string base_filename(string fn_src) { diff --git a/src/sdp/ao_rgx.d b/src/sdp/ao_rgx.d index b91ae35..91f5af5 100644 --- a/src/sdp/ao_rgx.d +++ b/src/sdp/ao_rgx.d @@ -188,5 +188,10 @@ template SiSUrgxInit() {      static bi_main_term_plus_rest_split                   = ctRegex!(`\s*:\s*`);      static bi_sub_terms_plus_obj_cite_number_offset_split = ctRegex!(`\s*\|\s*`);      static bi_term_and_obj_cite_numbers_match             = ctRegex!(`^(.+?)\+(\d+)`); +    /+ language codes +/ +    auto language_codes                                    = +       ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)"); +    auto language_code_and_filename                                    = +       ctRegex!("(am|bg|bn|br|ca|cs|cy|da|de|el|en|eo|es|et|eu|fi|fr|ga|gl|he|hi|hr|hy|ia|is|it|ja|ko|la|lo|lt|lv|ml|mr|nl|no|nn|oc|pl|pt|pt_BR|ro|ru|sa|se|sk|sl|sq|sr|sv|ta|te|th|tk|tr|uk|ur|vi|zh)/[A-Za-z0-9._-].+?[.](?:sst|ssm)$");    }  } diff --git a/src/sdp/output_epub.d b/src/sdp/output_epub.d index f914f16..f052d97 100644 --- a/src/sdp/output_epub.d +++ b/src/sdp/output_epub.d @@ -40,7 +40,7 @@ template outputEPub() {    </container>¶");      return o;    } -  string epub_oebps_content(C,M)(C contents, M doc_matters) { +  string epub_oebps_content(D,I)(D doc_abstraction, I doc_matters) {      string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere      string content = format(q"¶<?xml version='1.0' encoding='utf-8'?>    <?xml version='1.0' encoding='utf-8'?> @@ -75,12 +75,12 @@ template outputEPub() {        uuid,      );      foreach (sect; doc_matters.keys_seq_seg) { -      foreach (obj; contents[sect]) { +      foreach (obj; doc_abstraction[sect]) {        }      }      return content;    } -  string epub_oebps_toc(C,M)(C contents, M doc_matters) { +  string epub_oebps_toc(D,I)(D doc_abstraction, I doc_matters) {      int counter = 0;      string uuid = "18275d951861c77f78acd05672c9906924c59f18a2e0ba06dad95959693e9bd8"; // TODO shared elsewhere      auto markup = InlineMarkup(); @@ -113,7 +113,7 @@ template outputEPub() {        (doc_matters.dochead_meta["creator"]["author"].empty) ? "" : doc_matters.dochead_meta["creator"]["author"],          // author      );      foreach (sect; doc_matters.keys_seq_seg) { -      foreach (obj; contents[sect]) { +      foreach (obj; doc_abstraction[sect]) {          if (obj.is_a == "heading") {            foreach_reverse (k; 0 .. 7) {              switch (obj.dom_markedup[k]) { @@ -157,9 +157,9 @@ template outputEPub() {      return toc;    } -  void outputEPub(C,T)( -    auto ref const C         contents, -    auto ref T               doc_matters, +  void outputEPub(D,I)( +    auto ref const D         doc_abstraction, +    auto ref I               doc_matters,    ) {      mixin SiSUrgxInit;      auto xhtml_format = outputXHTMLs(); @@ -171,10 +171,10 @@ template outputEPub() {      string[] top_level_headings = ["","","",""];      auto mimetypes = epub_mimetypes;      auto meta_inf_container_xml = epub_container_xml; -    auto oebps_toc_ncx = epub_oebps_toc(contents, doc_matters); -    auto oebps_content_opf = epub_oebps_content(contents, doc_matters); +    auto oebps_toc_ncx = epub_oebps_toc(doc_abstraction, doc_matters); +    auto oebps_content_opf = epub_oebps_content(doc_abstraction, doc_matters);      foreach (part; doc_matters.keys_seq_seg) { -      foreach (obj; contents[part]) { +      foreach (obj; doc_abstraction[part]) {          if (obj.is_a == "heading") {            switch (obj.heading_lev_markup) {            case 0: .. case 3: @@ -214,100 +214,129 @@ template outputEPub() {            case 5: .. case 7:              doc_epub[segment_filename] ~= xhtml_format.heading(obj);              break; -          default: +          case 8: .. case 9: // unused numbers, if remain check              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -            } -            break; -          } -        } else if (obj.use == "frontmatter") { -          switch (obj.is_of) { -          case "para": -            switch (obj.is_a) { -            case "toc": -                doc_epub[segment_filename] ~= xhtml_format.toc(obj); -            break; -            default: -              // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -              break; +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +              writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check              }              break;            default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            if ((doc_matters.opt_action_bool["debug"])) { +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +            }              break;            } -        } else if (obj.use == "body") { -          switch (obj.is_of) { -          case "para": -            switch (obj.is_a) { +        } else { +          switch (obj.use) { +          case "frontmatter": +            switch (obj.is_of) {              case "para": -              doc_epub[segment_filename] ~= xhtml_format.para(obj); +              switch (obj.is_a) { +              case "toc": +                doc_epub[segment_filename] ~= xhtml_format.toc(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              default: -              // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); +              }                break;              }              break; -          case "block": -            switch (obj.is_a) { -            case "poem":                        // double check why both poem & verse -              break; -            case "verse": -              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); -              break; -            case "group": -              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +          case "body": +            switch (obj.is_of) { +            case "para": +              switch (obj.is_a) { +              case "para": +                doc_epub[segment_filename] ~= xhtml_format.para(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              case "block": -              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); -              break; -            case "quote": -              doc_epub[segment_filename] ~= xhtml_format.nugget(obj); -              break; -            case "table": -              doc_epub[segment_filename] ~= xhtml_format.para(obj); // -              break; -            case "code": -              doc_epub[segment_filename] ~= xhtml_format.code(obj); +              switch (obj.is_a) { +              case "poem":                        // double check why both poem & verse +                break; +              case "verse": +                doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "group": +                doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "block": +                doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "quote": +                doc_epub[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "table": +                doc_epub[segment_filename] ~= xhtml_format.para(obj); // +                break; +              case "code": +                doc_epub[segment_filename] ~= xhtml_format.code(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              default:                if ((doc_matters.opt_action_bool["debug"])) { -                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);                }                break;              }              break; -          default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); -            break; -          } -        } else if (obj.use == "backmatter") { -          switch (obj.is_of) { -          case "para": -            switch (obj.is_a) { -            case "endnote": -              doc_epub[segment_filename] ~= xhtml_format.endnote(obj); -              break; -            case "glossary": -              doc_epub[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "bibliography": -              doc_epub[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "bookindex": -              doc_epub[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "blurb": -              doc_epub[segment_filename] ~= xhtml_format.para(obj); +          case "backmatter": +            switch (obj.is_of) { +            case "para": +              switch (obj.is_a) { +              case "endnote": +                doc_epub[segment_filename] ~= xhtml_format.endnote(obj); +                break; +              case "glossary": +                doc_epub[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "bibliography": +                doc_epub[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "bookindex": +                doc_epub[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "blurb": +                doc_epub[segment_filename] ~= xhtml_format.para(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              default: -              // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); +              }                break;              }              break; +          case "comment": +            break;            default:              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              writeln(__FILE__, ":", __LINE__, ": ", obj.use);              }              break;            } @@ -372,6 +401,12 @@ template outputEPub() {        /+ OEBPS/content.opf +/        f = File(pth_epub.fn_oebps_content_opf(doc_matters.source_filename), "w");        f.writeln(oebps_content_opf); +      foreach (image; doc_matters.image_list) { +        if (exists("_sisu/image/"~ image)) { +          copy(("_sisu/image/"~ image), +            ((pth_epub.doc_oebps_image(doc_matters.source_filename)) ~ "/" ~ image)); +        } +      }      }      catch (ErrnoException ex) {        // Handle error diff --git a/src/sdp/output_html.d b/src/sdp/output_html.d index 1d55033..3af61ba 100644 --- a/src/sdp/output_html.d +++ b/src/sdp/output_html.d @@ -23,32 +23,9 @@ template outputHTML() {      output_xhtmls;    mixin outputXHTMLs; -  void scroll_write_output_file(Fn,C)( -    Fn fn_src, -    C doc, -  ) { -    debug(asserts){ -      static assert(is(typeof(fn_src) == string)); -      static assert(is(typeof(doc)    == string[])); -    } -    mixin SiSUpaths; -    auto pth_html = HtmlPaths(); -    try { -      if (!exists(pth_html.base)) { -        mkdirRecurse(pth_html.base); -      } -      auto f = File(pth_html.fn_scroll(fn_src), "w"); -      foreach (o; doc) { -        f.writeln(o); -      } -    } -    catch (ErrnoException ex) { -      // Handle error -    } -  } -  void scroll(C,T)( -    auto ref const C         contents, -    auto ref T               doc_matters, +  void scroll(D,I)( +    auto ref const D         doc_abstraction, +    auto ref I               doc_matters,    ) {      mixin SiSUrgxInit;      auto xhtml_format = outputXHTMLs(); @@ -56,8 +33,9 @@ template outputHTML() {      string[] doc_html;      string[] doc;      foreach (part; doc_matters.keys_seq_scroll) { -      foreach (obj; contents[part]) { -        if (obj.use == "frontmatter") { +      foreach (obj; doc_abstraction[part]) { +        switch (obj.use) { +        case "frontmatter":            switch (obj.is_of) {            case "para":              switch (obj.is_a) { @@ -76,11 +54,12 @@ template outputHTML() {              break;            default:              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);              }              break;            } -        } else if (obj.use == "body") { +          break; +        case "body":            switch (obj.is_of) {            case "para":              switch (obj.is_a) { @@ -132,7 +111,8 @@ template outputHTML() {              }              break;            } -        } else if (obj.use == "backmatter") { +          break; +        case "backmatter":            switch (obj.is_of) {            case "para":              switch (obj.is_a) { @@ -163,48 +143,50 @@ template outputHTML() {              break;            default:              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);              }              break;            } +          break; +        case "comment": +          break; +        default: +          if ((doc_matters.opt_action_bool["debug"])) { +            writeln(__FILE__, ":", __LINE__, ": ", obj.use); +          } +          break;          }        }      }      doc = xhtml_format.scroll_head(doc_matters.dochead_meta) ~ doc_html ~ xhtml_format.tail; -    scroll_write_output_file(doc_matters.source_filename, doc); +    scroll_write_output(doc_matters.source_filename, doc);    } -  void seg_write_output_files(M,C)( -    M doc_matters, -    C doc_html, +  void scroll_write_output(Fn,C)( +    Fn fn_src, +    C doc,    ) {      debug(asserts){ -      static assert(is(typeof(doc_html)      == string[][string])); +      static assert(is(typeof(fn_src) == string)); +      static assert(is(typeof(doc)    == string[]));      } -    mixin SiSUrgxInit; -    auto rgx = Rgx();      mixin SiSUpaths;      auto pth_html = HtmlPaths(); -    auto xhtml_format = outputXHTMLs(); -    auto m = matchFirst(doc_matters.source_filename, rgx.src_fn);      try { -      if (!exists(pth_html.seg(doc_matters.source_filename))) { -        mkdirRecurse(pth_html.seg(doc_matters.source_filename)); +      if (!exists(pth_html.base)) { +        mkdirRecurse(pth_html.base);        } -      foreach (seg_filename; doc_matters.segnames) { -        auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); -        foreach (docseg; doc_html[seg_filename]) { -          f.writeln(docseg); -        } -        f.writeln(xhtml_format.tail); // needed for each lev4 +      auto f = File(pth_html.fn_scroll(fn_src), "w"); +      foreach (o; doc) { +        f.writeln(o);        }      }      catch (ErrnoException ex) { -      // handle error +      // Handle error      }    } -  void seg(C,M)( -    auto ref const C         contents, -    auto ref M               doc_matters, +  void seg(D,I)( +    auto ref const D         doc_abstraction, +    auto ref I               doc_matters,    ) {      mixin SiSUrgxInit;      auto rgx = Rgx(); @@ -214,7 +196,7 @@ template outputHTML() {      string segment_filename;      string[] top_level_headings = ["","","",""];      foreach (part; doc_matters.keys_seq_seg) { -      foreach (obj; contents[part]) { +      foreach (obj; doc_abstraction[part]) {          if (obj.is_a == "heading") {                            // all headings: frontmatter, body & backmatter            switch (obj.heading_lev_markup) {            case 0: .. case 3: @@ -239,13 +221,13 @@ template outputHTML() {                top_level_headings[3] = "";                goto default;              default: -              top_level_headings[obj.heading_lev_markup] = xhtml_format.heading(obj); // should probably have different css tagging (fontsize etc) +              top_level_headings[obj.heading_lev_markup] = xhtml_format.heading(obj);                break;              }              break;            case 4:              segment_filename = obj.segment_anchor_tag; -            doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta); // consider placing seg_head here as can more easily populate it with lev4 info +            doc_html[segment_filename] ~= xhtml_format.seg_head(doc_matters.dochead_meta);              foreach (top_level_heading; top_level_headings) {                doc_html[segment_filename] ~= top_level_heading;              } @@ -254,107 +236,165 @@ template outputHTML() {            case 5: .. case 7:              doc_html[segment_filename] ~= xhtml_format.heading(obj);              break; -          default: +          case 8: .. case 9: // unused numbers, if remain check              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -            } -            break; -          } -        } else if (obj.use == "frontmatter") { -          switch (obj.is_of) { -          case "para": -            switch (obj.is_a) { -            case "toc": -                doc_html[segment_filename] ~= xhtml_format.toc(obj); -            break; -            default: -              // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); -              break; +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +              writeln(__FILE__, ":", __LINE__, ": ", obj.text); // check              }              break;            default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +            if ((doc_matters.opt_action_bool["debug"])) { +              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a, ": ", obj.heading_lev_markup); +            }              break;            } -        } else if (obj.use == "body") { -          switch (obj.is_of) { -          case "para": -            switch (obj.is_a) { +        } else { +          switch (obj.use) { +          case "frontmatter": +            switch (obj.is_of) {              case "para": -              doc_html[segment_filename] ~= xhtml_format.para(obj); +              switch (obj.is_a) { +              case "toc": +                doc_html[segment_filename] ~= xhtml_format.toc(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              default: -              // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              }                break;              }              break; -          case "block": -            switch (obj.is_a) { -            case "poem":                        // double check why both poem & verse -              break; -            case "verse": -              doc_html[segment_filename] ~= xhtml_format.nugget(obj); -              break; -            case "group": -              doc_html[segment_filename] ~= xhtml_format.nugget(obj); +          case "body": +            switch (obj.is_of) { +            case "para": +              switch (obj.is_a) { +              case "para": +                doc_html[segment_filename] ~= xhtml_format.para(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              case "block": -              doc_html[segment_filename] ~= xhtml_format.nugget(obj); -              break; -            case "quote": -              doc_html[segment_filename] ~= xhtml_format.nugget(obj); -              break; -            case "table": -              doc_html[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "code": -              doc_html[segment_filename] ~= xhtml_format.code(obj); +              switch (obj.is_a) { +              case "poem": +                break; +              case "verse": +                doc_html[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "group": +                doc_html[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "block": +                doc_html[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "quote": +                doc_html[segment_filename] ~= xhtml_format.nugget(obj); +                break; +              case "table": +                doc_html[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "code": +                doc_html[segment_filename] ~= xhtml_format.code(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              default:                if ((doc_matters.opt_action_bool["debug"])) { -                writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_of);                }                break;              }              break; -          default: -            // writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); -            break; -          } -        } else if (obj.use == "backmatter") { -          switch (obj.is_of) { -          case "para": -            switch (obj.is_a) { -            case "endnote": -              doc_html[segment_filename] ~= xhtml_format.endnote(obj); -              break; -            case "glossary": -              doc_html[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "bibliography": -              doc_html[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "bookindex": -              doc_html[segment_filename] ~= xhtml_format.para(obj); -              break; -            case "blurb": -              doc_html[segment_filename] ~= xhtml_format.para(obj); +          case "backmatter": +            switch (obj.is_of) { +            case "para": +              switch (obj.is_a) { +              case "endnote": +                doc_html[segment_filename] ~= xhtml_format.endnote(obj); +                break; +              case "glossary": +                doc_html[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "bibliography": +                doc_html[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "bookindex": +                doc_html[segment_filename] ~= xhtml_format.para(obj); +                break; +              case "blurb": +                doc_html[segment_filename] ~= xhtml_format.para(obj); +                break; +              default: +                if ((doc_matters.opt_action_bool["debug"])) { +                  writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +                } +                break; +              }                break;              default: -              // writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              if ((doc_matters.opt_action_bool["debug"])) { +                writeln(__FILE__, ":", __LINE__, ": ", obj.is_of); +              }                break;              }              break; +          case "comment": +            break;            default:              if ((doc_matters.opt_action_bool["debug"])) { -              writeln(__FILE__, ":", __LINE__, ": ", obj.is_a); +              writeln(__FILE__, ":", __LINE__, ": ", obj.use);              }              break;            }          }        }      } -    seg_write_output_files(doc_matters, doc_html); +    seg_write_output(doc_matters, doc_html); +  } +  void seg_write_output(M,C)( +    M doc_matters, +    C doc_html, +  ) { +    debug(asserts){ +      static assert(is(typeof(doc_html)      == string[][string])); +    } +    mixin SiSUrgxInit; +    auto rgx = Rgx(); +    mixin SiSUpaths; +    auto pth_html = HtmlPaths(); +    auto xhtml_format = outputXHTMLs(); +    auto m = matchFirst(doc_matters.source_filename, rgx.src_fn); +    try { +      if (!exists(pth_html.seg(doc_matters.source_filename))) { +        mkdirRecurse(pth_html.seg(doc_matters.source_filename)); +      } +      foreach (seg_filename; doc_matters.segnames) { +        auto f = File(pth_html.fn_seg(doc_matters.source_filename, seg_filename), "w"); +        foreach (docseg; doc_html[seg_filename]) { +          f.writeln(docseg); +        } +        f.writeln(xhtml_format.tail); // needed for each lev4 +      } +    } +    catch (ErrnoException ex) { +      // handle error +    }    }    auto html_css() {      string css; diff --git a/src/sdp/source_sisupod.d b/src/sdp/source_sisupod.d index 9ed2c97..8a24d55 100644 --- a/src/sdp/source_sisupod.d +++ b/src/sdp/source_sisupod.d @@ -21,9 +21,9 @@ template SiSUpod() {    import      ao_rgx,      output_xhtmls; -      void SiSUpod(T)(T doc_matters) {      debug(asserts){ +      // static assert(is(typeof(doc_matters) == tuple));      }      mixin SiSUrgxInit;      mixin SiSUpaths; @@ -31,23 +31,6 @@ template SiSUpod() {      mixin SiSUlanguageCodes;      auto lang = Lang();      auto rgx = Rgx(); -    /+ -      dir structure -      /tmp/_sisu_processing_/ralph/sisupod -        ├── conf -        ├── css (unless should be within conf?) -        ├── doc -        │   ├── en -        │   ├── es -        │   ├── fr -        │   └── zh -        └── image -   -      - tasks -        - create directory structure -        - map other language directories -          - check for corresponding files within -    +/      assert (match(doc_matters.source_filename, rgx.src_fn));      try {        /+ create directory structure +/ @@ -63,51 +46,61 @@ template SiSUpod() {        if (!exists(pth_sisupod.image(doc_matters.source_filename))) {          mkdirRecurse(pth_sisupod.image(doc_matters.source_filename));        } -      /+ copy relevant files +/ +      if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language))) { +        mkdirRecurse(pth_sisupod.doc_lng(doc_matters.source_filename, doc_matters.language)); +      }        debug(sisupod) {          writeln(__LINE__, ": ",            // doc_matters.environment["pwd"], "/",              doc_matters.source_filename, " -> ",            // doc_matters.environment["pwd"], "/", -            pth_sisupod.fn_doc(doc_matters.source_filename, "en") -        ); -      } -      // need to extract language code directories (from directory structure or filenames & have a default) -      if (!exists(pth_sisupod.doc_lng(doc_matters.source_filename, "en"))) { -        mkdirRecurse(pth_sisupod.doc_lng(doc_matters.source_filename, "en")); +            pth_sisupod.fn_doc( +              doc_matters.source_filename, +              doc_matters.language +        ));        }        if (exists(doc_matters.source_filename)) { -        copy(doc_matters.source_filename, -          pth_sisupod.fn_doc(doc_matters.source_filename, "en")); +        copy( +          doc_matters.source_filename, +          pth_sisupod.fn_doc( +            doc_matters.source_filename, +            doc_matters.language +        ));        }        if (doc_matters.file_insert_list.length > 0) {          foreach (insert_file; doc_matters.file_insert_list) {            debug(sisupod) {              writeln( -              // doc_matters.environment["pwd"], "/",                  insert_file, " -> ", -              // doc_matters.environment["pwd"], "/", -                pth_sisupod.fn_doc(doc_matters.source_filename, "en") -            ); +                pth_sisupod.fn_doc_insert( +                  doc_matters.source_filename, +                  insert_file, +                  doc_matters.language +            ));            }            if (exists(insert_file)) { -            copy(insert_file, -              pth_sisupod.fn_doc(doc_matters.source_filename, "en")); +            copy( +              insert_file, +              pth_sisupod.fn_doc_insert( +                doc_matters.source_filename, +                insert_file, +                doc_matters.language +            ));            }          }        }        foreach (image; doc_matters.image_list) {          debug(sisupod) {            writeln( -            // doc_matters.environment["pwd"], "/",                "_sisu/image/", image, " -> ", -            // doc_matters.environment["pwd"], "/",                pth_sisupod.image(doc_matters.source_filename), "/", image            );          }          if (exists("_sisu/image/"~ image)) { -          copy(("_sisu/image/"~ image), -            (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image)); +          copy( +            ("_sisu/image/"~ image), +            (pth_sisupod.image(doc_matters.source_filename) ~ "/" ~ image) +          );          }        }      } @@ -115,6 +108,4 @@ template SiSUpod() {        // Handle error      }    } -   -    } | 
