Module: IsoDoc::Gb::BaseConvert
- Included in:
- HtmlConvert, WordConvert
- Defined in:
- lib/isodoc/gb/base_convert.rb
Constant Summary collapse
- EXAMPLE_TBL_ATTR =
{ class: "example_label", style: "padding:2pt 2pt 2pt 2pt;vertical-align:top;" }.freeze
Instance Method Summary collapse
- #clausedelimspace(out) ⇒ Object
- #cleanup(docxml) ⇒ Object
- #deprecated_term_parse(node, out) ⇒ Object
- #end_line(_isoxml, out) ⇒ Object
- #error_parse(node, out) ⇒ Object
- #example_cleanup(docxml) ⇒ Object
- #example_p_parse(node, div) ⇒ Object
- #example_parse(node, out) ⇒ Object
- #example_parse1(node, div) ⇒ Object
- #example_span_label(node, div, name) ⇒ Object
- #formula_dl_parse(node, out) ⇒ Object
- #formula_parse1(node, out) ⇒ Object
- #formula_where(dl, out) ⇒ Object
- #middle(isoxml, out) ⇒ Object
- #node_begins_with_para(node) ⇒ Object
- #note_delim ⇒ Object
- #note_parse(node, out) ⇒ Object
- #note_parse_table(node, out) ⇒ Object
- #note_parse_table1(node, out, name) ⇒ Object
- #omit_docid_prefix(prefix) ⇒ Object
- #scss_fontheader ⇒ Object
- #string_parse(node, out) ⇒ Object
- #termnote_parse(node, out) ⇒ Object
- #termref_render(x) ⇒ Object
- #termref_resolve(docxml) ⇒ Object
- #textcleanup(docxml) ⇒ Object
Instance Method Details
#clausedelimspace(out) ⇒ Object
162 163 164 |
# File 'lib/isodoc/gb/base_convert.rb', line 162 def clausedelimspace(out) out << " " end |
#cleanup(docxml) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/isodoc/gb/base_convert.rb', line 18 def cleanup(docxml) @i18n ||= i18n_init(@lang, @script) @cleanup = Cleanup.new(@script, @i18n.deprecated) super @cleanup.cleanup(docxml) docxml end |
#deprecated_term_parse(node, out) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/isodoc/gb/base_convert.rb', line 136 def deprecated_term_parse(node, out) out.p **{ class: "DeprecatedTerms" } do |p| p << l10n("#{@i18n.deprecated}: ") node.children.each { |c| parse(c, p) } end end |
#end_line(_isoxml, out) ⇒ Object
113 114 115 |
# File 'lib/isodoc/gb/base_convert.rb', line 113 def end_line(_isoxml, out) out.hr **{ width: "25%" } end |
#error_parse(node, out) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/isodoc/gb/base_convert.rb', line 117 def error_parse(node, out) # catch elements not defined in ISO case node.name when "string" then string_parse(node, out) else super end end |
#example_cleanup(docxml) ⇒ Object
26 27 28 29 |
# File 'lib/isodoc/gb/base_convert.rb', line 26 def example_cleanup(docxml) super @cleanup.example_cleanup(docxml) end |
#example_p_parse(node, div) ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/isodoc/gb/base_convert.rb', line 172 def example_p_parse(node, div) name = node&.at(ns("./name"))&.remove div.p do |p| example_span_label(node, p, name) insert_tab(p, 1) node.first_element_child.children.each { |n| parse(n, p) } end node.element_children[1..-1].each { |n| parse(n, div) } end |
#example_parse(node, out) ⇒ Object
199 200 201 202 203 204 |
# File 'lib/isodoc/gb/base_convert.rb', line 199 def example_parse(node, out) out.div **{ id: node["id"], class: "example" } do |div| node_begins_with_para(node) ? example_p_parse(node, div) : example_parse1(node, div) end end |
#example_parse1(node, div) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/isodoc/gb/base_convert.rb', line 182 def example_parse1(node, div) div.p do |p| example_span_label(node, p, node.at(ns("./name"))) insert_tab(p, 1) end node.children.each { |n| parse(n, div) unless n.name == "name" } end |
#example_span_label(node, div, name) ⇒ Object
166 167 168 169 170 |
# File 'lib/isodoc/gb/base_convert.rb', line 166 def example_span_label(node, div, name) div.span **{ class: "example_label" } do |p| name and name.children.each { |n| parse(n, div) } end end |
#formula_dl_parse(node, out) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/isodoc/gb/base_convert.rb', line 55 def formula_dl_parse(node, out) out.table **{ class: "formula_dl" } do |v| node.elements.each_slice(2) do |dt, dd| v.tr do |tr| tr.td **{ style: "vertical-align:top;text-align:left;" } do |term| dt_parse(dt, term) end tr.td(**{ style: "vertical-align:top;" }) { |td| td << "—" } tr.td **{ style: "vertical-align:top;" } do |listitem| dd.children.each { |n| parse(n, listitem) } end end end end end |
#formula_parse1(node, out) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/isodoc/gb/base_convert.rb', line 35 def formula_parse1(node, out) out.div **attr_code(class: "formula") do |div| insert_tab(div, 1) parse(node.at(ns("./stem")), div) lbl = node&.at(ns("./name"))&.text unless lbl.nil? insert_tab(div, 1) div << "(#{lbl})" end end end |
#formula_where(dl, out) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/isodoc/gb/base_convert.rb', line 47 def formula_where(dl, out) return unless dl out.p **{ style: "page-break-after:avoid;"} do |p| p << @i18n.where end formula_dl_parse(dl, out) end |
#middle(isoxml, out) ⇒ Object
108 109 110 111 |
# File 'lib/isodoc/gb/base_convert.rb', line 108 def middle(isoxml, out) super end_line(isoxml, out) end |
#node_begins_with_para(node) ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/isodoc/gb/base_convert.rb', line 190 def node_begins_with_para(node) node.elements.each do |e| next if e.name == "name" return true if e.name == "p" return false end false end |
#note_delim ⇒ Object
75 76 77 |
# File 'lib/isodoc/gb/base_convert.rb', line 75 def note_delim l10n(": ") end |
#note_parse(node, out) ⇒ Object
79 80 81 |
# File 'lib/isodoc/gb/base_convert.rb', line 79 def note_parse(node, out) note_parse_table(node, out) end |
#note_parse_table(node, out) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/isodoc/gb/base_convert.rb', line 83 def note_parse_table(node, out) @note = true name = node&.at(ns("./name"))&.remove note_parse_table1(node, out, name) @note = false end |
#note_parse_table1(node, out, name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/isodoc/gb/base_convert.rb', line 90 def note_parse_table1(node, out, name) out.table **note_attrs(node) do |t| t.tr do |tr| tr.td **EXAMPLE_TBL_ATTR do |td| name and name.children.each { |n| parse(n, td) } td << note_delim end tr.td **{ style: "vertical-align:top;", class: "Note" } do |td| node.children.each { |n| parse(n, td) } end end end end |
#omit_docid_prefix(prefix) ⇒ Object
31 32 33 |
# File 'lib/isodoc/gb/base_convert.rb', line 31 def omit_docid_prefix(prefix) super || prefix == "Chinese Standard" end |
#scss_fontheader ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/gb/base_convert.rb', line 9 def scss_fontheader b = [:bodyfont] || "Arial" h = [:headerfont] || "Arial" m = [:monospacefont] || "Courier" t = [:titlefont] || "Arial" "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\ "$titlefont: #{t};\n" end |
#string_parse(node, out) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/isodoc/gb/base_convert.rb', line 126 def string_parse(node, out) if node["script"] == "Hant" out.span **{ class: "Hant" } do |s| node.children.each { |c| parse(c, s) } end else node.children.each { |c| parse(c, out) } end end |
#termnote_parse(node, out) ⇒ Object
104 105 106 |
# File 'lib/isodoc/gb/base_convert.rb', line 104 def termnote_parse(node, out) note_parse_table(node, out) end |
#termref_render(x) ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/isodoc/gb/base_convert.rb', line 143 def termref_render(x) x.sub!(%r{\s*\[MODIFICATION\]\s*$}m, l10n(", #{@i18n.modified}")) parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m) parts[1] = l10n(", #{@i18n.source}") if parts.size > 1 && parts[1] == "," && !/^\s*#{@i18n.modified}/.match(parts[2]) parts.map do |p| /\s*\[MODIFICATION\]/.match(p) ? l10n(", #{@i18n.modified} — ") : p end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]")) end |
#termref_resolve(docxml) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/isodoc/gb/base_convert.rb', line 154 def termref_resolve(docxml) docxml.gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, l10n("; ")). split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4). map do |a| a.size < 3 ? a[0] : a[0] + termref_render(a[2]) end.join end |
#textcleanup(docxml) ⇒ Object
206 207 208 |
# File 'lib/isodoc/gb/base_convert.rb', line 206 def textcleanup(docxml) termref_resolve(docxml) end |