metanorma-mpfd 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ module IsoDoc
8
8
  class Metadata < IsoDoc::Metadata
9
9
  def initialize(lang, script, labels)
10
10
  super
11
- # set(:status, "")
12
11
  end
13
12
 
14
13
  def title(isoxml, _out)
@@ -31,9 +30,9 @@ module IsoDoc
31
30
  end
32
31
 
33
32
  def doctype(isoxml, _out)
34
- b = isoxml.at(ns("//bibdata")) || return
35
- return unless b["type"]
36
- t = b["type"].split(/[- ]/).
33
+ b = isoxml&.at(ns("//bibdata/ext/doctype"))&.text || return
34
+ return unless b
35
+ t = b.split(/[- ]/).
37
36
  map{ |w| w.capitalize unless w == "MPF" }.join(" ")
38
37
  set(:doctype, t)
39
38
  end
@@ -1,6 +1,5 @@
1
+ require_relative "base_convert"
1
2
  require "isodoc"
2
- require_relative "metadata"
3
- require "fileutils"
4
3
 
5
4
  module IsoDoc
6
5
  module Mpfd
@@ -12,13 +11,7 @@ module IsoDoc
12
11
  super
13
12
  end
14
13
 
15
- def convert1(docxml, filename, dir)
16
- FileUtils.cp html_doc_path("logo.jpg"), File.join(@localdir, "logo.jpg")
17
- FileUtils.cp html_doc_path('mpfa-logo-no-text@4x.png'), File.join(@localdir, "mpfa-logo-no-text@4x.png")
18
- @files_to_delete << File.join(@localdir, "logo.jpg")
19
- @files_to_delete << File.join(@localdir, "mpfa-logo-no-text@4x.png")
20
- super
21
- end
14
+ include BaseConvert
22
15
 
23
16
  def default_fonts(options)
24
17
  {
@@ -37,10 +30,6 @@ module IsoDoc
37
30
  }
38
31
  end
39
32
 
40
- def metadata_init(lang, script, labels)
41
- @meta = Metadata.new(lang, script, labels)
42
- end
43
-
44
33
  def googlefonts()
45
34
  <<~HEAD.freeze
46
35
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
@@ -62,75 +51,6 @@ module IsoDoc
62
51
  docxml
63
52
  end
64
53
 
65
- def annex_name(annex, name, div)
66
- div.h1 **{ class: "Annex" } do |t|
67
- t << "#{get_anchors[annex['id']][:label]} "
68
- t.b do |b|
69
- name&.children&.each { |c2| parse(c2, b) }
70
- end
71
- end
72
- end
73
-
74
- def fileloc(loc)
75
- File.join(File.dirname(__FILE__), loc)
76
- end
77
-
78
- def i18n_init(lang, script)
79
- super
80
- y = if lang == "en"
81
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
82
- elsif lang == "zh" && script == "Hans"
83
- YAML.load_file(File.join(File.dirname(__FILE__),
84
- "i18n-zh-Hans.yaml"))
85
- else
86
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
87
- end
88
- @labels = @labels.merge(y)
89
- @annex_lbl = y["annex"]
90
- @clause_lbl = y["clause"]
91
- end
92
-
93
- def terms_defs_title(f)
94
- return f&.at(ns("./title"))&.content
95
- end
96
-
97
- TERM_CLAUSE = "//preface/terms | "\
98
- "//preface/clause[descendant::terms]".freeze
99
-
100
- SECTIONS_XPATH =
101
- "//foreword | //introduction | //preface/terms | //preface/clause | //annex | "\
102
- "//sections/clause | //bibliography/references | "\
103
- "//bibliography/clause".freeze
104
-
105
- def terms_defs(isoxml, out, num)
106
- f = isoxml.at(ns(TERM_CLAUSE)) or return num
107
- out.div **attr_code(id: f["id"]) do |div|
108
- clause_name(nil, terms_defs_title(f), div, nil)
109
- f.elements.each do |e|
110
- parse(e, div) unless %w{title source}.include? e.name
111
- end
112
- end
113
- num
114
- end
115
-
116
- FRONT_CLAUSE = "//*[parent::preface]".freeze
117
- #FRONT_CLAUSE = "//clause[parent::preface] | //terms[parent::preface]".freeze
118
-
119
- def preface(isoxml, out)
120
- isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
121
- if c.name == "terms" || c.at(ns(".//terms")) then terms_defs isoxml, out, 0
122
- else
123
- out.div **attr_code(id: c["id"]) do |s|
124
- clause_name(get_anchors[c['id']][:label],
125
- c&.at(ns("./title"))&.content, s, nil)
126
- c.elements.reject { |c1| c1.name == "title" }.each do |c1|
127
- parse(c1, s)
128
- end
129
- end
130
- end
131
- end
132
- end
133
-
134
54
  def make_body3(body, docxml)
