metanorma-bipm 2.0.8 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,101 @@
1
+ module IsoDoc
2
+ module BIPM
3
+ class PresentationXMLConvert < IsoDoc::Generic::PresentationXMLConvert
4
+ def doccontrol(doc)
5
+ return unless doc.at(ns("//bibdata/relation[@type = 'supersedes']"))
6
+
7
+ clause = <<~DOCCONTROL
8
+ <doccontrol>
9
+ <title>Document Control</title>
10
+ <table unnumbered="true"><tbody>
11
+ <tr><th>Authors:</th><td/><td>#{list_authors(doc)}</td></tr>
12
+ #{doccontrol_row1(doc)} #{doccontrol_row2(doc)} #{list_drafts(doc)}
13
+ </tbody></table></doccontrol>
14
+ DOCCONTROL
15
+ doc.root << clause
16
+ end
17
+
18
+ def doccontrol_row1(doc)
19
+ return "" if list_draft(doc,
20
+ 1) == ["", ""] && list_cochairs(doc).empty?
21
+
22
+ <<~ROW
23
+ <tr>#{list_draft(doc, 1)&.map { |x| "<td>#{x}</td>" }&.join}
24
+ <td>#{list_cochairs(doc)}</td></tr>
25
+ ROW
26
+ end
27
+
28
+ def doccontrol_row2(docxml)
29
+ list_draft(docxml, 2) == ["", ""] && list_chairs(docxml).empty? and
30
+ return ""
31
+
32
+ <<~ROW
33
+ <tr>#{list_draft(docxml, 2)&.map { |x| "<td>#{x}</td>" }&.join}
34
+ <td>#{list_chairs(docxml)}</td></tr>
35
+ ROW
36
+ end
37
+
38
+ def list_drafts(xml)
39
+ ret = ""
40
+ i = 3
41
+ while list_draft(xml, i) != ["", ""]
42
+ ret += "<tr>#{list_draft(xml, i).map do |x|
43
+ "<td>#{x}</td>"
44
+ end.join} "\
45
+ "<td/></tr>"
46
+ i += 1
47
+ end
48
+ ret
49
+ end
50
+
51
+ def list_draft(xml, idx)
52
+ d = xml.at(ns("//bibdata/relation[@type = 'supersedes'][#{idx}]"\
53
+ "/bibitem")) or return ["", ""]
54
+
55
+ draft = d&.at(ns("./version/draft"))&.text and draft = "Draft #{draft}"
56
+ edn = d&.at(ns("./edition"))&.text and edn = "Version #{edn}"
57
+ [[draft, edn].join(" "), d&.at(ns("./date"))&.text]
58
+ end
59
+
60
+ def list_authors(xml)
61
+ ret = list_people(
62
+ xml, "//bibdata/contributor[xmlns:role/@type = 'author']/person"
63
+ )
64
+ @i18n.boolean_conj(ret, "and")
65
+ end
66
+
67
+ COCHAIR = "xmlns:role[contains(text(),'co-chair')]".freeze
68
+ CHAIR = "[xmlns:role[contains(text(),'chair')]"\
69
+ "[not(contains(text(),'co-chair'))]]".freeze
70
+
71
+ def list_cochairs(xml)
72
+ ret = list_people(xml, "//bibdata/contributor[#{COCHAIR}]/person")
73
+ ret.empty? and return ""
74
+ role = xml&.at(ns("//bibdata/contributor[#{COCHAIR}]/role"))&.text
75
+ label = ret.size > 1 && role ? "#{role}s" : role
76
+ "#{label}: #{@i18n.boolean_conj(ret, 'and')}"
77
+ end
78
+
79
+ def list_chairs(xml)
80
+ ret = list_people(xml, "//bibdata/contributor#{CHAIR}/person")
81
+ ret.empty? and return ""
82
+ role = xml&.at(ns("//bibdata/contributor#{CHAIR}/role"))&.text
83
+ label = ret.size > 1 && role ? "#{role}s" : role
84
+ "#{label}: #{@i18n.boolean_conj(ret, 'and')}"
85
+ end
86
+
87
+ def list_people(xml, xpath)
88
+ ret = []
89
+ xml.xpath(ns(xpath)).each do |p|
90
+ name = p&.at(ns("./name/completename"))&.text
91
+ aff = p&.at(ns("./affiliation/organization/abbreviation"))&.text ||
92
+ p&.at(ns("./affiliation/organization/name"))&.text
93
+ c = name || ""
94
+ aff and c += " (#{aff})"
95
+ ret << c
96
+ end
97
+ ret
98
+ end
99
+ end
100
+ end
101
+ end
@@ -77,6 +77,7 @@
77
77
  </div>
78
78
  {% endif %}
79
79
 
80
+ <div class="coverpage-warning" id="coverpage-note-destination"/>
80
81
 
81
82
  </div>
82
83
 
@@ -16,7 +16,7 @@ module IsoDoc
16
16
  end
17
17
 
18
18
  def i18n_init(lang, script, i18nyaml = nil)
19
- @i18n = I18n.new(lang, script, i18nyaml || @i18nyaml)
19
+ @i18n = I18n.new(lang, script, i18nyaml: i18nyaml || @i18nyaml)
20
20
  end
21
21
  end
22
22
  end