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
- #clause_name(num, title, div, header_class) ⇒ Object
- #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_label(node) ⇒ Object
- #example_p_parse(node, div) ⇒ Object
- #example_parse(node, out) ⇒ Object
- #example_parse1(node, div) ⇒ Object
- #example_span_label(node, div, name) ⇒ Object
- #foreword(isoxml, out) ⇒ Object
- #formula_dl_parse(node, out) ⇒ Object
- #formula_parse(node, out) ⇒ Object
- #formula_where(dl, out) ⇒ Object
- #i18n_init(lang, script) ⇒ Object
- #metadata_init(lang, script, labels) ⇒ Object
- #middle(isoxml, out) ⇒ Object
- #node_begins_with_para(node) ⇒ Object
- #note_parse(node, out) ⇒ Object
- #note_parse_table(node, out, label) ⇒ 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
#clause_name(num, title, div, header_class) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/isodoc/gb/base_convert.rb', line 200 def clause_name(num, title, div, header_class) header_class = {} if header_class.nil? div.h1 **attr_code(header_class) do |h1| if num && !@suppressheadingnumbers h1 << "#{num}." h1 << " " end title.is_a?(String) ? h1 << title : title&.children&.each { |c2| parse(c2, h1) } end div.parent.at(".//h1") end |
#clausedelimspace(out) ⇒ Object
196 197 198 |
# File 'lib/isodoc/gb/base_convert.rb', line 196 def clausedelimspace(out) out << " " end |
#cleanup(docxml) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/isodoc/gb/base_convert.rb', line 29 def cleanup(docxml) @cleanup = Cleanup.new(@script, @deprecated_lbl) super @cleanup.cleanup(docxml) docxml end |
#deprecated_term_parse(node, out) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/isodoc/gb/base_convert.rb', line 158 def deprecated_term_parse(node, out) out.p **{ class: "DeprecatedTerms" } do |p| p << l10n("#{@deprecated_lbl}: ") node.children.each { |c| parse(c, p) } end end |
#end_line(_isoxml, out) ⇒ Object
135 136 137 |
# File 'lib/isodoc/gb/base_convert.rb', line 135 def end_line(_isoxml, out) out.hr **{ width: "25%" } end |
#error_parse(node, out) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/isodoc/gb/base_convert.rb', line 139 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
36 37 38 39 |
# File 'lib/isodoc/gb/base_convert.rb', line 36 def example_cleanup(docxml) super @cleanup.example_cleanup(docxml) end |
#example_label(node) ⇒ Object
102 103 104 |
# File 'lib/isodoc/gb/base_convert.rb', line 102 def example_label(node) l10n(super + ":") end |
#example_p_parse(node, div) ⇒ Object
224 225 226 227 228 229 230 231 232 |
# File 'lib/isodoc/gb/base_convert.rb', line 224 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
251 252 253 254 255 256 |
# File 'lib/isodoc/gb/base_convert.rb', line 251 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
234 235 236 237 238 239 240 |
# File 'lib/isodoc/gb/base_convert.rb', line 234 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
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/isodoc/gb/base_convert.rb', line 213 def example_span_label(node, div, name) n = @xrefs.get[node["id"]] div.span **{ class: "example_label" } do |p| lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @example_lbl : l10n("#{@example_lbl} #{n[:label]}") p << l10n(lbl + ":") name and !lbl.nil? and p << " — " name and name.children.each { |n| parse(n, div) } end end |
#foreword(isoxml, out) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/isodoc/gb/base_convert.rb', line 184 def foreword(isoxml, out) f = isoxml.at(ns("//foreword")) || return page_break(out) out.div do |s| s.h1 **{ class: "ForewordTitle" } do |h1| h1 << "#{@foreword_lbl} " # insert_tab(h1, 1) end f.elements.each { |e| parse(e, s) unless e.name == "title" } end end |
#formula_dl_parse(node, out) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/isodoc/gb/base_convert.rb', line 82 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_parse(node, out) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/isodoc/gb/base_convert.rb', line 59 def formula_parse(node, out) out.div **formula_attrs(node) do |div1| div1.div **attr_code(class: "formula") do |div| insert_tab(div, 1) parse(node.at(ns("./stem")), div) lbl = @xrefs.anchor(node['id'], :label, false) unless lbl.nil? insert_tab(div, 1) div << "(#{lbl})" end end formula_where(node.at(ns("./dl")), div1) end end |
#formula_where(dl, out) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/isodoc/gb/base_convert.rb', line 74 def formula_where(dl, out) return unless dl out.p **{ style: "page-break-after:avoid;"} do |p| p << @where_lbl end formula_dl_parse(dl, out) end |
#i18n_init(lang, script) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/isodoc/gb/base_convert.rb', line 41 def i18n_init(lang, script) super y = if lang == "en" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) elsif lang == "zh" && script == "Hans" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) else YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) end @labels = @labels.merge(y) end |
#metadata_init(lang, script, labels) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/isodoc/gb/base_convert.rb', line 19 def (lang, script, labels) unless ["en", "zh"].include? lang lang = "zh" script = "Hans" end @meta = Metadata.new(lang, script, labels) @meta.set(:standardclassimg, @standardclassimg) @common. = @meta end |
#middle(isoxml, out) ⇒ Object
130 131 132 133 |
# File 'lib/isodoc/gb/base_convert.rb', line 130 def middle(isoxml, out) super end_line(isoxml, out) end |
#node_begins_with_para(node) ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'lib/isodoc/gb/base_convert.rb', line 242 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_parse(node, out) ⇒ Object
106 107 108 |
# File 'lib/isodoc/gb/base_convert.rb', line 106 def note_parse(node, out) note_parse_table(node, out, note_label(node) + ":") end |
#note_parse_table(node, out, label) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/isodoc/gb/base_convert.rb', line 110 def note_parse_table(node, out, label) @note = true out.table **note_attrs(node) do |t| t.tr do |tr| @libdir = File.dirname(__FILE__) tr.td **EXAMPLE_TBL_ATTR do |td| td << l10n(label) end tr.td **{ style: "vertical-align:top;", class: "Note" } do |td| node.children.each { |n| parse(n, td) } end end end @note = false end |
#omit_docid_prefix(prefix) ⇒ Object
55 56 57 |
# File 'lib/isodoc/gb/base_convert.rb', line 55 def omit_docid_prefix(prefix) super || prefix == "Chinese Standard" end |
#scss_fontheader ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/isodoc/gb/base_convert.rb', line 10 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
148 149 150 151 152 153 154 155 156 |
# File 'lib/isodoc/gb/base_convert.rb', line 148 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
126 127 128 |
# File 'lib/isodoc/gb/base_convert.rb', line 126 def termnote_parse(node, out) note_parse_table(node, out, "#{@xrefs.anchor(node['id'], :label)}:") end |
#termref_render(x) ⇒ Object
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/isodoc/gb/base_convert.rb', line 165 def termref_render(x) x.sub!(%r{\s*\[MODIFICATION\]\s*$}m, l10n(", #{@modified_lbl}")) parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m) parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 && parts[1] == "," && !/^\s*#{@modified_lbl}/.match(parts[2]) parts.map do |p| /\s*\[MODIFICATION\]/.match(p) ? l10n(", #{@modified_lbl} — ") : p end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]")) end |
#termref_resolve(docxml) ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/isodoc/gb/base_convert.rb', line 176 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
258 259 260 |
# File 'lib/isodoc/gb/base_convert.rb', line 258 def textcleanup(docxml) termref_resolve(docxml) end |