135
55
  body.div **{ class: "main-section" } do |div3|
136
56
  preface docxml, div3
@@ -139,142 +59,6 @@ module IsoDoc
139
59
  comments div3
140
60
  end
141
61
  end
142
-
143
- def middle(isoxml, out)
144
- middle_title(out)
145
- clause isoxml, out
146
- annex isoxml, out
147
- bibliography isoxml, out
148
- end
149
-
150
- def termdef_parse(node, out)
151
- set_termdomain("")
152
- node.children.each { |n| parse(n, out) }
153
- end
154
-
155
- def initial_anchor_names(d)
156
- #preface_names(d.at(ns("//foreword")))
157
- #preface_names(d.at(ns("//introduction")))
158
- #preface_names(d.at(ns("//preface/terms | "\
159
- #"//preface/clause[descendant::terms]")))
160
- d.xpath(ns(FRONT_CLAUSE)).each do |c|
161
- preface_names(c)
162
- sequential_asset_names(c)
163
- end
164
- middle_section_asset_names(d)
165
- clause_names(d, 0)
166
- termnote_anchor_names(d)
167
- termexample_anchor_names(d)
168
- end
169
-
170
- def annex_name_lbl(clause, num)
171
- l10n("<b>#{@annex_lbl} #{num}</b>")
172
- end
173
-
174
- def clause_names(docxml, sect_num)
175
- q = "//clause[parent::sections]"
176
- @topnum = nil
177
- lvl = 0
178
- docxml.xpath(ns(q)).each do |c|
179
- container_names(c, 0)
180
- sect_num, lvl = sect_names(c, nil, sect_num, 0, lvl)
181
- end
182
- end
183
-
184
- def container_names(clause, lvl)
185
- if clause["container"]
186
- @anchors[clause["id"]] =
187
- { label: nil, xref: clause.at(ns("./title"))&.text, level: lvl+1 }
188
- end
189
- clause.xpath(ns("./clause | ./term | ./terms | "\
190
- "./definitions")).each do |c|
191
- container_names(c, clause["container"] ? lvl+1 : lvl)
192
- end
193
- end
194
-
195
- def sect_names(clause, num, i, lvl, prev_lvl)
196
- return i if clause.nil?
197
- curr = i
198
- if !clause["container"]
199
- retlvl = lvl
200
- i+=1
201
- curr = i
202
- name = num.nil? ? i.to_s : "#{num}.#{i}"
203
- @anchors[clause["id"]] = { label: name, xref: l10n("#{@clause_lbl} #{name}"), level: lvl+1 }
204
- end
205
- prev = lvl
206
- j = 0
207
- clause.xpath(ns("./clause | ./term | ./terms | "\
208
- "./definitions")).each do |c|
209
- if clause["container"]
210
- i, lvl = sect_names(c, num, i, lvl, lvl)
211
- else
212
- j, prev = sect_names(c, name, j, lvl+1, prev)
213
- end
214
- end
215
- i = j if j >0
216
- i = curr if lvl < prev
217
- [i, prev]
218
- end
219
-
220
- def annex_naming(c, num, lvl, i)
221
- if c["guidance"] then annex_names1(c, "#{num}E", lvl + 1)
222
- else
223
- i+= 1 unless c["container"]
224
- annex_names1(c, "#{num}.#{i}", lvl + 1)
225
- end
226
- i
227
- end
228
-
229
- def annex_names(clause, num)
230
- @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
231
- xref: "#{@annex_lbl} #{num}", level: 1 }
232
- i = 0
233
- clause.xpath(ns("./clause")).each do |c|
234
- container_names(c, 0)
235
- i = annex_naming(c, num, 1, i)
236
- end
237
- hierarchical_asset_names(clause, num)
238
- end
239
-
240
- def annex_names1(clause, num, level)
241
- clause["container"] or @anchors[clause["id"]] =
242
- { label: num, xref: "#{@annex_lbl} #{num}", level: level }
243
- i = 0
244
- clause.xpath(ns("./clause")).each do |c|
245
- i = annex_naming(c, num, level, i)
246
- end
247
- end
248
-
249
- def clause(isoxml, out)
250
- isoxml.xpath(ns(MIDDLE_CLAUSE)).each do |c|
251
- out.div **attr_code(id: c["id"]) do |s|
252
- clause_name(get_anchors[c['id']][:label],
253
- c&.at(ns("./title"))&.content, s, class: c["container"] ? "containerhdr" : nil )
254
- c.elements.reject { |c1| c1.name == "title" }.each do |c1|
255
- parse(c1, s)
256
- end
257
- end
258
- end
259
- end
260
-
261
- def clause_parse_title(node, div, c1, out)
262
- if node["inline-header"] == "true"
263
- inline_header_title(out, node, c1)
264
- else
265
- attrs = { class: node["container"] ? "containerhdr" : nil }
266
- div.send "h#{get_anchors[node['id']][:level]}", **attr_code(attrs) do |h|
267
- lbl = get_anchors[node['id']][:label]
268
- h << "#{lbl}. " if lbl && !@suppressheadingnumbers
269
- c1&.children&.each { |c2| parse(c2, h) }
270
- end
271
- end
272
- end
273
-
274
- def ol_depth(node)
275
- ol_style(node["type"])
276
- end
277
-
278
62
  end
