isodoc 1.2.3 → 1.2.8
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.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +69 -0
- data/README.adoc +1 -3
- data/isodoc.gemspec +3 -1
- data/lib/isodoc-yaml/i18n-en.yaml +1 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +9 -8
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +1 -0
- data/lib/isodoc/base_style/all.css +5 -1
- data/lib/isodoc/base_style/metanorma_word.css +6 -0
- data/lib/isodoc/base_style/metanorma_word.scss +6 -0
- data/lib/isodoc/base_style/reset.css +5 -1
- data/lib/isodoc/base_style/reset.scss +6 -1
- data/lib/isodoc/convert.rb +1 -14
- data/lib/isodoc/function/blocks.rb +1 -0
- data/lib/isodoc/function/inline.rb +0 -33
- data/lib/isodoc/function/references.rb +5 -3
- data/lib/isodoc/function/table.rb +1 -0
- data/lib/isodoc/function/to_word_html.rb +3 -2
- data/lib/isodoc/function/utils.rb +1 -1
- data/lib/isodoc/html_function/postprocess.rb +1 -0
- data/lib/isodoc/i18n.rb +23 -52
- data/lib/isodoc/metadata.rb +44 -111
- data/lib/isodoc/metadata_contributor.rb +90 -0
- data/lib/isodoc/metadata_date.rb +11 -0
- data/lib/isodoc/presentation_function/bibdata.rb +96 -0
- data/lib/isodoc/presentation_function/block.rb +28 -9
- data/lib/isodoc/presentation_function/inline.rb +149 -34
- data/lib/isodoc/presentation_xml_convert.rb +7 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +12 -0
- data/lib/isodoc/word_function/postprocess.rb +2 -2
- data/lib/isodoc/word_function/table.rb +3 -2
- data/lib/isodoc/xref.rb +1 -0
- data/lib/isodoc/xref/xref_anchor.rb +8 -3
- data/lib/isodoc/xref/xref_counter.rb +21 -7
- data/lib/isodoc/xref/xref_gen.rb +29 -6
- data/lib/isodoc/xref/xref_sect_gen.rb +1 -1
- data/lib/isodoc/xslfo_convert.rb +6 -1
- data/spec/assets/i18n.yaml +22 -5
- data/spec/isodoc/blocks_spec.rb +331 -215
- data/spec/isodoc/footnotes_spec.rb +4 -5
- data/spec/isodoc/i18n_spec.rb +89 -16
- data/spec/isodoc/inline_spec.rb +185 -163
- data/spec/isodoc/metadata_spec.rb +69 -19
- data/spec/isodoc/postproc_spec.rb +40 -3
- data/spec/isodoc/presentation_xml_spec.rb +584 -1
- data/spec/isodoc/ref_spec.rb +5 -5
- data/spec/isodoc/section_spec.rb +9 -9
- data/spec/isodoc/table_spec.rb +306 -207
- data/spec/isodoc/terms_spec.rb +1 -1
- data/spec/isodoc/xref_spec.rb +46 -18
- data/spec/spec_helper.rb +6 -0
- metadata +35 -7
- data/.github/workflows/macos.yml +0 -42
- data/.github/workflows/ubuntu.yml +0 -62
- data/.github/workflows/windows.yml +0 -44
data/lib/isodoc/metadata.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative './metadata_date'
|
4
|
+
require_relative './metadata_contributor'
|
4
5
|
|
5
6
|
module IsoDoc
|
6
7
|
class Metadata
|
7
|
-
DATETYPES = %w{published accessed created implemented obsoleted confirmed
|
8
|
-
updated issued received transmitted copied unchanged
|
9
|
-
circulated vote-started
|
10
|
-
vote-ended}.freeze
|
11
|
-
|
12
8
|
attr_accessor :fonts_options
|
13
9
|
|
14
10
|
def ns(xpath)
|
@@ -20,7 +16,7 @@ module IsoDoc
|
|
20
16
|
end
|
21
17
|
|
22
18
|
def initialize(lang, script, i18n, fonts_options = {})
|
23
|
-
@metadata = {}
|
19
|
+
@metadata = { lang: lang, script: script }
|
24
20
|
DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] = 'XXX' }
|
25
21
|
@lang = lang
|
26
22
|
@script = script
|
@@ -42,113 +38,37 @@ module IsoDoc
|
|
42
38
|
@metadata[key] = value
|
43
39
|
end
|
44
40
|
|
45
|
-
|
46
|
-
authors.reduce([]) do |ret, a|
|
47
|
-
if a.at(ns('./name/completename'))
|
48
|
-
ret << a.at(ns('./name/completename')).text
|
49
|
-
else
|
50
|
-
fn = []
|
51
|
-
forenames = a.xpath(ns('./name/forename'))
|
52
|
-
forenames.each { |f| fn << f.text }
|
53
|
-
surname = a&.at(ns('./name/surname'))&.text
|
54
|
-
ret << fn.join(' ') + ' ' + surname
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
41
|
+
NOLANG = "[not(@language) or @language = '']".freeze
|
58
42
|
|
59
|
-
def
|
60
|
-
|
61
|
-
name = a&.at(ns('./affiliation/organization/name'))&.text
|
62
|
-
location = a&.at(ns('./affiliation/organization/address/'\
|
63
|
-
'formattedAddress'))&.text
|
64
|
-
m << (!name.nil? && !location.nil? ? "#{name}, #{location}" :
|
65
|
-
(name || location || ''))
|
66
|
-
m
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def extract_person_names_affiliations(authors)
|
71
|
-
names = extract_person_names(authors)
|
72
|
-
affils = extract_person_affiliations(authors)
|
73
|
-
ret = {}
|
74
|
-
affils.each_with_index do |a, i|
|
75
|
-
ret[a] ||= []
|
76
|
-
ret[a] << names[i]
|
77
|
-
end
|
78
|
-
ret
|
79
|
-
end
|
80
|
-
|
81
|
-
def personal_authors(isoxml)
|
82
|
-
authors = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\
|
83
|
-
"or xmlns:role/@type = 'editor']/person"))
|
84
|
-
set(:authors, extract_person_names(authors))
|
85
|
-
set(:authors_affiliations, extract_person_names_affiliations(authors))
|
86
|
-
end
|
87
|
-
|
88
|
-
def author(xml, _out)
|
89
|
-
personal_authors(xml)
|
90
|
-
agency(xml)
|
91
|
-
end
|
92
|
-
|
93
|
-
def bibdate(isoxml, _out)
|
94
|
-
isoxml.xpath(ns('//bibdata/date')).each do |d|
|
95
|
-
set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
|
96
|
-
end
|
43
|
+
def currlang
|
44
|
+
"[@language = '#{@lang}']"
|
97
45
|
end
|
98
46
|
|
99
47
|
def doctype(isoxml, _out)
|
100
|
-
b = isoxml&.at(ns(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
def iso?(org)
|
106
|
-
name = org&.at(ns('./name'))&.text
|
107
|
-
abbrev = org&.at(ns('./abbreviation'))&.text
|
108
|
-
(abbrev == 'ISO' ||
|
109
|
-
name == 'International Organization for Standardization')
|
110
|
-
end
|
111
|
-
|
112
|
-
def agency(xml)
|
113
|
-
agency = ''
|
114
|
-
publisher = []
|
115
|
-
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
|
116
|
-
'organization')).each do |org|
|
117
|
-
name = org&.at(ns('./name'))&.text
|
118
|
-
agency1 = org&.at(ns('./abbreviation'))&.text || name
|
119
|
-
publisher << name if name
|
120
|
-
agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
|
121
|
-
end
|
122
|
-
set(:agency, agency.sub(%r{/$}, ''))
|
123
|
-
set(:publisher, multiple_and(publisher, @labels['and']))
|
124
|
-
end
|
125
|
-
|
126
|
-
def multiple_and(names, andword)
|
127
|
-
return '' if names.empty?
|
128
|
-
return names[0] if names.length == 1
|
129
|
-
(names.length == 2) &&
|
130
|
-
(return l10n("#{names[0]} #{andword} #{names[1]}", @lang, @script))
|
131
|
-
l10n(names[0..-2].join(', ') + " #{andword} #{names[-1]}", @lang, @script)
|
48
|
+
b = isoxml&.at(ns("//bibdata/ext/doctype#{NOLANG}"))&.text || return
|
49
|
+
set(:doctype, status_print(b))
|
50
|
+
b1 = isoxml&.at(ns("//bibdata/ext/doctype#{currlang}"))&.text || b
|
51
|
+
set(:doctype_display, status_print(b1))
|
132
52
|
end
|
133
53
|
|
134
|
-
def docstatus(
|
135
|
-
docstatus = isoxml.at(ns('//bibdata/status/stage'))
|
54
|
+
def docstatus(xml, _out)
|
136
55
|
set(:unpublished, true)
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
56
|
+
return unless s = xml.at(ns("//bibdata/status/stage#{NOLANG}"))
|
57
|
+
s1 = xml.at(ns("//bibdata/status/stage#{currlang}")) || s
|
58
|
+
set(:stage, status_print(s.text))
|
59
|
+
s1 and set(:stage_display, status_print(s1.text))
|
60
|
+
(i = xml&.at(ns("//bibdata/status/substage#{NOLANG}"))&.text) and
|
61
|
+
set(:substage, i)
|
62
|
+
(i1 = xml&.at(ns("//bibdata/status/substage#{currlang}"))&.text || i) and
|
63
|
+
set(:substage_display, i1)
|
64
|
+
(i2 = xml&.at(ns('//bibdata/status/iteration'))&.text) and
|
65
|
+
set(:iteration, i2)
|
66
|
+
set(:unpublished, unpublished(s.text))
|
67
|
+
unpublished(s.text) && set(:stageabbr, stage_abbr(s.text))
|
147
68
|
end
|
148
69
|
|
149
70
|
def stage_abbr(docstatus)
|
150
|
-
status_print(docstatus).split(/ /)
|
151
|
-
.map { |s| s[0].upcase }.join('')
|
71
|
+
status_print(docstatus).split(/ /).map { |s| s[0].upcase }.join('')
|
152
72
|
end
|
153
73
|
|
154
74
|
def unpublished(status)
|
@@ -156,7 +76,7 @@ module IsoDoc
|
|
156
76
|
end
|
157
77
|
|
158
78
|
def status_print(status)
|
159
|
-
status.split(
|
79
|
+
status.split(/[- ]/).map(&:capitalize).join(' ')
|
160
80
|
end
|
161
81
|
|
162
82
|
def docid(isoxml, _out)
|
@@ -164,18 +84,23 @@ module IsoDoc
|
|
164
84
|
set(:docnumber, dn&.text)
|
165
85
|
end
|
166
86
|
|
87
|
+
def otherid(isoxml, _out)
|
88
|
+
dn = isoxml.at(ns('//bibdata/docidentifier[@type = "ISBN"]'))
|
89
|
+
set(:isbn, dn&.text)
|
90
|
+
dn = isoxml.at(ns('//bibdata/docidentifier[@type = "ISBN10"]'))
|
91
|
+
set(:isbn10, dn&.text)
|
92
|
+
end
|
93
|
+
|
167
94
|
def docnumeric(isoxml, _out)
|
168
95
|
dn = isoxml.at(ns('//bibdata/docnumber'))
|
169
96
|
set(:docnumeric, dn&.text)
|
170
97
|
end
|
171
98
|
|
172
99
|
def draftinfo(draft, revdate)
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
draftinfo += ')'
|
178
|
-
end
|
100
|
+
return "" unless draft
|
101
|
+
draftinfo = " (#{@labels['draft_label']} #{draft}"
|
102
|
+
draftinfo += ", #{revdate}" if revdate
|
103
|
+
draftinfo += ')'
|
179
104
|
l10n(draftinfo, @lang, @script)
|
180
105
|
end
|
181
106
|
|
@@ -191,7 +116,7 @@ module IsoDoc
|
|
191
116
|
end
|
192
117
|
|
193
118
|
def title(isoxml, _out)
|
194
|
-
main = isoxml&.at(ns("//bibdata/title[@language='
|
119
|
+
main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"))&.text
|
195
120
|
set(:doctitle, main)
|
196
121
|
end
|
197
122
|
|
@@ -231,5 +156,13 @@ module IsoDoc
|
|
231
156
|
isoxml.xpath(ns('//bibdata/keyword')).each { |kw| ret << kw.text }
|
232
157
|
set(:keywords, ret)
|
233
158
|
end
|
159
|
+
|
160
|
+
def note(isoxml, _out)
|
161
|
+
ret = []
|
162
|
+
isoxml.xpath(ns("//bibdata/note[@type = 'title-footnote']")).each do |n|
|
163
|
+
ret << n.text
|
164
|
+
end
|
165
|
+
set(:title_footnote, ret)
|
166
|
+
end
|
234
167
|
end
|
235
168
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class Metadata
|
3
|
+
def extract_person_names(authors)
|
4
|
+
authors.reduce([]) do |ret, a|
|
5
|
+
if a.at(ns('./name/completename'))
|
6
|
+
ret << a.at(ns('./name/completename')).text
|
7
|
+
else
|
8
|
+
fn = []
|
9
|
+
forenames = a.xpath(ns('./name/forename'))
|
10
|
+
forenames.each { |f| fn << f.text }
|
11
|
+
surname = a&.at(ns('./name/surname'))&.text
|
12
|
+
ret << fn.join(' ') + ' ' + surname
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def extract_person_affiliations(authors)
|
18
|
+
authors.reduce([]) do |m, a|
|
19
|
+
name = a&.at(ns('./affiliation/organization/name'))&.text
|
20
|
+
location = a&.at(ns('./affiliation/organization/address/'\
|
21
|
+
'formattedAddress'))&.text
|
22
|
+
m << (!name.nil? && !location.nil? ? "#{name}, #{location}" :
|
23
|
+
(name || location || ''))
|
24
|
+
m
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_person_names_affiliations(authors)
|
29
|
+
names = extract_person_names(authors)
|
30
|
+
affils = extract_person_affiliations(authors)
|
31
|
+
ret = {}
|
32
|
+
affils.each_with_index do |a, i|
|
33
|
+
ret[a] ||= []
|
34
|
+
ret[a] << names[i]
|
35
|
+
end
|
36
|
+
ret
|
37
|
+
end
|
38
|
+
|
39
|
+
def personal_authors(isoxml)
|
40
|
+
authors = isoxml.xpath(ns("//bibdata/contributor[role/@type = 'author' "\
|
41
|
+
"or xmlns:role/@type = 'editor']/person"))
|
42
|
+
set(:authors, extract_person_names(authors))
|
43
|
+
set(:authors_affiliations, extract_person_names_affiliations(authors))
|
44
|
+
end
|
45
|
+
|
46
|
+
def author(xml, _out)
|
47
|
+
personal_authors(xml)
|
48
|
+
agency(xml)
|
49
|
+
end
|
50
|
+
|
51
|
+
def iso?(org)
|
52
|
+
name = org&.at(ns('./name'))&.text
|
53
|
+
abbrev = org&.at(ns('./abbreviation'))&.text
|
54
|
+
(abbrev == 'ISO' ||
|
55
|
+
name == 'International Organization for Standardization')
|
56
|
+
end
|
57
|
+
|
58
|
+
def agency1(xml)
|
59
|
+
agency = ''
|
60
|
+
publisher = []
|
61
|
+
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
|
62
|
+
'organization')).each do |org|
|
63
|
+
name = org&.at(ns('./name'))&.text
|
64
|
+
agency1 = org&.at(ns('./abbreviation'))&.text || name
|
65
|
+
publisher << name if name
|
66
|
+
agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
|
67
|
+
end
|
68
|
+
[agency, publisher]
|
69
|
+
end
|
70
|
+
|
71
|
+
def agency(xml)
|
72
|
+
agency, publisher = agency1(xml)
|
73
|
+
set(:agency, agency.sub(%r{/$}, ''))
|
74
|
+
set(:publisher, @i18n.multiple_and(publisher, @labels['and']))
|
75
|
+
agency_addr(xml)
|
76
|
+
end
|
77
|
+
|
78
|
+
def agency_addr(xml)
|
79
|
+
a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/"\
|
80
|
+
"organization")) or return
|
81
|
+
n = a.at(ns("./subdivision")) and set(:subdivision, n.text)
|
82
|
+
n = a.at(ns("./address/formattedAddress")) and
|
83
|
+
set(:pub_address, n.children.to_xml)
|
84
|
+
n = a.at(ns("./phone[not(@type = 'fax')]")) and set(:pub_phone, n.text)
|
85
|
+
n = a.at(ns("./phone[@type = 'fax']")) and set(:pub_fax, n.text)
|
86
|
+
n = a.at(ns("./email")) and set(:pub_email, n.text)
|
87
|
+
n = a.at(ns("./uri")) and set(:pub_uri, n.text)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/isodoc/metadata_date.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module IsoDoc
|
2
2
|
class Metadata
|
3
|
+
DATETYPES = %w{published accessed created implemented obsoleted confirmed
|
4
|
+
updated issued received transmitted copied unchanged
|
5
|
+
circulated vote-started
|
6
|
+
vote-ended}.freeze
|
7
|
+
|
3
8
|
def months
|
4
9
|
{
|
5
10
|
"01": @labels["month_january"],
|
@@ -35,5 +40,11 @@ module IsoDoc
|
|
35
40
|
Date.parse(isodate).strftime("%B %d, %Y")
|
36
41
|
end
|
37
42
|
end
|
43
|
+
|
44
|
+
def bibdate(isoxml, _out)
|
45
|
+
isoxml.xpath(ns('//bibdata/date')).each do |d|
|
46
|
+
set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
|
47
|
+
end
|
48
|
+
end
|
38
49
|
end
|
39
50
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
|
+
def bibdata(docxml)
|
4
|
+
a = bibdata_current(docxml) or return
|
5
|
+
bibdata_i18n(a)
|
6
|
+
a.next =
|
7
|
+
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), "").join("")}"\
|
8
|
+
"</localized-strings>"
|
9
|
+
end
|
10
|
+
|
11
|
+
def bibdata_current(docxml)
|
12
|
+
a = docxml.at(ns("//bibdata")) or return
|
13
|
+
a.xpath(ns("./language")).each do |l|
|
14
|
+
l.text == @lang and l["current"] = "true"
|
15
|
+
end
|
16
|
+
a.xpath(ns("./script")).each do |l|
|
17
|
+
l.text == @script and l["current"] = "true"
|
18
|
+
end
|
19
|
+
a
|
20
|
+
end
|
21
|
+
|
22
|
+
def bibdata_i18n(b)
|
23
|
+
hash_translate(b, @i18n.get["doctype_dict"], "./ext/doctype")
|
24
|
+
hash_translate(b, @i18n.get["stage_dict"], "./status/stage")
|
25
|
+
hash_translate(b, @i18n.get["substage_dict"], "./status/substage")
|
26
|
+
end
|
27
|
+
|
28
|
+
def hash_translate(bibdata, hash, xpath)
|
29
|
+
x = bibdata.at(ns(xpath)) or return
|
30
|
+
x["language"] = ""
|
31
|
+
hash.is_a? Hash or return
|
32
|
+
hash[x.text] or return
|
33
|
+
x.next = x.dup
|
34
|
+
x.next["language"] = @lang
|
35
|
+
x.next.children = hash[x.text]
|
36
|
+
end
|
37
|
+
|
38
|
+
def i18n_tag(k, v)
|
39
|
+
"<localized-string key='#{k}' language='#{@lang}'>#{v}</localized-string>"
|
40
|
+
end
|
41
|
+
|
42
|
+
def i18n_safe(k)
|
43
|
+
k.gsub(/\s|\./, "_")
|
44
|
+
end
|
45
|
+
|
46
|
+
def i8n_name(h, pref)
|
47
|
+
if h.is_a? Hash then i8n_name1(h, pref)
|
48
|
+
elsif h.is_a? Array
|
49
|
+
h.reject { |a| blank?(a) }.each_with_object([]).
|
50
|
+
with_index do |(v1, g), i|
|
51
|
+
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
|
52
|
+
end
|
53
|
+
else [i18n_tag(pref, h)]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def i8n_name1(h, pref)
|
58
|
+
h.reject { |k, v| blank?(v) }.each_with_object([]) do |(k, v), g|
|
59
|
+
if v.is_a? Hash then i8n_name(v, i18n_safe(k)).each { |x| g << x }
|
60
|
+
elsif v.is_a? Array
|
61
|
+
v.reject { |a| blank?(a) }.each_with_index do |v1, i|
|
62
|
+
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
|
63
|
+
end
|
64
|
+
else
|
65
|
+
g << i18n_tag("#{pref}#{pref.empty? ? "" : "."}#{i18n_safe(k)}", v)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
#https://stackoverflow.com/a/31822406
|
71
|
+
def blank?(v)
|
72
|
+
v.nil? || v.respond_to?(:empty?) && v.empty?
|
73
|
+
end
|
74
|
+
|
75
|
+
def trim_hash(h)
|
76
|
+
loop do
|
77
|
+
h_new = trim_hash1(h)
|
78
|
+
break h if h==h_new
|
79
|
+
h = h_new
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def trim_hash1(h)
|
84
|
+
return h unless h.is_a? Hash
|
85
|
+
h.each_with_object({}) do |(k,v), g|
|
86
|
+
next if blank?(v)
|
87
|
+
g[k] = if v.is_a? Hash then trim_hash1(h[k])
|
88
|
+
elsif v.is_a? Array
|
89
|
+
h[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) }
|
90
|
+
else
|
91
|
+
v
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module IsoDoc
|
2
2
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
|
+
def lower2cap(s)
|
4
|
+
return s if /^[[:upper:]][[:upper:]]/.match(s)
|
5
|
+
s.capitalize
|
6
|
+
end
|
7
|
+
|
3
8
|
def figure(docxml)
|
4
9
|
docxml.xpath(ns("//figure")).each do |f|
|
5
10
|
figure1(f)
|
@@ -12,7 +17,7 @@ module IsoDoc
|
|
12
17
|
return if labelled_ancestor(f) && f.ancestors("figure").empty?
|
13
18
|
return if f.at(ns("./figure")) and !f.at(ns("./name"))
|
14
19
|
lbl = @xrefs.anchor(f['id'], :label, false) or return
|
15
|
-
prefix_name(f, " — ", l10n("#{@i18n.figure} #{lbl}"), "name")
|
20
|
+
prefix_name(f, " — ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
16
21
|
end
|
17
22
|
|
18
23
|
def prefix_name(f, delim, number, elem)
|
@@ -36,7 +41,7 @@ module IsoDoc
|
|
36
41
|
return if labelled_ancestor(f)
|
37
42
|
return unless f.ancestors("example").empty?
|
38
43
|
lbl = @xrefs.anchor(f['id'], :label, false) or return
|
39
|
-
prefix_name(f, " — ", l10n("#{@i18n.figure} #{lbl}"), "name")
|
44
|
+
prefix_name(f, " — ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
|
40
45
|
end
|
41
46
|
|
42
47
|
def formula(docxml)
|
@@ -65,7 +70,7 @@ module IsoDoc
|
|
65
70
|
|
66
71
|
def example1(f)
|
67
72
|
n = @xrefs.get[f["id"]]
|
68
|
-
lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example
|
73
|
+
lbl = (n.nil? || n[:label].nil? || n[:label].empty?) ? @i18n.example:
|
69
74
|
l10n("#{@i18n.example} #{n[:label]}")
|
70
75
|
prefix_name(f, " — ", lbl, "name")
|
71
76
|
end
|
@@ -81,7 +86,7 @@ module IsoDoc
|
|
81
86
|
return if f.parent.name == "bibitem"
|
82
87
|
n = @xrefs.get[f["id"]]
|
83
88
|
lbl = (@i18n.note if n.nil? || n[:label].nil? || n[:label].empty?) ?
|
84
|
-
@i18n.note
|
89
|
+
@i18n.note: l10n("#{@i18n.note} #{n[:label]}")
|
85
90
|
prefix_name(f, "", lbl, "name")
|
86
91
|
end
|
87
92
|
|
@@ -94,24 +99,24 @@ module IsoDoc
|
|
94
99
|
# introduce name element
|
95
100
|
def termnote1(f)
|
96
101
|
lbl = l10n(@xrefs.anchor(f['id'], :label) || '???')
|
97
|
-
prefix_name(f, "", lbl, "name")
|
102
|
+
prefix_name(f, "", lower2cap(lbl), "name")
|
98
103
|
end
|
99
104
|
|
100
105
|
def recommendation(docxml)
|
101
106
|
docxml.xpath(ns("//recommendation")).each do |f|
|
102
|
-
recommendation1(f, @i18n.recommendation)
|
107
|
+
recommendation1(f, lower2cap(@i18n.recommendation))
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
106
111
|
def requirement(docxml)
|
107
112
|
docxml.xpath(ns("//requirement")).each do |f|
|
108
|
-
recommendation1(f, @i18n.requirement)
|
113
|
+
recommendation1(f, lower2cap(@i18n.requirement))
|
109
114
|
end
|
110
115
|
end
|
111
116
|
|
112
117
|
def permission(docxml)
|
113
118
|
docxml.xpath(ns("//permission")).each do |f|
|
114
|
-
recommendation1(f, @i18n.permission)
|
119
|
+
recommendation1(f, lower2cap(@i18n.permission))
|
115
120
|
end
|
116
121
|
end
|
117
122
|
|
@@ -132,7 +137,21 @@ module IsoDoc
|
|
132
137
|
return if labelled_ancestor(f)
|
133
138
|
return if f["unnumbered"] && !f.at(ns("./name"))
|
134
139
|
n = @xrefs.anchor(f['id'], :label, false)
|
135
|
-
prefix_name(f, " — ", l10n("#{@i18n.table} #{n}"), "name")
|
140
|
+
prefix_name(f, " — ", l10n("#{lower2cap @i18n.table} #{n}"), "name")
|
141
|
+
end
|
142
|
+
|
143
|
+
# we use this to eliminate the semantic amend blocks from rendering
|
144
|
+
def amend(docxml)
|
145
|
+
docxml.xpath(ns("//amend")).each do |f|
|
146
|
+
amend1(f)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def amend1(f)
|
151
|
+
f.xpath(ns("./autonumber")).each { |a| a.remove }
|
152
|
+
f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
|
153
|
+
f.xpath(ns("./description")).each { |a| a.replace(a.children) }
|
154
|
+
f.replace(f.children)
|
136
155
|
end
|
137
156
|
end
|
138
157
|
end
|