isodoc 0.4.5 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,13 @@
1
1
  module IsoDoc
2
2
  class Convert
3
+ def docid_l10n(x)
4
+ x.gsub(/All Parts/, @all_parts_lbl)
5
+ end
6
+
3
7
  def iso_bibitem_ref_code(b)
4
- isocode = b.at(ns("./docidentifier"))
8
+ isocode = b.at(ns("./docidentifier")).text
5
9
  isodate = b.at(ns("./date[@type = 'published']"))
6
- reference = "ISO #{isocode.text}"
10
+ reference = docid_l10n(isocode)
7
11
  reference += ": #{isodate.text}" if isodate
8
12
  reference
9
13
  end
@@ -16,16 +20,19 @@ module IsoDoc
16
20
  footnote_parse(date_note, ref)
17
21
  end
18
22
 
23
+ def iso_bibitem_entry_attrs(b, biblio)
24
+ { id: b["id"], class: biblio ? "Biblio" : nil }
25
+ end
26
+
19
27
  def iso_bibitem_entry(list, b, ordinal, biblio)
20
- attrs = { id: b["id"], class: biblio ? "Biblio" : nil }
21
- list.p **attr_code(attrs) do |ref|
28
+ list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
22
29
  if biblio
23
30
  ref << "[#{ordinal}]"
24
31
  insert_tab(ref, 1)
25
32
  end
26
33
  ref << iso_bibitem_ref_code(b)
27
34
  date_note_process(b, ref)
28
- ref << ", " if biblio
35
+ ref << ", "
29
36
  ref.i { |i| i << " #{b.at(ns('./title')).text}" }
30
37
  end
31
38
  end
@@ -41,7 +48,7 @@ module IsoDoc
41
48
  end
42
49
  end
43
50
 
44
- def ref_entry(list, b, ordinal, bibliography)
51
+ def ref_entry(list, b, ordinal, _bibliography)
45
52
  ref = b.at(ns("./ref"))
46
53
  para = b.at(ns("./p"))
47
54
  list.p **attr_code("id": ref["id"], class: "Biblio") do |r|
@@ -50,17 +57,22 @@ module IsoDoc
50
57
  end
51
58
  end
52
59
 
60
+ # TODO generate formatted ref if not present
53
61
  def noniso_bibitem(list, b, ordinal, bibliography)
54
- ref = b.at(ns("./docidentifier"))
55
- para = b.at(ns("./formattedref"))
56
62
  list.p **attr_code("id": b["id"], class: "Biblio") do |r|
57
- ref_entry_code(r, ordinal, ref.text.gsub(/[\[\]]/, ""))
58
- para.children.each { |n| parse(n, r) }
63
+ if bibliography
64
+ id = docid_l10n(b.at(ns("./docidentifier")).text.gsub(/[\[\]]/, ""))
65
+ ref_entry_code(r, ordinal, id)
66
+ else
67
+ r << "#{iso_bibitem_ref_code(b)}, "
68
+ end
69
+ b.at(ns("./formattedref")).children.each { |n| parse(n, r) }
59
70
  end
60
71
  end
61
72
 
62
73
  ISO_PUBLISHER_XPATH =
63
- "./contributor[xmlns:role/@type = 'publisher']/organization[name = 'ISO']"
74
+ "./contributor[xmlns:role/@type = 'publisher']/"\
75
+ "organization[name = 'ISO' or xmlns:name = 'IEC']".freeze
64
76
 
65
77
  def split_bibitems(f)
66
78
  iso_bibitem = []
@@ -85,33 +97,22 @@ module IsoDoc
85
97
  end
86
98
  end
87
99
 
88
- NORM_WITH_REFS_PREF = <<~BOILERPLATE
89
- The following documents are referred to in the text in such a way
90
- that some or all of their content constitutes requirements of this
91
- document. For dated references, only the edition cited applies.
92
- For undated references, the latest edition of the referenced
93
- document (including any amendments) applies.
94
- BOILERPLATE
95
-
96
- NORM_EMPTY_PREF =
97
- "There are no normative references in this document."
98
-
99
100
  def norm_ref_preface(f, div)
100
101
  refs = f.elements.select do |e|
101
102
  ["reference", "bibitem"].include? e.name
102
103
  end
103
- pref = if refs.empty? then self.class::NORM_EMPTY_PREF
104
- else
105
- self.class::NORM_WITH_REFS_PREF
104
+ pref = if refs.empty? then @norm_empty_pref
105
+ else
106
+ @norm_with_refs_pref
106
107
  end