279
63
  end
280
64
  end
@@ -1,6 +1,5 @@
1
+ require_relative "base_convert"
1
2
  require "isodoc"
2
- require_relative "metadata"
3
- require "fileutils"
4
3
 
5
4
  module IsoDoc
6
5
  module Mpfd
@@ -12,13 +11,7 @@ module IsoDoc
12
11
  super
13
12
  end
14
13
 
15
- def convert1(docxml, filename, dir)
16
- FileUtils.cp html_doc_path("logo.jpg"), File.join(@localdir, "logo.jpg")
17
- FileUtils.cp html_doc_path('mpfa-logo-no-text@4x.png'), File.join(@localdir, "mpfa-logo-no-text@4x.png")
18
- @files_to_delete << File.join(@localdir, "logo.jpg")
19
- @files_to_delete << File.join(@localdir, "mpfa-logo-no-text@4x.png")
20
- super
21
- end
14
+ include BaseConvert
22
15
 
23
16
  def default_fonts(options)
24
17
  {
@@ -44,10 +37,6 @@ module IsoDoc
44
37
  }
45
38
  end
46
39
 
47
- def metadata_init(lang, script, labels)
48
- @meta = Metadata.new(lang, script, labels)
49
- end
50
-
51
40
  def make_body(xml, docxml)
52
41
  body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
53
42
  xml.body **body_attr do |body|
@@ -57,70 +46,6 @@ module IsoDoc
57
46
  end
58
47
  end
59
48
 
60
- def annex_name(annex, name, div)
61
- div.h1 **{ class: "Annex" } do |t|
62
- t << "#{get_anchors[annex['id']][:label]} "
63
- t.b do |b|
64
- name&.children&.each { |c2| parse(c2, b) }
65
- end
66
- end
67
- end
68
-
69
- def fileloc(loc)
70
- File.join(File.dirname(__FILE__), loc)
71
- end
72
-
73
- def i18n_init(lang, script)
74
- super
75
- y = if lang == "en"
76
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
77
- elsif lang == "zh" && script == "Hans"
78
- YAML.load_file(File.join(File.dirname(__FILE__),
79
- "i18n-zh-Hans.yaml"))
80
- else
81
- YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
82
- end
83
- @labels = @labels.merge(y)
84
- @annex_lbl = y["annex"]
85
- @clause_lbl = y["clause"]
86
- end
87
-
88
- def terms_defs_title(f)
89
- return f&.at(ns("./title"))&.content
90
- end
91
-
92
- TERM_CLAUSE = "//preface/terms | "\
93
- "//preface/clause[descendant::terms]".freeze
94
-
95
- SECTIONS_XPATH =
96
- "//foreword | //introduction | //preface/terms | //preface/clause | //annex | "\
97
- "//sections/clause | //bibliography/references | "\
98
- "//bibliography/clause".freeze
99
-
100
- def terms_defs(isoxml, out, num)
101
- f = isoxml.at(ns(TERM_CLAUSE)) or return num
102
- out.div **attr_code(id: f["id"]) do |div|
103
- clause_name(nil, terms_defs_title(f), div, nil)
104
- f.elements.each do |e|
105
- parse(e, div) unless %w{title source}.include? e.name
106
- end
107
- end
108
- num
109
- end
110
-
111
- FRONT_CLAUSE = "//*[parent::preface]".freeze
112
-
113
- def initial_anchor_names(d)
114
- d.xpath(ns(FRONT_CLAUSE)).each do |c|
115
- preface_names(c)
116
- sequential_asset_names(c)
117
- end
118
- middle_section_asset_names(d)
119
- clause_names(d, 0)
120
- termnote_anchor_names(d)
121
- termexample_anchor_names(d)
122
- end
123
-
124
49
  def make_body2(body, docxml)
125
50
  body.div **{ class: "WordSection2" } do |div2|
126
51
  info docxml, div2
