Module: IsoDoc::Itu::BaseConvert
- Included in:
- HtmlConvert, WordConvert
- Defined in:
- lib/isodoc/itu/ref.rb,
lib/isodoc/itu/terms.rb,
lib/isodoc/itu/cleanup.rb,
lib/isodoc/itu/base_convert.rb
Constant Summary collapse
- FRONT_CLAUSE =
"//*[parent::preface]" \ "[not(local-name() = 'abstract')]".freeze
Instance Method Summary collapse
- #acknowledgements(clause, out) ⇒ Object
- #annex(node, out) ⇒ Object
- #annex_name(_annex, name, div) ⇒ Object
- #bibitem_entry(list, bibitem, _ordinal, biblio) ⇒ Object
- #biblio_list(clause, div, biblio) ⇒ Object
-
#clause(clause, out) ⇒ Object
can have supertitle in resolution.
- #clause_attrs(node) ⇒ Object
- #clausedelim ⇒ Object
- #cleanup(docxml) ⇒ Object
- #dl1(dlist) ⇒ Object
- #dl2tbody(dlist) ⇒ Object
- #dl_parse(node, out) ⇒ Object
- #foreword(clause, out) ⇒ Object
- #info(isoxml, out) ⇒ Object
- #introduction(clause, out) ⇒ Object
-
#note_p_parsex(node, div) ⇒ Object
TODO kill.
- #note_parse(node, out) ⇒ Object
-
#note_parse1x(node, div) ⇒ Object
TODO kill.
-
#ol_depthx(node) ⇒ Object
KILL.
- #para_class(node) ⇒ Object
- #preface_normal(clause, out) ⇒ Object
- #refs_cleanup(docxml) ⇒ Object
- #term_cleanup(docxml) ⇒ Object
- #term_cleanup1(docxml) ⇒ Object
- #term_cleanup2(docxml) ⇒ Object
- #termdef_parse(node, out) ⇒ Object
- #termdef_parse1(node, div, defn, source) ⇒ Object
- #title_cleanup(docxml) ⇒ Object
Instance Method Details
#acknowledgements(clause, out) ⇒ Object
28 29 30 |
# File 'lib/isodoc/itu/base_convert.rb', line 28 def acknowledgements(clause, out) introduction(clause, out) end |
#annex(node, out) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/isodoc/itu/base_convert.rb', line 65 def annex(node, out) @meta.get[:doctype_original] == "recommendation-annex" or page_break(out) out.div **attr_code(id: node["id"], class: "Section3") do |s| annex_name(node, nil, s) unless node.at(ns("./fmt-title")) node.elements.each do |c1| if c1.name == "fmt-title" then annex_name(node, c1, s) else parse(c1, s) end end end end |
#annex_name(_annex, name, div) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/isodoc/itu/base_convert.rb', line 58 def annex_name(_annex, name, div) r_a = @meta.get[:doctype_original] == "recommendation-annex" div.h1 class: r_a ? "RecommendationAnnex" : "Annex" do |t| name&.children&.each { |c2| parse(c2, t) } end end |
#bibitem_entry(list, bibitem, _ordinal, biblio) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/itu/ref.rb', line 8 def bibitem_entry(list, bibitem, _ordinal, biblio) list.tr **attr_code(iso_bibitem_entry_attrs(bibitem, biblio)) do |ref| ref.td style: "vertical-align:top" do |td| tag = bibitem.at(ns("./biblio-tag")) tag&.children&.each { |n| parse(n, td) } end ref.td { |td| reference_format(bibitem, td) } end end |
#biblio_list(clause, div, biblio) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/isodoc/itu/ref.rb', line 18 def biblio_list(clause, div, biblio) div.table class: "biblio", border: "0" do |t| i = 0 t.tbody do |tbody| clause.elements.each do |b| if b.name == "bibitem" b["hidden"] == "true" and next i += 1 bibitem_entry(tbody, b, i, biblio) else unless %w(title clause references fmt-title fmt-xref-label).include? b.name tbody.tx { |tx| parse(b, tx) } end end end end end clause.xpath(ns("./clause | ./references")).each { |x| parse(x, div) } end |
#clause(clause, out) ⇒ Object
can have supertitle in resolution
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/isodoc/itu/base_convert.rb', line 122 def clause(clause, out) out.div **attr_code(clause_attrs(clause)) do |s| clause.elements.each do |c1| if c1.name == "fmt-title" then clause_name(clause, c1, s, nil) else parse(c1, s) end end end end |
#clause_attrs(node) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/isodoc/itu/base_convert.rb', line 114 def clause_attrs(node) if node["type"] == "keyword" super.merge(class: "Keyword") else super end end |
#clausedelim ⇒ Object
36 37 38 |
# File 'lib/isodoc/itu/base_convert.rb', line 36 def clausedelim "" end |
#cleanup(docxml) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/isodoc/itu/cleanup.rb', line 4 def cleanup(docxml) super term_cleanup(docxml) refs_cleanup(docxml) title_cleanup(docxml) end |
#dl1(dlist) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/isodoc/itu/base_convert.rb', line 139 def dl1(dlist) ret = dl2tbody(dlist) n = dlist.at(ns("./colgroup")) and ret = "#{n.remove.to_xml}#{ret}" n = dlist.at(ns("./fmt-name")) and ret = "#{n.remove.to_xml}#{ret}" dlist.name = "table" dlist["class"] = "dl" dlist.children.first.previous = ret end |
#dl2tbody(dlist) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/isodoc/itu/base_convert.rb', line 148 def dl2tbody(dlist) ret = "" dlist.elements.select { |n| %w{dt dd}.include? n.name } .each_slice(2) do |dt, dd| ret += "<tr><th width='20%'>#{dt.children.to_xml}</th>" \ "<td width='80%'>#{dd.children.to_xml}</td></tr>" dt.replace(" ") dd.remove end "<tbody>#{ret}</tbody>" end |
#dl_parse(node, out) ⇒ Object
133 134 135 136 137 |
# File 'lib/isodoc/itu/base_convert.rb', line 133 def dl_parse(node, out) node.ancestors("table, formula, figure").empty? or return super dl1(node) table_parse(node, out) end |
#foreword(clause, out) ⇒ Object
24 25 26 |
# File 'lib/isodoc/itu/base_convert.rb', line 24 def foreword(clause, out) introduction(clause, out) end |
#info(isoxml, out) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/isodoc/itu/base_convert.rb', line 79 def info(isoxml, out) @meta.ip_notice_received isoxml, out @meta.techreport isoxml, out @meta.contribution isoxml, out super end |
#introduction(clause, out) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/isodoc/itu/base_convert.rb', line 14 def introduction(clause, out) title = clause.at(ns("./fmt-title")) out.div **attr_code(clause_attrs(clause)) do |s| clause_name(clause, title, s, class: "IntroTitle") clause.elements.reject { |c1| c1.name == "fmt-title" }.each do |c1| parse(c1, s) end end end |
#note_p_parsex(node, div) ⇒ Object
TODO kill
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/itu/base_convert.rb', line 87 def note_p_parsex(node, div) name = node.at(ns("./name"))&.remove div.p do |p| name and p.span class: "note_label" do |s| name.children.each { |n| parse(n, s) } end node.first_element_child.children.each { |n| parse(n, p) } end node.element_children[1..-1].each { |n| parse(n, div) } end |
#note_parse(node, out) ⇒ Object
109 110 111 112 |
# File 'lib/isodoc/itu/base_convert.rb', line 109 def note_parse(node, out) node["type"] == "title-footnote" and return super end |
#note_parse1x(node, div) ⇒ Object
TODO kill
99 100 101 102 103 104 105 106 107 |
# File 'lib/isodoc/itu/base_convert.rb', line 99 def note_parse1x(node, div) name = node.at(ns("./name"))&.remove div.p do |p| name and p.span class: "note_label" do |s| name.children.each { |n| parse(n, s) } end end node.children.each { |n| parse(n, div) } end |
#ol_depthx(node) ⇒ Object
KILL
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/isodoc/itu/base_convert.rb', line 46 def ol_depthx(node) node["class"] == "steps" || node.at(".//ancestor::xmlns:ol[@class = 'steps']") or return super depth = node.ancestors("ul, ol").size + 1 type = :arabic type = :alphabet if [2, 7].include? depth type = :roman if [3, 8].include? depth type = :alphabet_upper if [4, 9].include? depth type = :roman_upper if [5, 10].include? depth ol_style(type) end |
#para_class(node) ⇒ Object
40 41 42 43 |
# File 'lib/isodoc/itu/base_convert.rb', line 40 def para_class(node) node["class"] == "supertitle" and return "supertitle" super end |
#preface_normal(clause, out) ⇒ Object
32 33 34 |
# File 'lib/isodoc/itu/base_convert.rb', line 32 def preface_normal(clause, out) introduction(clause, out) end |
#refs_cleanup(docxml) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/isodoc/itu/cleanup.rb', line 42 def refs_cleanup(docxml) docxml.xpath("//tx[following-sibling::tx]").each do |tx| tx << tx.next_element.remove.children end docxml.xpath("//tx").each do |tx| tx.name = "td" tx["colspan"] = "2" tx.wrap("<tr></tr>") end docxml end |
#term_cleanup(docxml) ⇒ Object
19 20 21 22 23 |
# File 'lib/isodoc/itu/cleanup.rb', line 19 def term_cleanup(docxml) term_cleanup1(docxml) term_cleanup2(docxml) docxml end |
#term_cleanup1(docxml) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/isodoc/itu/cleanup.rb', line 25 def term_cleanup1(docxml) docxml.xpath("//p[@class = 'Terms']").each do |d| h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]") d.add_first_child "<b>#{h2.children.to_xml}</b> " d["id"] = h2["id"] h2.remove end end |
#term_cleanup2(docxml) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/isodoc/itu/cleanup.rb', line 34 def term_cleanup2(docxml) docxml.xpath("//p[@class = 'TermNum']").each do |d| (d1 = d.next_element and d1.name == "p") or next d1.children.each { |e| e.parent = d } d1.remove end end |
#termdef_parse(node, out) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/isodoc/itu/terms.rb', line 16 def termdef_parse(node, out) defn = node.at(ns("./fmt-definition")) source = node.at(ns("./fmt-termsource//fmt-origin/@citeas")) out.div **attr_code(id: node["id"]) do |div| termdef_parse1(node, div, defn, source) node.children.each do |n| next if %w(fmt-preferred fmt-definition fmt-termsource fmt-title fmt-name).include? n.name parse(n, out) end end end |
#termdef_parse1(node, div, defn, source) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/isodoc/itu/terms.rb', line 4 def termdef_parse1(node, div, defn, source) div.p **{ class: "TermNum", id: node["id"] } do |p| p.b do |b| node&.at(ns("./fmt-name"))&.children&.each { |n| parse(n, b) } insert_tab(b, 1) node&.at(ns("./fmt-preferred"))&.children&.each { |n| parse(n, b) } end source and p << "#{source.value} " end defn&.children&.each { |n| parse(n, div) } end |
#title_cleanup(docxml) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/isodoc/itu/cleanup.rb', line 11 def title_cleanup(docxml) docxml.xpath("//h1[@class = 'RecommendationAnnex']").each do |h| h.name = "p" h["class"] = "h1Annex" end docxml end |