metanorma-gb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.hound.yml +3 -0
  4. data/.oss-guides.rubocop.yml +1077 -0
  5. data/.rubocop.ribose.yml +65 -0
  6. data/.rubocop.tb.yml +650 -0
  7. data/.rubocop.yml +15 -0
  8. data/.travis.yml +15 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE +25 -0
  12. data/README.adoc +369 -0
  13. data/Rakefile +6 -0
  14. data/asciidoctor-gb.gemspec.old +47 -0
  15. data/bin/console +14 -0
  16. data/bin/rspec +18 -0
  17. data/bin/setup +8 -0
  18. data/lib/asciidoctor-gb.rb +11 -0
  19. data/lib/asciidoctor/gb.rb +7 -0
  20. data/lib/asciidoctor/gb/biblio.rng +836 -0
  21. data/lib/asciidoctor/gb/converter.rb +224 -0
  22. data/lib/asciidoctor/gb/front.rb +228 -0
  23. data/lib/asciidoctor/gb/gbstandard.rng +409 -0
  24. data/lib/asciidoctor/gb/html/blank.png +0 -0
  25. data/lib/asciidoctor/gb/html/footer.png +0 -0
  26. data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.png +0 -0
  27. data/lib/asciidoctor/gb/html/gb-logos/gb-issuer-default.svg +980 -0
  28. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.gif +0 -0
  29. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.png +0 -0
  30. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-db.svg +1 -0
  31. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.gif +0 -0
  32. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.png +0 -0
  33. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gb.svg +1 -0
  34. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
  35. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.png +0 -0
  36. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
  37. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.gif +0 -0
  38. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.png +0 -0
  39. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-gm.svg +1 -0
  40. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
  41. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.png +0 -0
  42. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
  43. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.gif +0 -0
  44. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.png +0 -0
  45. data/lib/asciidoctor/gb/html/gb-logos/gb-standard-zb.svg +13 -0
  46. data/lib/asciidoctor/gb/html/gb.scss +556 -0
  47. data/lib/asciidoctor/gb/html/header.html +216 -0
  48. data/lib/asciidoctor/gb/html/html_gb_intro.html +9 -0
  49. data/lib/asciidoctor/gb/html/html_gb_titlepage.html +99 -0
  50. data/lib/asciidoctor/gb/html/htmlstyle.scss +269 -0
  51. data/lib/asciidoctor/gb/html/logo.png +0 -0
  52. data/lib/asciidoctor/gb/html/word_gb_intro.html +3 -0
  53. data/lib/asciidoctor/gb/html/word_gb_titlepage.html +388 -0
  54. data/lib/asciidoctor/gb/html/wordstyle.scss +2543 -0
  55. data/lib/asciidoctor/gb/isodoc.rng +1059 -0
  56. data/lib/asciidoctor/gb/isostandard.rng +1001 -0
  57. data/lib/asciidoctor/gb/section_input.rb +150 -0
  58. data/lib/asciidoctor/gb/validate.rb +115 -0
  59. data/lib/asciidoctor/gb/version.rb +5 -0
  60. data/lib/isodoc/gb/gbcleanup.rb +90 -0
  61. data/lib/isodoc/gb/gbconvert.rb +66 -0
  62. data/lib/isodoc/gb/gbhtmlconvert.rb +84 -0
  63. data/lib/isodoc/gb/gbhtmlrender.rb +208 -0
  64. data/lib/isodoc/gb/gbwordconvert.rb +136 -0
  65. data/lib/isodoc/gb/gbwordrender.rb +206 -0
  66. data/lib/isodoc/gb/html/blank.png +0 -0
  67. data/lib/isodoc/gb/html/footer.png +0 -0
  68. data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.png +0 -0
  69. data/lib/isodoc/gb/html/gb-logos/gb-issuer-default.svg +980 -0
  70. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.gif +0 -0
  71. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.png +0 -0
  72. data/lib/isodoc/gb/html/gb-logos/gb-standard-db.svg +1 -0
  73. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.gif +0 -0
  74. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.png +0 -0
  75. data/lib/isodoc/gb/html/gb-logos/gb-standard-gb.svg +1 -0
  76. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.gif +0 -0
  77. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.png +0 -0
  78. data/lib/isodoc/gb/html/gb-logos/gb-standard-gjb.svg +1 -0
  79. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.gif +0 -0
  80. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.png +0 -0
  81. data/lib/isodoc/gb/html/gb-logos/gb-standard-gm.svg +1 -0
  82. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.gif +0 -0
  83. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.png +0 -0
  84. data/lib/isodoc/gb/html/gb-logos/gb-standard-jjf.svg +1 -0
  85. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.gif +0 -0
  86. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.png +0 -0
  87. data/lib/isodoc/gb/html/gb-logos/gb-standard-zb.svg +13 -0
  88. data/lib/isodoc/gb/html/gb.scss +556 -0
  89. data/lib/isodoc/gb/html/header.html +216 -0
  90. data/lib/isodoc/gb/html/html_compliant_gb_titlepage.html +116 -0
  91. data/lib/isodoc/gb/html/html_gb_intro.html +6 -0
  92. data/lib/isodoc/gb/html/html_gb_titlepage.html +94 -0
  93. data/lib/isodoc/gb/html/htmlcompliantstyle.scss +1220 -0
  94. data/lib/isodoc/gb/html/htmlstyle.scss +1007 -0
  95. data/lib/isodoc/gb/html/logo.png +0 -0
  96. data/lib/isodoc/gb/html/scripts.html +71 -0
  97. data/lib/isodoc/gb/html/word_gb_intro.html +3 -0
  98. data/lib/isodoc/gb/html/word_gb_titlepage.html +388 -0
  99. data/lib/isodoc/gb/html/wordstyle.scss +2543 -0
  100. data/lib/isodoc/gb/i18n-en.yaml +12 -0
  101. data/lib/isodoc/gb/i18n-zh-Hans.yaml +12 -0
  102. data/lib/isodoc/gb/metadata.rb +232 -0
  103. data/lib/metanorma/gb.rb +7 -0
  104. data/lib/metanorma/gb/processor.rb +43 -0
  105. data/metanorma-gb.gemspec +48 -0
  106. metadata +380 -0