107
108
  div.p pref
108
109
  end
109
110
 
110
111
  def norm_ref(isoxml, out)
111
112
  q = "./*/references[title = 'Normative References']"
112
- f = isoxml.at(ns(q)) or return
113
+ f = isoxml.at(ns(q)) || return
113
114
  out.div do |div|
114
- clause_name("2.", "Normative References", div, false)
115
+ clause_name("2.", @normref_lbl, div, nil)
115
116
  norm_ref_preface(f, div)
116
117
  biblio_list(f, div, false)
117
118
  end
@@ -119,15 +120,48 @@ module IsoDoc
119
120
 
120
121
  def bibliography(isoxml, out)
121
122
  q = "./*/references[title = 'Bibliography']"
122
- f = isoxml.at(ns(q)) or return
123
+ f = isoxml.at(ns(q)) || return
123
124
  page_break(out)
124
125
  out.div do |div|
125
- div.h1 "Bibliography", **{ class: "Section3" }
126
+ div.h1 @bibliography_lbl, **{ class: "Section3" }
126
127
  f.elements.reject do |e|
127
128
  ["reference", "title", "bibitem"].include? e.name
128
129
  end.each { |e| parse(e, div) }
129
130
  biblio_list(f, div, true)
130
131
  end
131
132
  end
133
+
134
+ def bibliography_parse(node, out)
135
+ title = node&.at(ns("./title"))&.text || ""
136
+ out.div do |div|
137
+ div.h2 title, **{ class: "Section3" }
138
+ node.elements.reject do |e|
139
+ ["reference", "title", "bibitem"].include? e.name
140
+ end.each { |e| parse(e, div) }
141
+ biblio_list(node, div, true)
142
+ end
143
+ end
144
+
145
+ def format_ref(ref, isopub)
146
+ return "ISO #{ref}" if isopub
147
+ return "[#{ref}]" if /^\d+$/.match?(ref) && !/^\[.*\]$/.match?(ref)
148
+ ref
149
+ end
150
+
151
+ def reference_names(ref)
152
+ isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
153
+ docid = ref.at(ns("./docidentifier"))
154
+ return ref_names(ref) unless docid
155
+ date = ref.at(ns("./date[@type = 'published']"))
156
+ reference = format_ref(docid_l10n(docid.text), isopub)
157
+ reference += ": #{date.text}" if date && isopub && date != "--"
158
+ @anchors[ref["id"]] = { xref: reference }
159
+ end
160
+
161
+ def ref_names(ref)
162
+ linkend = ref.text
163
+ linkend.gsub!(/[\[\]]/, "") unless /^\[\d+\]$/.match? linkend
164
+ @anchors[ref["id"]] = { xref: linkend }
165
+ end
132
166
  end
133
167
  end
@@ -1,42 +1,45 @@
1
1
  module IsoDoc
2
2
  class Convert
3
+ def inline_header_title(out, node, c1)
4
+ out.span **{ class: "zzMoveToFollowing" } do |s|
5
+ s.b do |b|
6
+ b << "#{get_anchors[node['id']][:label]}. #{c1.text} "
7
+ end
8
+ end
9
+ end
10
+
11
+ def clause_parse_title(node, div, c1, out)
12
+ if node["inline-header"] == "true"
13
+ inline_header_title(out, node, c1)
14
+ else
15
+ div.send "h#{get_anchors[node['id']][:level]}" do |h|
16
+ h << "#{get_anchors[node['id']][:label]}. #{c1.text}"
17
+ end
18
+ end
19
+ end
20
+
3
21
  def clause_parse(node, out)
4
- out.div **attr_code(id: node["id"]) do |s|
22
+ out.div **attr_code(id: node["id"]) do |div|
5
23
  node.children.each do |c1|
6
24
  if c1.name == "title"
7
- if node["inline-header"]
8
- out.span **{ class: "zzMoveToFollowing" } do |s|
9
- s.b do |b|
10
- b << "#{get_anchors()[node['id']][:label]}. #{c1.text} "
11
- end
12
- end
13
- else
14
- s.send "h#{get_anchors()[node['id']][:level]}" do |h|
15
- h << "#{get_anchors()[node['id']][:label]}. #{c1.text}"
16
- end
17
- end
25
+ clause_parse_title(node, div, c1, out)
18
26
  else