@@ -132,127 +57,6 @@ module IsoDoc
132
57
  end
133
58
  section_break(body)
134
59
  end
135
-
136
- def middle(isoxml, out)
137
- middle_title(out)
138
- clause isoxml, out
139
- annex isoxml, out
140
- bibliography isoxml, out
141
- end
142
-
143
- def termdef_parse(node, out)
144
- set_termdomain("")
145
- node.children.each { |n| parse(n, out) }
146
- end
147
-
148
- def annex_name_lbl(clause, num)
149
- l10n("<b>#{@annex_lbl} #{num}</b>")
150
- end
151
-
152
- def clause_names(docxml, sect_num)
153
- q = "//clause[parent::sections]"
154
- @topnum = nil
155
- lvl = 0
156
- docxml.xpath(ns(q)).each do |c|
157
- container_names(c, 0)
158
- sect_num, lvl = sect_names(c, nil, sect_num, 0, lvl)
159
- end
160
- end
161
-
162
- def container_names(clause, lvl)
163
- if clause["container"]
164
- @anchors[clause["id"]] =
165
- { label: nil, xref: clause.at(ns("./title"))&.text, level: lvl+1 }
166
- end
167
- clause.xpath(ns("./clause | ./term | ./terms | "\
168
- "./definitions")).each do |c|
169
- container_names(c, clause["container"] ? lvl+1 : lvl)
170
- end
171
- end
172
-
173
- def sect_names(clause, num, i, lvl, prev_lvl)
174
- return i if clause.nil?
175
- curr = i
176
- if !clause["container"]
177
- retlvl = lvl
178
- i+=1
179
- curr = i
180
- name = num.nil? ? i.to_s : "#{num}.#{i}"
181
- @anchors[clause["id"]] = { label: name, xref: l10n("#{@clause_lbl} #{name}"), level: lvl+1 }
182
- end
183
- prev = lvl
184
- j = 0
185
- clause.xpath(ns("./clause | ./term | ./terms | "\
186
- "./definitions")).each do |c|
187
- if clause["container"]
188
- i, lvl = sect_names(c, num, i, lvl, lvl)
189
- else
190
- j, prev = sect_names(c, name, j, lvl+1, prev)
191
- end
192
- end
193
- i = j if j >0
194
- i = curr if lvl < prev
195
- [i, prev]
196
- end
197
-
198
- def annex_naming(c, num, lvl, i)
199
- if c["guidance"] then annex_names1(c, "#{num}E", lvl + 1)
200
- else
201
- i+= 1 unless c["container"]
202
- annex_names1(c, "#{num}.#{i}", lvl + 1)
203
- end
204
- i
205
- end
206
-
207
- def annex_names(clause, num)
208
- @anchors[clause["id"]] = { label: annex_name_lbl(clause, num),
209
- xref: "#{@annex_lbl} #{num}", level: 1 }
210
- i = 0
211
- clause.xpath(ns("./clause")).each do |c|
212
- container_names(c, 0)
213
- i = annex_naming(c, num, 1, i)
214
- end
215
- hierarchical_asset_names(clause, num)
216
- end
217
-
218
- def annex_names1(clause, num, level)
219
- clause["container"] or @anchors[clause["id"]] =
220
- { label: num, xref: "#{@annex_lbl} #{num}", level: level }
221
- i = 0
222
- clause.xpath(ns("./clause")).each do |c|
223
- i = annex_naming(c, num, level, i)
224
- end
225
- end
226
-
227
- def clause(isoxml, out)
228
- isoxml.xpath(ns(MIDDLE_CLAUSE)).each do |c|
229
- out.div **attr_code(id: c["id"]) do |s|
230
- clause_name(get_anchors[c['id']][:label],
231
- c&.at(ns("./title"))&.content, s, class: c["container"] ? "containerhdr" : nil )
232
- c.elements.reject { |c1| c1.name == "title" }.each do |c1|
233
- parse(c1, s)
234
- end
235
- end
236
- end
237
- end
238
-
239
- def clause_parse_title(node, div, c1, out)
240
- if node["inline-header"] == "true"
241
- inline_header_title(out, node, c1)
242
- else
243
- attrs = { class: node["container"] ? "containerhdr" : nil }
244
- div.send "h#{get_anchors[node['id']][:level]}", **attr_code(attrs) do |h|
245
- lbl = get_anchors[node['id']][:label]
246
- h << "#{lbl}. " if lbl && !@suppressheadingnumbers
247
- c1&.children&.each { |c2| parse(c2, h) }
248
- end
249
- end
250
- end
251
-
252
- def ol_depth(node)
253
- ol_style(node["type"])
254
- end
255
-
256
60
  end
257
61
  end
258
62
  end