@@ -0,0 +1,208 @@
1
+ module IsoDoc
2
+ module Gb
3
+ # A {Converter} implementation that generates GB output, and a document
4
+ # schema encapsulation of the document for validation
5
+ class HtmlConvert < IsoDoc::HtmlConvert
6
+ def formula_parse(node, out)
7
+ out.div **attr_code(id: node["id"], class: "formula") do |div|
8
+ insert_tab(div, 1)
9
+ parse(node.at(ns("./stem")), out)
10
+ insert_tab(div, 1)
11
+ div << "(#{get_anchors[node['id']][:label]})"
12
+ end
13
+ formula_where(node.at(ns("./dl")), out)
14
+ end
15
+
16
+ def formula_where(dl, out)
17
+ return unless dl
18
+ out.p { |p| p << @where_lbl }
19
+ formula_dl_parse(dl, out)
20
+ end
21
+
22
+ def formula_dl_parse(node, out)
23
+ out.table **{ class: "dl" } do |v|
24
+ node.elements.each_slice(2) do |dt, dd|
25
+ v.tr do |tr|
26
+ tr.td **{ valign: "top", align: "left" } do |term|
27
+ dt_parse(dt, term)
28
+ end
29
+ tr.td(**{ valign: "top" }) { |td| td << "&mdash;" }
30
+ tr.td **{ valign: "top" } do |listitem|
31
+ dd.children.each { |n| parse(n, listitem) }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ EXAMPLE_TBL_ATTR =
39
+ { valign: "top", class: "example_label",
40
+ style: "padding:2pt 2pt 2pt 2pt" }.freeze
41
+
42
+ def example_parse(node, out)
43
+ out.table **attr_code(id: node["id"], class: "example") do |t|
44
+ t.tr do |tr|
45
+ tr.td **EXAMPLE_TBL_ATTR do |td|
46
+ td << l10n(example_label(node) + ":")
47
+ end
48
+ tr.td **{ valign: "top", class: "example" } do |td|
49
+ node.children.each { |n| parse(n, td) }
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def note_parse(node, out)
56
+ @note = true
57
+ out.table **attr_code(id: node["id"], class: "Note") do |t|
58
+ t.tr do |tr|
59
+ tr.td **EXAMPLE_TBL_ATTR do |td|
60
+ td << l10n(note_label(node) + ":")
61
+ end
62
+ tr.td **{ valign: "top", class: "Note" } do |td|
63
+ node.children.each { |n| parse(n, td) }
64
+ end
65
+ end
66
+ end
67
+ @note = false
68
+ end
69
+
70
+ def termnote_parse(node, out)
71
+ @note = true
72
+ out.table **attr_code(id: node["id"], class: "Note") do |t|
73
+ t.tr do |tr|
74
+ tr.td **EXAMPLE_TBL_ATTR do |td|
75
+ td << l10n("#{get_anchors[node['id']][:label]}:")
76
+ end
77
+ tr.td **{ valign: "top", class: "Note" } do |td|
78
+ node.children.each { |n| parse(n, td) }
79
+ end
80
+ end
81
+ end
82
+ @note = false
83
+ end
84
+
85
+ def middle(isoxml, out)
86
+ super
87
+ end_line(isoxml, out)
88
+ end
89
+
90
+ def end_line(_isoxml, out)
91
+ out.hr **{ width: "25%" }
92
+ end
93
+
94
+ def error_parse(node, out)
95
+ # catch elements not defined in ISO
96
+ case node.name
97
+ when "string" then string_parse(node, out)
98
+ else
99
+ super
100
+ end
101
+ end
102
+
103
+ def string_parse(node, out)
104
+ if node["script"] == "Hant"
105
+ out.span **{ class: "Hant" } do |s|
106
+ node.children.each { |c| parse(c, s) }
107
+ end
108
+ else
109
+ node.children.each { |c| parse(c, out) }
110
+ end
111
+ end
112
+
113
+ def deprecated_term_parse(node, out)
114
+ out.p **{ class: "DeprecatedTerms" } do |p|
115
+ p << l10n("#{@deprecated_lbl}: ")
116
+ node.children.each { |c| parse(c, p) }
117
+ end
118
+ end
119
+
120
+ def termref_render(x)
121
+ parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m)
122
+ parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 && parts[1] == ","
123
+ parts.map do |p|
124
+ /\s*\[MODIFICATION\]/.match?(p) ? l10n(", #{@modified_lbl} &mdash; ") : p
125
+ end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]"))
126
+ end
127
+
128
+ def termref_resolve(docxml)
129
+ docxml.split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4).
130
+ map do |a|
131
+ a.size < 3 ? a[0] : a[0] + termref_render(a[2])
132
+ end.join
133
+ end
134
+
135
+ def populate_template(docxml, format)
136
+ meta = @meta.get.merge(@labels)
137
+ logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format)
138
+ logofile = @meta.standard_logo(meta[:gbprefix])
139
+ @files_to_delete << logofile + ".gif" unless logofile.nil?
140
+ docxml = termref_resolve(docxml)
141
+ meta[:standard_agency_formatted] =
142
+ @common.format_agency(meta[:standard_agency], format)
143
+ meta[:standard_logo] = logo
144
+ template = Liquid::Template.parse(docxml)
145
+ template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
146
+ end
147
+
148
+ def foreword(isoxml, out)
149
+ f = isoxml.at(ns("//foreword")) || return
150
+ page_break(out)
151
+ out.div do |s|
152
+ s.h1 **{ class: "ForewordTitle" } do |h1|
153
+ h1 << "#{@foreword_lbl}&nbsp;"
154
+ # insert_tab(h1, 1)
155
+ end
156
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
157
+ end
158
+ end
159
+
160
+ def clause_name(num, title, div, header_class)
161
+ header_class = {} if header_class.nil?
162
+ div.h1 **attr_code(header_class) do |h1|
163
+ if num
164
+ h1 << "#{num}."
165
+ h1 << "&#x3000;"
166
+ end
167
+ h1 << title
168
+ end
169
+ div.parent.at(".//h1")
170
+ end
171
+
172
+ def clause_parse_title(node, div, c1, out)
173
+ if node["inline-header"] == "true"
174
+ inline_header_title(out, node, c1)
175
+ else
176
+ div.send "h#{get_anchors[node['id']][:level]}" do |h|
177
+ h << "#{get_anchors[node['id']][:label]}.&#x3000;"
178
+ c1.children.each { |c2| parse(c2, h) }
179
+ end
180
+ end
181
+ end
182
+
183
+ def annex_name(annex, name, div)
184
+ div.h1 **{ class: "Annex" } do |t|
185
+ t << "#{get_anchors[annex['id']][:label]}<br/><br/>"
186
+ t << name.text
187
+ end
188
+ end
189
+
190
+ def term_defs_boilerplate(div, source, term, preface)
191
+ unless preface
192
+ (source.empty? && term.nil?) and div << @no_terms_boilerplate or
193
+ div << term_defs_boilerplate_cont(source, term)
194
+ end
195
+ #div << @term_def_boilerplate unless preface
196
+ end
197
+
198
+ def reference_names(ref)
199
+ isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
200
+ docid = ref.at(ns("./docidentifier"))
201
+ date = ref.at(ns("./date[@type = 'published']"))
202
+ reference = format_ref(docid.text, isopub, date)
203
+ @anchors[ref["id"]] = { xref: reference }
204
+ end
205
+ end
206
+ end
207
+ end
208
+
@@ -0,0 +1,136 @@
1
+ require "isodoc"
2
+ require_relative "gbconvert"
3
+ require_relative "gbcleanup"
4
+ require "gb_agencies"
5
+ require_relative "metadata"
6
+ require_relative "gbwordrender"
7
+ require "fileutils"
8
+
9
+ module IsoDoc
10
+ module Gb
11
+ # A {Converter} implementation that generates GB output, and a document
12
+ # schema encapsulation of the document for validation
13
+ class WordConvert < IsoDoc::WordConvert
14
+ def initialize(options)
15
+ @common = IsoDoc::Gb::Common.new(options)
16
+ @libdir = File.dirname(__FILE__)
17
+ super
18
+ @lang = "zh"
19
+ @script = "Hans"
20
+ end
21
+
22
+ def default_fonts(options)
23
+ script = options[:script] || "Hans"
24
+ scope = options[:scope] || "national"
25
+ {
26
+ bodyfont: (script == "Hans" ? '"SimSun",serif' : '"Cambria",serif'),
27
+ headerfont: (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif'),
28
+ monospacefont: '"Courier New",monospace',
29
+ titlefont: (scope == "national" ? (script != "Hans" ? '"Cambria",serif' : '"SimSun",serif' ) :
30
+ (script == "Hans" ? '"SimHei",sans-serif' : '"Calibri",sans-serif' ))
31
+ }
32
+ end
33
+
34
+ def default_file_locations(options)
35
+ {
36
+ wordstylesheet: html_doc_path("wordstyle.scss"),
37
+ standardstylesheet: html_doc_path("gb.scss"),
38
+ header: html_doc_path("header.html"),
39
+ wordcoverpage: html_doc_path("word_gb_titlepage.html"),
40
+ wordintropage: html_doc_path("word_gb_intro.html"),
41
+ ulstyle: "l7",
42
+ olstyle: "l10",
43
+ }
44
+ end
45
+
46
+ def extract_fonts(options)
47
+ b = options[:bodyfont] || "Arial"
48
+ h = options[:headerfont] || "Arial"
49
+ m = options[:monospacefont] || "Courier"
50
+ t = options[:titlefont] || "Arial"
51
+ "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n"
52
+ end
53
+
54
+ def metadata_init(lang, script, labels)
55
+ unless ["en", "zh"].include? lang
56
+ lang = "zh"
57
+ script = "Hans"
58
+ end
59
+ @meta = Metadata.new(lang, script, labels)
60
+ @common = IsoDoc::Gb::Common.new(meta: @meta)
61
+ end
62
+
63
+ def cleanup(docxml)
64
+ @cleanup = Cleanup.new(@script, @deprecated_lbl)
65
+ super
66
+ @cleanup.cleanup(docxml)
67
+ docxml
68
+ end
69
+
70
+ def example_cleanup(docxml)
71
+ super
72
+ @cleanup.example_cleanup(docxml)
73
+ end
74
+
75
+ def i18n_init(lang, script)
76
+ super
77
+ y = if lang == "en"
78
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
79
+ elsif lang == "zh" && script == "Hans"
80
+ YAML.load_file(File.join(File.dirname(__FILE__),
81
+ "i18n-zh-Hans.yaml"))
82
+ else
83
+ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml"))
84
+ end
85
+ @labels = @labels.merge(y)
86
+ end
87
+
88
+ ENDLINE = <<~END.freeze
89
+ <v:line id="_x0000_s1026"
90
+ alt="" style='position:absolute;left:0;text-align:left;z-index:251662848;
91
+ mso-wrap-edited:f;mso-width-percent:0;mso-height-percent:0;
92
+ mso-width-percent:0;mso-height-percent:0'
93
+ from="6.375cm,20.95pt" to="10.625cm,20.95pt"
94
+ strokeweight="1.5pt"/>
95
+ END
96
+
97
+ def end_line(_isoxml, out)
98
+ out.parent.add_child(ENDLINE)
99
+ end
100
+
101
+ def generate_header(filename, dir)
102
+ return unless @header
103
+ template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
104
+ meta = @meta.get
105
+ meta[:filename] = filename
106
+ params = meta.map { |k, v| [k.to_s, v] }.to_h
107
+ File.open("header.html", "w") { |f| f.write(template.render(params)) }
108
+ system "cp #{@common.fileloc(File.join('html', 'blank.png'))} blank.png"
109
+ FileUtils.cp @common.fileloc(File.join('html', 'blank.png')), "blank.png"
110
+ @files_to_delete << "blank.png"
111
+ @files_to_delete << "header.html"
112
+ "header.html"
113
+ end
114
+
115
+ def header_strip(h)
116
+ h = h.to_s.gsub(%r{<br/>}, " ").sub(/<\/?h[12][^>]*>/, "")
117
+ h1 = to_xhtml_fragment(h.dup)
118
+ h1.traverse do |x|
119
+ x.replace(" ") if x.name == "span" &&
120
+ /mso-tab-count/.match?(x["style"])
121
+ x.remove if x.name == "span" && x["class"] == "MsoCommentReference"
122
+ x.remove if x.name == "a" && x["epub:type"] == "footnote"
123
+ x.replace(x.children) if x.name == "a"
124
+ end
125
+ from_xhtml(h1)
126
+ end
127
+
128
+ def word_cleanup(docxml)
129
+ word_preface(docxml)
130
+ word_annex_cleanup(docxml)
131
+ @cleanup.title_cleanup(docxml.at('//div[@class="WordSection2"]'))
132
+ docxml
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,206 @@
1
+ module IsoDoc
2
+ module Gb
3
+ # A {Converter} implementation that generates GB output, and a document
4
+ # schema encapsulation of the document for validation
5
+ class WordConvert < IsoDoc::WordConvert
6
+ def formula_parse(node, out)
7
+ out.div **attr_code(id: node["id"], class: "formula") do |div|
8
+ insert_tab(div, 1)
9
+ parse(node.at(ns("./stem")), out)
10
+ insert_tab(div, 1)
11
+ div << "(#{get_anchors[node['id']][:label]})"
12
+ end
13
+ formula_where(node.at(ns("./dl")), out)
14
+ end
15
+
16
+ def formula_where(dl, out)
17
+ return unless dl
18
+ out.p { |p| p << @where_lbl }
19
+ formula_dl_parse(dl, out)
20
+ end
21
+
22
+ def formula_dl_parse(node, out)
23
+ out.table **{ class: "dl" } do |v|
24
+ node.elements.each_slice(2) do |dt, dd|
25
+ v.tr do |tr|
26
+ tr.td **{ valign: "top", align: "left" } do |term|
27
+ dt_parse(dt, term)
28
+ end
29
+ tr.td(**{ valign: "top" }) { |td| td << "&mdash;" }
30
+ tr.td **{ valign: "top" } do |listitem|
31
+ dd.children.each { |n| parse(n, listitem) }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ EXAMPLE_TBL_ATTR =
39
+ { valign: "top", class: "example_label",
40
+ style: "padding:2pt 2pt 2pt 2pt" }.freeze
41
+
42
+ def example_parse(node, out)
43
+ out.table **attr_code(id: node["id"], class: "example") do |t|
44
+ t.tr do |tr|
45
+ tr.td **EXAMPLE_TBL_ATTR do |td|
46
+ td << l10n(example_label(node) + ":")
47
+ end
48
+ tr.td **{ valign: "top", class: "example" } do |td|
49
+ node.children.each { |n| parse(n, td) }
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def note_parse(node, out)
56
+ @note = true
57
+ out.table **attr_code(id: node["id"], class: "Note") do |t|
58
+ t.tr do |tr|
59
+ tr.td **EXAMPLE_TBL_ATTR do |td|
60
+ td << l10n(note_label(node) + ":")
61
+ end
62
+ tr.td **{ valign: "top", class: "Note" } do |td|
63
+ node.children.each { |n| parse(n, td) }
64
+ end
65
+ end
66
+ end
67
+ @note = false
68
+ end
69
+
70
+ def termnote_parse(node, out)
71
+ @note = true
72
+ out.table **attr_code(id: node["id"], class: "Note") do |t|
73
+ t.tr do |tr|
74
+ tr.td **EXAMPLE_TBL_ATTR do |td|
75
+ td << l10n("#{get_anchors[node['id']][:label]}:")
76
+ end
77
+ tr.td **{ valign: "top", class: "Note" } do |td|
78
+ node.children.each { |n| parse(n, td) }
79
+ end
80
+ end
81
+ end
82
+ @note = false
83
+ end
84
+
85
+ def middle(isoxml, out)
86
+ super
87
+ end_line(isoxml, out)
88
+ end
89
+
90
+ def end_line(_isoxml, out)
91
+ out.hr **{ width: "25%" }
92
+ end
93
+
94
+ def error_parse(node, out)
95
+ # catch elements not defined in ISO
96
+ case node.name
97
+ when "string" then string_parse(node, out)
98
+ else
99
+ super
100
+ end
101
+ end
102
+
103
+ def string_parse(node, out)
104
+ if node["script"] == "Hant"
105
+ out.span **{ class: "Hant" } do |s|
106
+ node.children.each { |c| parse(c, s) }
107
+ end
108
+ else
109
+ node.children.each { |c| parse(c, out) }
110
+ end
111
+ end
112
+
113
+ def deprecated_term_parse(node, out)
114
+ out.p **{ class: "DeprecatedTerms" } do |p|
115
+ p << l10n("#{@deprecated_lbl}: ")
116
+ node.children.each { |c| parse(c, p) }
117
+ end
118
+ end
119
+
120
+ def termref_render(x)
121
+ parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m)
122
+ parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 && parts[1] == ","
123
+ parts.map do |p|
124
+ /\s*\[MODIFICATION\]/.match?(p) ? l10n(", #{@modified_lbl} &mdash; ") : p
125
+ end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]"))
126
+ end
127
+
128
+ def termref_resolve(docxml)
129
+ docxml.split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4).
130
+ map do |a|
131
+ a.size < 3 ? a[0] : a[0] + termref_render(a[2])
132
+ end.join
133
+ end
134
+
135
+ def populate_template(docxml, format)
136
+ meta = @meta.get.merge(@labels)
137
+ logo = @common.format_logo(meta[:gbprefix], meta[:gbscope], format)
138
+ logofile = @meta.standard_logo(meta[:gbprefix])
139
+ @files_to_delete << logofile + ".gif" unless logofile.nil?
140
+ docxml = termref_resolve(docxml)
141
+ meta[:standard_agency_formatted] =
142
+ @common.format_agency(meta[:standard_agency], format)
143
+ meta[:standard_logo] = logo
144
+ template = Liquid::Template.parse(docxml)
145
+ template.render(meta.map { |k, v| [k.to_s, v] }.to_h)
146
+ end
147
+
148
+ def foreword(isoxml, out)
149
+ f = isoxml.at(ns("//foreword")) || return
150
+ page_break(out)
151
+ out.div do |s|
152
+ s.h1 **{ class: "ForewordTitle" } do |h1|
153
+ h1 << "#{@foreword_lbl}&nbsp;"
154
+ # insert_tab(h1, 1)
155
+ end
156
+ f.elements.each { |e| parse(e, s) unless e.name == "title" }
157
+ end
158
+ end
159
+
160
+ def clause_name(num, title, div, header_class)
161
+ header_class = {} if header_class.nil?
162
+ div.h1 **attr_code(header_class) do |h1|
163
+ if num
164
+ h1 << "#{num}."
165
+ h1 << "&#x3000;"
166
+ end
167
+ h1 << title
168
+ end
169
+ div.parent.at(".//h1")
170
+ end
171
+
172
+ def clause_parse_title(node, div, c1, out)
173
+ if node["inline-header"] == "true"
174
+ inline_header_title(out, node, c1)
175
+ else
176
+ div.send "h#{get_anchors[node['id']][:level]}" do |h|
177
+ h << "#{get_anchors[node['id']][:label]}.&#x3000;"
178
+ c1.children.each { |c2| parse(c2, h) }
179
+ end
180
+ end
181
+ end
182
+
183
+ def annex_name(annex, name, div)
184
+ div.h1 **{ class: "Annex" } do |t|
185
+ t << "#{get_anchors[annex['id']][:label]}<br/><br/>"
186
+ t << name.text
187
+ end
188
+ end
189
+
190
+ def term_defs_boilerplate(div, source, term, preface)
191
+ (source.empty? && term.nil?) and div << @no_terms_boilerplate or
192
+ div << term_defs_boilerplate_cont(source, term)
193
+ #div << @term_def_boilerplate unless preface
194
+ end
195
+
196
+ def reference_names(ref)
197
+ isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
198
+ docid = ref.at(ns("./docidentifier"))
199
+ date = ref.at(ns("./date[@type = 'published']"))
200
+ reference = format_ref(docid.text, isopub, date)
201
+ @anchors[ref["id"]] = { xref: reference }
202
+ end
203
+ end
204
+ end
205
+ end
206
+