19
- parse(c1, s)
27
+ parse(c1, div)
20
28
  end
21
29
  end
22
30
  end
23
31
  end
24
32
 
25
- def clause_name(num, title, div, inline_header)
26
- if inline_header
27
- div.span **{ class: "zzMoveToFollowing" } do |s|
28
- s.b do |b|
29
- b << num
30
- b << title + " "
31
- end
32
- end
33
- else
34
- div.h1 do |h1|
33
+ def clause_name(num, title, div, header_class)
34
+ header_class = {} if header_class.nil?
35
+ div.h1 **attr_code(header_class) do |h1|
36
+ if num
35
37
  h1 << num
36
38
  insert_tab(h1, 1)
37
- h1 << title
38
39
  end
40
+ h1 << title
39
41
  end
42
+ div.parent.at(".//h1")
40
43
  end
41
44
 
42
45
  def clause(isoxml, out)
@@ -45,8 +48,8 @@ module IsoDoc
45
48
  out.div **attr_code(id: c["id"]) do |s|
46
49
  c.elements.each do |c1|
47
50
  if c1.name == "title"
48
- clause_name("#{get_anchors()[c['id']][:label]}.",
49
- c1.text, s, c["inline-header"])
51
+ clause_name("#{get_anchors[c['id']][:label]}.",
52
+ c1.text, s, nil)
50
53
  else
51
54
  parse(c1, s)
52
55
  end
@@ -57,7 +60,7 @@ module IsoDoc
57
60
 
58
61
  def annex_name(annex, name, div)
59
62
  div.h1 **{ class: "Annex" } do |t|
60
- t << "#{get_anchors()[annex['id']][:label]}<br/><br/>"
63
+ t << "#{get_anchors[annex['id']][:label]}<br/><br/>"
61
64
  t << "<b>#{name.text}</b>"
62
65
  end
63
66
  end
@@ -65,15 +68,13 @@ module IsoDoc
65
68
  def annex(isoxml, out)
66
69
  isoxml.xpath(ns("//annex")).each do |c|
67
70
  page_break(out)
68
- out.div **attr_code(id: c["id"], class: "Section3" ) do |s|
69
- #s1.div **{ class: "annex" } do |s|
70
- c.elements.each do |c1|
71
- if c1.name == "title" then annex_name(c, c1, s)
72
- else
73
- parse(c1, s)
74
- end
71
+ out.div **attr_code(id: c["id"], class: "Section3") do |s|
72
+ c.elements.each do |c1|
73
+ if c1.name == "title" then annex_name(c, c1, s)
74
+ else
75
+ parse(c1, s)
75
76
  end
76
- # end
77
+ end
77
78
  end
78
79
  end
79
80
  end
@@ -81,39 +82,88 @@ module IsoDoc
81
82
  def scope(isoxml, out)
82
83
  f = isoxml.at(ns("//clause[title = 'Scope']")) || return
83
84
  out.div **attr_code(id: f["id"]) do |div|
84
- clause_name("1.", "Scope", div, false)
85
+ clause_name("1.", @scope_lbl, div, nil)
85
86
  f.elements.each do |e|
86
87
  parse(e, div) unless e.name == "title"
87
88
  end
88
89
  end
89
90
  end
90
91
 
92
+ def external_terms_boilerplate(sources)
93
+ @external_terms_boilerplate.gsub(/%/, sources)
94
+ end
95
+
96
+ def internal_external_terms_boilerplate(sources)
97
+ @internal_external_terms_boilerplate.gsub(/%/, sources)
98
+ end
99
+
100
+ def term_defs_boilerplate(div, source, term)
101
+ if source.empty? && term.nil?
102
+ div << @no_terms_boilerplate
103
+ else
104
+ div << term_defs_boilerplate_cont(source, term)
105
+ end
106
+ div << @term_def_boilerplate
107
+ end
108
+
109
+ def term_defs_boilerplate_cont(src, term)
110
+ sources = sentence_join(src.map { |s| s["citeas"] })
111
+ if src.empty?
112
+ @internal_terms_boilerplate
113
+ elsif term.nil?
114
+ external_terms_boilerplate(sources)
115
+ else
116
+ internal_external_terms_boilerplate(sources)
117
+ end
118
+ end
119
+
120
+ def terms_defs_title(f)
121
+ symbols = f.at(".//symbols-abbrevs")
122
+ return @termsdefsymbols_lbl if symbols
123
+ @termsdef_lbl
124
+ end
125
+
91
126
  def terms_defs(isoxml, out)
92
- f = isoxml.at(ns("//terms")) || return
127
+ f = isoxml.at(ns("//sections/terms")) || return
93
128
  out.div **attr_code(id: f["id"]) do |div|
94
- clause_name("3.", "Terms and Definitions", div, false)
129
+ clause_name("3.", terms_defs_title(f), div, nil)
130
+ term_defs_boilerplate(div, f.xpath(ns("./source")), f.at(ns(".//term")))
95
131
  f.elements.each do |e|
96
- parse(e, div) unless e.name == "title"
132
+ parse(e, div) unless %w{title source}.include? e.name
97
133
  end
98
134
  end
99
135
  end
100
136
 
137
+ # subclause
138
+ def terms_parse(isoxml, out)
139
+ clause_parse(isoxml, out)
140
+ end
141
+
101
142
  def symbols_abbrevs(isoxml, out)
102
- f = isoxml.at(ns("//symbols-abbrevs")) || return
103
- out.div **attr_code(id: f["id"]) do |div|
104
- clause_name("4.", "Symbols and Abbreviations", div, false)
143
+ f = isoxml.at(ns("//sections/symbols-abbrevs")) || return
144
+ out.div **attr_code(id: f["id"], class: "Symbols") do |div|
145
+ clause_name("4.", @symbols_lbl, div, nil)
105
146
  f.elements.each do |e|
106
147
  parse(e, div) unless e.name == "title"
107
148
  end
108
149
  end
109
150
  end
110
151
 
152
+ # subclause
153
+ def symbols_parse(isoxml, out)
154
+ isoxml.children.first.previous =
155
+ "<title>Symbols and Abbreviated Terms</title>"
156
+ clause_parse(isoxml, out)
157
+ end
158
+
111
159
  def introduction(isoxml, out)
112
160
  f = isoxml.at(ns("//introduction")) || return
161
+ num = f.at(ns(".//subsection")) ? "0." : nil
113
162
  title_attr = { class: "IntroTitle" }
114
163
  page_break(out)
115
164
  out.div **{ class: "Section3", id: f["id"] } do |div|
116
- div.h1 "Introduction", **attr_code(title_attr)
165
+ # div.h1 "Introduction", **attr_code(title_attr)
166
+ clause_name(num, @introduction_lbl, div, title_attr)
117
167
  f.elements.each do |e|
118
168
  if e.name == "patent-notice"
119
169
  e.elements.each { |e1| parse(e1, div) }
@@ -128,7 +178,7 @@ module IsoDoc
128
178
  f = isoxml.at(ns("//foreword")) || return
129
179
  page_break(out)
130
180
  out.div **attr_code(id: f["id"]) do |s|
131
- s.h1 **{ class: "ForewordTitle" } { |h1| h1 << "Foreword" }
181
+ s.h1 **{ class: "ForewordTitle" } { |h1| h1 << @foreword_lbl }
132
182
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
133
183
  end
134
184
  end
@@ -2,12 +2,10 @@ module IsoDoc
2
2
  class Convert
3
3
  def table_title_parse(node, out)
4
4
  name = node.at(ns("./name"))
5
- if name
6
- out.p **{ class: "TableTitle", align: "center" } do |p|
7
- p.b do |b|
8
- b << "#{get_anchors()[node['id']][:label]}&nbsp;&mdash; "
9
- b << name.text
10
- end
5
+ out.p **{ class: "TableTitle", align: "center" } do |p|
6
+ p.b do |b|
7
+ b << l10n("#{@table_lbl} #{get_anchors[node['id']][:label]}")
8
+ b << l10n("&nbsp;&mdash; #{name.text}") if name
11
9
  end
12
10
  end
13
11
  end
@@ -60,35 +58,37 @@ module IsoDoc
60
58
  thead_parse(node, t)
61
59
  tbody_parse(node, t)
62
60
  tfoot_parse(node, t)
63
- dl = node.at(ns("./dl")) and parse(dl, out)
61
+ (dl = node.at(ns("./dl"))) && parse(dl, out)
64
62
  node.xpath(ns("./note")).each { |n| parse(n, out) }
65
63
  end
66
64
  @in_table = false
67
65
  # out.p { |p| p << "&nbsp;" }
68
66
  end
69
67
 
70
- SW = "solid windowtext"
68
+ SW = "solid windowtext".freeze
69
+
70
+ # def make_tr_attr(td, row, totalrows, cols, totalcols, header)
71
+ # border-left:#{col.zero? ? "#{SW} 1.5pt;" : "none;"}
72
+ # border-right:#{SW} #{col == totalcols && !header ? "1.5" : "1.0"}pt;
71
73
 
72
- #border-left:#{col.zero? ? "#{SW} 1.5pt;" : "none;"}
73
- #border-right:#{SW} #{col == totalcols && !header ? "1.5" : "1.0"}pt;
74
- def make_tr_attr(td, row, totalrows, col, totalcols, header)
74
+ def make_tr_attr(td, row, totalrows)
75
75
  style = td.name == "th" ? "font-weight:bold;" : ""
76
76
  rowmax = td["rowspan"] ? row + td["rowspan"].to_i - 1 : row
77
77
  style += <<~STYLE
78
- border-top:#{row.zero? ? "#{SW} 1.5pt;" : "none;"}
79
- mso-border-top-alt:#{row.zero? ? "#{SW} 1.5pt;" : "none;"}
80
- border-bottom:#{SW} #{rowmax == totalrows ? "1.5" : "1.0"}pt;
81
- mso-border-bottom-alt:#{SW} #{rowmax == totalrows ? "1.5" : "1.0"}pt;
78
+ border-top:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'}
79
+ mso-border-top-alt:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'}
80
+ border-bottom:#{SW} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
81
+ mso-border-bottom-alt:#{SW} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
82
82
  STYLE
83
83
  { rowspan: td["rowspan"], colspan: td["colspan"],
84
84
  align: td["align"], style: style.gsub(/\n/, "") }
85
85
  end
86
86
 
87
- def tr_parse(node, out, ord, totalrows, header)
87
+ def tr_parse(node, out, ord, totalrows, _header)
88
88
  out.tr do |r|
89
- node.elements.each_with_index do |td, i|
90
- attrs = make_tr_attr(td, ord, totalrows - 1,
91
- i, node.elements.size - 1, header)
89
+ node.elements.each do |td|
90
+ attrs = make_tr_attr(td, ord, totalrows - 1)
91
+ # i, node.elements.size - 1, header)
92
92
  r.send td.name, **attr_code(attrs) do |entry|
93
93
  td.children.each { |n| parse(n, entry) }
94
94
  end
@@ -1,6 +1,5 @@
1
1
  module IsoDoc
2
2
  class Convert
3
-
4
3
  def definition_parse(node, out)
5
4
  node.children.each { |n| parse(n, out) }
6
5
  end
@@ -12,8 +11,8 @@ module IsoDoc
12
11
  end
13
12
 
14
13
  def deprecated_term_parse(node, out)
15
- out.p **{ class: "AltTerms" } do |p|
16
- p << "DEPRECATED: #{node.text}"
14
+ out.p **{ class: "DeprecatedTerms" } do |p|
15
+ p << l10n("#{@deprecated_lbl}: #{node.text}")
17
16
  end
18
17
  end
19
18
 
@@ -38,7 +37,7 @@ module IsoDoc
38
37
  out.div **{ class: "Note" } do |div|
39
38
  first = node.first_element_child
40
39
  div.p **{ class: "Note" } do |p|
41
- p << "EXAMPLE:"
40
+ p << l10n("#{@example_lbl}:")
42
41
  insert_tab(p, 1)
43
42
  para_then_remainder(first, node, p)
44
43
  end
@@ -49,7 +48,7 @@ module IsoDoc
49
48
  out.div **{ class: "Note" } do |div|
50
49
  first = node.first_element_child
51
50
  div.p **{ class: "Note" } do |p|
52
- p << "#{get_anchors()[node["id"]][:label]}: "
51
+ p << "#{get_anchors[node['id']][:label]}: "
53
52
  para_then_remainder(first, node, p)
54
53
  end
55
54
  end
@@ -65,7 +64,7 @@ module IsoDoc
65
64
 
66
65
  def termdef_parse(node, out)
67
66
  out.p **{ class: "TermNum", id: node["id"] } do |p|
68
- p << get_anchors()[node["id"]][:label]
67
+ p << get_anchors[node["id"]][:label]
69
68
  end
70
69
  set_termdomain("")
71
70
  node.children.each { |n| parse(n, out) }