isodoc 1.6.4 → 1.7.0
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 +1 -1
- data/.rubocop.yml +1 -1
- data/isodoc.gemspec +2 -1
- data/lib/isodoc-yaml/i18n-ar.yaml +19 -25
- data/lib/isodoc-yaml/i18n-de.yaml +1 -0
- data/lib/isodoc-yaml/i18n-en.yaml +2 -0
- data/lib/isodoc-yaml/i18n-es.yaml +1 -0
- data/lib/isodoc-yaml/i18n-fr.yaml +2 -0
- data/lib/isodoc-yaml/i18n-ru.yaml +1 -0
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +2 -0
- data/lib/isodoc/convert.rb +4 -2
- data/lib/isodoc/function/blocks.rb +6 -5
- data/lib/isodoc/function/references.rb +33 -52
- data/lib/isodoc/function/section.rb +0 -1
- data/lib/isodoc/function/table.rb +21 -22
- data/lib/isodoc/function/terms.rb +6 -7
- data/lib/isodoc/gem_tasks.rb +8 -9
- data/lib/isodoc/html_convert.rb +5 -1
- data/lib/isodoc/html_function/comments.rb +12 -12
- data/lib/isodoc/html_function/html.rb +2 -2
- data/lib/isodoc/html_function/postprocess.rb +195 -185
- data/lib/isodoc/html_function/sectionsplit.rb +244 -0
- data/lib/isodoc/metadata.rb +22 -20
- data/lib/isodoc/metadata_contributor.rb +31 -28
- data/lib/isodoc/presentation_function/bibdata.rb +7 -0
- data/lib/isodoc/presentation_function/block.rb +7 -4
- data/lib/isodoc/presentation_function/inline.rb +7 -12
- data/lib/isodoc/presentation_function/section.rb +38 -1
- data/lib/isodoc/presentation_xml_convert.rb +2 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/xref.rb +10 -7
- data/lib/isodoc/xref/xref_anchor.rb +45 -44
- data/lib/isodoc/xref/xref_counter.rb +113 -103
- data/lib/isodoc/xref/xref_gen.rb +39 -11
- data/spec/isodoc/blocks_spec.rb +184 -447
- data/spec/isodoc/cleanup_spec.rb +40 -42
- data/spec/isodoc/i18n_spec.rb +694 -821
- data/spec/isodoc/inline_spec.rb +197 -208
- data/spec/isodoc/metadata_spec.rb +384 -379
- data/spec/isodoc/postproc_spec.rb +121 -30
- data/spec/isodoc/presentation_xml_spec.rb +4 -4
- data/spec/isodoc/ref_spec.rb +5 -5
- data/spec/isodoc/section_spec.rb +216 -199
- data/spec/isodoc/sectionsplit_spec.rb +190 -0
- data/spec/isodoc/table_spec.rb +41 -42
- data/spec/isodoc/terms_spec.rb +1 -1
- data/spec/isodoc/xref_spec.rb +684 -1020
- metadata +19 -3
@@ -0,0 +1,244 @@
|
|
1
|
+
require "metanorma"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
module IsoDoc::HtmlFunction
|
5
|
+
module Html
|
6
|
+
# assume we pass in Presentation XML, but we want to recover Semantic XML
|
7
|
+
def sectionsplit_convert(input_filename, file, debug, output_filename = nil)
|
8
|
+
input_filename += ".xml" unless input_filename.match?(/\.xml$/)
|
9
|
+
File.exist?(input_filename) or
|
10
|
+
File.open(input_filename, "w:UTF-8") { |f| f.write(file) }
|
11
|
+
presxml = File.read(input_filename, encoding: "utf-8")
|
12
|
+
@openmathdelim, @closemathdelim = extract_delims(presxml)
|
13
|
+
xml, filename, dir = convert_init(presxml, input_filename, debug)
|
14
|
+
build_collection(xml, presxml, output_filename || filename, dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_collection(xml, presxml, filename, dir)
|
18
|
+
base = File.basename(filename)
|
19
|
+
collection_setup(base, dir)
|
20
|
+
files = sectionsplit(xml, base, dir)
|
21
|
+
collection_manifest(base, files, xml, presxml, dir).render(
|
22
|
+
format: %i(html), output_folder: "#{filename}_collection",
|
23
|
+
coverpage: File.join(dir, "cover.html")
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def collection_manifest(filename, files, origxml, _presxml, dir)
|
28
|
+
File.open(File.join(dir, "#{filename}.html.yaml"), "w:UTF-8") do |f|
|
29
|
+
f.write(collectionyaml(files, origxml))
|
30
|
+
end
|
31
|
+
Metanorma::Collection.parse File.join(dir, "#{filename}.html.yaml")
|
32
|
+
end
|
33
|
+
|
34
|
+
def collection_setup(filename, dir)
|
35
|
+
FileUtils.mkdir_p "#{filename}_collection"
|
36
|
+
FileUtils.mkdir_p dir
|
37
|
+
File.open(File.join(dir, "cover.html"), "w:UTF-8") do |f|
|
38
|
+
f.write(coll_cover)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def coll_cover
|
43
|
+
<<~COVER
|
44
|
+
<html>
|
45
|
+
<head/>
|
46
|
+
<body>
|
47
|
+
<h1>{{ doctitle }}</h1>
|
48
|
+
<h2>{{ docnumber }}</h2>
|
49
|
+
<nav>{{ labels["navigation"] }}</nav>
|
50
|
+
</body>
|
51
|
+
</html>
|
52
|
+
COVER
|
53
|
+
end
|
54
|
+
|
55
|
+
def sectionsplit(xml, filename, dir)
|
56
|
+
xref_preprocess(xml)
|
57
|
+
out = emptydoc(xml)
|
58
|
+
[["//preface/*", "preface"], ["//sections/*", "sections"],
|
59
|
+
["//annex", nil],
|
60
|
+
["//bibliography/*[not(@hidden = 'true')]", "bibliography"],
|
61
|
+
["//indexsect", nil]].each_with_object([]) do |n, ret|
|
62
|
+
xml.xpath(ns(n[0])).each do |s|
|
63
|
+
ret << sectionfile(out, dir, "#{filename}.#{ret.size}", s, n[1])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def emptydoc(xml)
|
69
|
+
out = xml.dup
|
70
|
+
out.xpath(
|
71
|
+
ns("//preface | //sections | //annex | //bibliography/clause | "\
|
72
|
+
"//bibliography/references[not(@hidden = 'true')] | //indexsect"),
|
73
|
+
).each(&:remove)
|
74
|
+
out
|
75
|
+
end
|
76
|
+
|
77
|
+
def sectionfile(xml, dir, file, chunk, parentnode)
|
78
|
+
fname = create_sectionfile(xml.dup, dir, file, chunk, parentnode)
|
79
|
+
{ order: chunk["displayorder"].to_i, url: fname,
|
80
|
+
title: titlerender(chunk) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def create_sectionfile(out, dir, file, chunk, parentnode)
|
84
|
+
ins = out.at(ns("//misccontainer")) || out.at(ns("//bibdata"))
|
85
|
+
if parentnode
|
86
|
+
ins.next = "<#{parentnode}/>"
|
87
|
+
ins.next.add_child(chunk.dup)
|
88
|
+
else
|
89
|
+
ins.next = chunk.dup
|
90
|
+
end
|
91
|
+
outname = "#{file}.xml"
|
92
|
+
File.open(File.join(dir, outname), "w:UTF-8") { |f| f.write(out) }
|
93
|
+
outname
|
94
|
+
end
|
95
|
+
|
96
|
+
def xref_preprocess(xml)
|
97
|
+
svg_preprocess(xml)
|
98
|
+
key = (0...8).map { rand(65..90).chr }.join # random string
|
99
|
+
refs = eref_to_internal_eref(xml, key)
|
100
|
+
refs += xref_to_internal_eref(xml, key)
|
101
|
+
xml.root["type"] = key # to force recognition of internal refs
|
102
|
+
ins = new_hidden_ref(xml)
|
103
|
+
copy_repo_items_biblio(ins, xml)
|
104
|
+
insert_indirect_biblio(ins, refs, key)
|
105
|
+
end
|
106
|
+
|
107
|
+
def svg_preprocess(xml)
|
108
|
+
xml.xpath("//m:svg", "m" => "http://www.w3.org/2000/svg").each do |s|
|
109
|
+
m = svgmap_wrap(s)
|
110
|
+
s.xpath(".//m:a", "m" => "http://www.w3.org/2000/svg").each do |a|
|
111
|
+
next unless /^#/.match? a["href"]
|
112
|
+
|
113
|
+
a["href"] = a["href"].sub(/^#/, "")
|
114
|
+
m << "<target href='#{a['href']}'>"\
|
115
|
+
"<xref target='#{a['href']}'/></target>"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def svgmap_wrap(svg)
|
121
|
+
ret = svg.at("./ancestor::xmlns:svgmap") and return ret
|
122
|
+
ret = svg.at("./ancestor::xmlns:figure")
|
123
|
+
ret.wrap("<svgmap/>")
|
124
|
+
svg.at("./ancestor::xmlns:svgmap")
|
125
|
+
end
|
126
|
+
|
127
|
+
def make_anchor(anchor)
|
128
|
+
"<localityStack><locality type='anchor'><referenceFrom>"\
|
129
|
+
"#{anchor}</referenceFrom></locality></localityStack>"
|
130
|
+
end
|
131
|
+
|
132
|
+
def xref_to_internal_eref(xml, key)
|
133
|
+
xml.xpath(ns("//xref")).each_with_object({}) do |x, m|
|
134
|
+
x["bibitemid"] = "#{key}_#{x['target']}"
|
135
|
+
x << make_anchor(x["target"])
|
136
|
+
m[x["bibitemid"]] = true
|
137
|
+
x.delete("target")
|
138
|
+
x["type"] = key
|
139
|
+
x.name = "eref"
|
140
|
+
end.keys
|
141
|
+
end
|
142
|
+
|
143
|
+
def eref_to_internal_eref(xml, key)
|
144
|
+
eref_to_internal_eref_select(xml).each_with_object([]) do |x, m|
|
145
|
+
url = xml.at(ns("//bibitem[@id = '#{x}']/url[@type = 'citation']"))
|
146
|
+
xml.xpath(("//*[@bibitemid = '#{x}']")).each do |e|
|
147
|
+
id = eref_to_internal_eref1(e, key, url)
|
148
|
+
id and m << id
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def eref_to_internal_eref1(elem, key, url)
|
154
|
+
if url
|
155
|
+
elem.name = "link"
|
156
|
+
elem["target"] = url
|
157
|
+
nil
|
158
|
+
else
|
159
|
+
elem["bibitemid"] = "#{key}_#{elem['bibitemid']}"
|
160
|
+
elem << make_anchor(elem["bibitemid"])
|
161
|
+
elem["type"] = key
|
162
|
+
elem["bibitemid"]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def eref_to_internal_eref_select(xml)
|
167
|
+
refs = xml.xpath(("//*/@bibitemid")).map { |x| x.text } # rubocop:disable Style/SymbolProc
|
168
|
+
refs.uniq.reject do |x|
|
169
|
+
xml.at(ns("//bibitem[@id = '#{x}'][@type = 'internal']")) ||
|
170
|
+
xml.at(ns("//bibitem[@id = '#{x}']"\
|
171
|
+
"[docidentifier/@type = 'repository']"))
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# from standoc
|
176
|
+
def new_hidden_ref(xmldoc)
|
177
|
+
ins = xmldoc.at("bibliography") or
|
178
|
+
xmldoc.root << "<bibliography/>" and ins = xmldoc.at("bibliography")
|
179
|
+
ins.add_child("<references hidden='true' normative='false'/>").first
|
180
|
+
end
|
181
|
+
|
182
|
+
def copy_repo_items_biblio(ins, xml)
|
183
|
+
xml.xpath(ns("//references/bibitem[docidentifier/@type = 'repository']"))
|
184
|
+
.each do |b|
|
185
|
+
ins << b.dup
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def insert_indirect_biblio(ins, refs, prefix)
|
190
|
+
refs.each do |x|
|
191
|
+
ins << <<~BIBENTRY
|
192
|
+
<bibitem id="#{x}" type="internal">
|
193
|
+
<docidentifier type="repository">#{x.sub(/^#{prefix}_/, "#{prefix}/")}</docidentifier>
|
194
|
+
</bibitem>
|
195
|
+
BIBENTRY
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def recursive_string_keys(hash)
|
200
|
+
case hash
|
201
|
+
when Hash then Hash[
|
202
|
+
hash.map { |k, v| [k.to_s, recursive_string_keys(v)] }
|
203
|
+
]
|
204
|
+
when Enumerable then hash.map { |v| recursive_string_keys(v) }
|
205
|
+
else
|
206
|
+
hash
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def titlerender(section)
|
211
|
+
title = section.at(ns("./title")) or return "[Untitled]"
|
212
|
+
t = title.dup
|
213
|
+
t.xpath(ns(".//tab | .//br")).each { |x| x.replace(" ") }
|
214
|
+
t.xpath(ns(".//strong")).each { |x| x.replace(x.children) }
|
215
|
+
t.children.to_xml
|
216
|
+
end
|
217
|
+
|
218
|
+
def collectionyaml(files, xml)
|
219
|
+
ret = {
|
220
|
+
directives: ["presentation-xml", "bare-after-first"],
|
221
|
+
bibdata: {
|
222
|
+
title: {
|
223
|
+
type: "title-main",
|
224
|
+
language: @lang,
|
225
|
+
content: xml.at(ns("//bibdata/title")).text,
|
226
|
+
},
|
227
|
+
type: "collection",
|
228
|
+
docid: {
|
229
|
+
type: xml.at(ns("//bibdata/docidentifier/@type")).text,
|
230
|
+
id: xml.at(ns("//bibdata/docidentifier")).text,
|
231
|
+
},
|
232
|
+
},
|
233
|
+
manifest: {
|
234
|
+
level: "collection",
|
235
|
+
title: "Collection",
|
236
|
+
docref: files.sort_by { |f| f[:order] }.each.map do |f|
|
237
|
+
{ fileref: f[:url], identifier: f[:title] }
|
238
|
+
end,
|
239
|
+
},
|
240
|
+
}
|
241
|
+
recursive_string_keys(ret).to_yaml
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
data/lib/isodoc/metadata.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "./metadata_date"
|
4
|
+
require_relative "./metadata_contributor"
|
5
5
|
|
6
6
|
module IsoDoc
|
7
7
|
class Metadata
|
@@ -17,7 +17,7 @@ module IsoDoc
|
|
17
17
|
|
18
18
|
def initialize(lang, script, i18n, fonts_options = {})
|
19
19
|
@metadata = { lang: lang, script: script }
|
20
|
-
DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] =
|
20
|
+
DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] = "XXX" }
|
21
21
|
@lang = lang
|
22
22
|
@script = script
|
23
23
|
@c = HTMLEntities.new
|
@@ -38,7 +38,7 @@ module IsoDoc
|
|
38
38
|
@metadata[key] = value
|
39
39
|
end
|
40
40
|
|
41
|
-
NOLANG = "[not(@language) or @language = '']"
|
41
|
+
NOLANG = "[not(@language) or @language = '']"
|
42
42
|
|
43
43
|
def currlang
|
44
44
|
"[@language = '#{@lang}']"
|
@@ -54,6 +54,7 @@ module IsoDoc
|
|
54
54
|
def docstatus(xml, _out)
|
55
55
|
set(:unpublished, true)
|
56
56
|
return unless s = xml.at(ns("//bibdata/status/stage#{NOLANG}"))
|
57
|
+
|
57
58
|
s1 = xml.at(ns("//bibdata/status/stage#{currlang}")) || s
|
58
59
|
set(:stage, status_print(s.text))
|
59
60
|
s1 and set(:stage_display, status_print(s1.text))
|
@@ -61,26 +62,26 @@ module IsoDoc
|
|
61
62
|
set(:substage, i)
|
62
63
|
(i1 = xml&.at(ns("//bibdata/status/substage#{currlang}"))&.text || i) and
|
63
64
|
set(:substage_display, i1)
|
64
|
-
(i2 = xml&.at(ns(
|
65
|
+
(i2 = xml&.at(ns("//bibdata/status/iteration"))&.text) and
|
65
66
|
set(:iteration, i2)
|
66
67
|
set(:unpublished, unpublished(s.text))
|
67
68
|
unpublished(s.text) && set(:stageabbr, stage_abbr(s.text))
|
68
69
|
end
|
69
70
|
|
70
71
|
def stage_abbr(docstatus)
|
71
|
-
status_print(docstatus).split(/ /).map { |s| s[0].upcase }.join(
|
72
|
+
status_print(docstatus).split(/ /).map { |s| s[0].upcase }.join("")
|
72
73
|
end
|
73
74
|
|
74
75
|
def unpublished(status)
|
75
|
-
!status.casecmp(
|
76
|
+
!status.casecmp("published").zero?
|
76
77
|
end
|
77
78
|
|
78
79
|
def status_print(status)
|
79
|
-
status.split(/[- ]/).map(&:capitalize).join(
|
80
|
+
status.split(/[- ]/).map(&:capitalize).join(" ")
|
80
81
|
end
|
81
82
|
|
82
83
|
def docid(isoxml, _out)
|
83
|
-
dn = isoxml.at(ns(
|
84
|
+
dn = isoxml.at(ns("//bibdata/docidentifier"))
|
84
85
|
set(:docnumber, dn&.text)
|
85
86
|
end
|
86
87
|
|
@@ -92,23 +93,24 @@ module IsoDoc
|
|
92
93
|
end
|
93
94
|
|
94
95
|
def docnumeric(isoxml, _out)
|
95
|
-
dn = isoxml.at(ns(
|
96
|
+
dn = isoxml.at(ns("//bibdata/docnumber"))
|
96
97
|
set(:docnumeric, dn&.text)
|
97
98
|
end
|
98
99
|
|
99
100
|
def draftinfo(draft, revdate)
|
100
101
|
return "" unless draft
|
102
|
+
|
101
103
|
draftinfo = " (#{@labels['draft_label']} #{draft}"
|
102
104
|
draftinfo += ", #{revdate}" if revdate
|
103
|
-
draftinfo +=
|
105
|
+
draftinfo += ")"
|
104
106
|
l10n(draftinfo, @lang, @script)
|
105
107
|
end
|
106
108
|
|
107
109
|
def version(isoxml, _out)
|
108
|
-
set(:edition, isoxml&.at(ns(
|
109
|
-
set(:docyear, isoxml&.at(ns(
|
110
|
-
set(:draft, isoxml&.at(ns(
|
111
|
-
revdate = isoxml&.at(ns(
|
110
|
+
set(:edition, isoxml&.at(ns("//bibdata/edition"))&.text)
|
111
|
+
set(:docyear, isoxml&.at(ns("//bibdata/copyright/from"))&.text)
|
112
|
+
set(:draft, isoxml&.at(ns("//bibdata/version/draft"))&.text)
|
113
|
+
revdate = isoxml&.at(ns("//bibdata/version/revision-date"))&.text
|
112
114
|
set(:revdate, revdate)
|
113
115
|
set(:revdate_monthyear, monthyr(revdate))
|
114
116
|
set(:draftinfo,
|
@@ -131,20 +133,20 @@ module IsoDoc
|
|
131
133
|
|
132
134
|
def relations_partof(isoxml)
|
133
135
|
std = isoxml.at(ns("//bibdata/relation[@type = 'partOf']")) || return
|
134
|
-
id = std.at(ns(
|
136
|
+
id = std.at(ns(".//docidentifier"))
|
135
137
|
set(:partof, id.text) if id
|
136
138
|
end
|
137
139
|
|
138
140
|
def relations_obsoletes(isoxml)
|
139
141
|
std = isoxml.at(ns("//bibdata/relation[@type = 'obsoletes']")) || return
|
140
|
-
locality = std.at(ns(
|
141
|
-
id = std.at(ns(
|
142
|
+
locality = std.at(ns(".//locality"))
|
143
|
+
id = std.at(ns(".//docidentifier"))
|
142
144
|
set(:obsoletes, id.text) if id
|
143
145
|
set(:obsoletes_part, locality.text) if locality
|
144
146
|
end
|
145
147
|
|
146
148
|
def url(xml, _out)
|
147
|
-
(a = xml.at(ns(
|
149
|
+
(a = xml.at(ns("//bibdata/uri[not(@type)]"))) && set(:url, a.text)
|
148
150
|
(a = xml.at(ns("//bibdata/uri[@type = 'html']"))) && set(:html, a.text)
|
149
151
|
(a = xml.at(ns("//bibdata/uri[@type = 'xml']"))) && set(:xml, a.text)
|
150
152
|
(a = xml.at(ns("//bibdata/uri[@type = 'pdf']"))) && set(:pdf, a.text)
|
@@ -153,7 +155,7 @@ module IsoDoc
|
|
153
155
|
|
154
156
|
def keywords(isoxml, _out)
|
155
157
|
ret = []
|
156
|
-
isoxml.xpath(ns(
|
158
|
+
isoxml.xpath(ns("//bibdata/keyword")).each { |kw| ret << kw.text }
|
157
159
|
set(:keywords, ret)
|
158
160
|
end
|
159
161
|
|
@@ -2,26 +2,29 @@ module IsoDoc
|
|
2
2
|
class Metadata
|
3
3
|
def extract_person_names(authors)
|
4
4
|
authors.reduce([]) do |ret, a|
|
5
|
-
if a.at(ns(
|
6
|
-
ret << a.at(ns(
|
5
|
+
if a.at(ns("./name/completename"))
|
6
|
+
ret << a.at(ns("./name/completename")).text
|
7
7
|
else
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
ret << fn.join(' ') + ' ' + surname
|
8
|
+
forenames = a.xpath(ns("./name/forename"))
|
9
|
+
fn = forenames.each_with_object([]) { |f, m| m << f.text }
|
10
|
+
surname = a&.at(ns("./name/surname"))&.text
|
11
|
+
ret << "#{fn.join(' ')} #{surname}"
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
16
|
def extract_person_affiliations(authors)
|
18
17
|
authors.reduce([]) do |m, a|
|
19
|
-
name = a&.at(ns(
|
20
|
-
subdivs = a&.xpath(ns(
|
21
|
-
name and subdivs and !subdivs.empty? and
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
name = a&.at(ns("./affiliation/organization/name"))&.text
|
19
|
+
subdivs = a&.xpath(ns("./affiliation/organization/subdivision"))&.map(&:text)&.join(", ")
|
20
|
+
name and subdivs and !subdivs.empty? and
|
21
|
+
name = l10n("#{name}, #{subdivs}", @lang, @script)
|
22
|
+
location = a&.at(ns("./affiliation/organization/address/formattedAddress"))&.text
|
23
|
+
m << (if !name.nil? && !location.nil?
|
24
|
+
l10n("#{name}, #{location}", @lang, @script)
|
25
|
+
else
|
26
|
+
(name || location || "")
|
27
|
+
end)
|
25
28
|
m
|
26
29
|
end
|
27
30
|
end
|
@@ -50,19 +53,19 @@ module IsoDoc
|
|
50
53
|
end
|
51
54
|
|
52
55
|
def iso?(org)
|
53
|
-
name = org&.at(ns(
|
54
|
-
abbrev = org&.at(ns(
|
55
|
-
(abbrev ==
|
56
|
-
name ==
|
56
|
+
name = org&.at(ns("./name"))&.text
|
57
|
+
abbrev = org&.at(ns("./abbreviation"))&.text
|
58
|
+
(abbrev == "ISO" ||
|
59
|
+
name == "International Organization for Standardization")
|
57
60
|
end
|
58
61
|
|
59
62
|
def agency1(xml)
|
60
|
-
agency =
|
63
|
+
agency = ""
|
61
64
|
publisher = []
|
62
65
|
xml.xpath(ns("//bibdata/contributor[xmlns:role/@type = 'publisher']/"\
|
63
|
-
|
64
|
-
name = org&.at(ns(
|
65
|
-
agency1 = org&.at(ns(
|
66
|
+
"organization")).each do |org|
|
67
|
+
name = org&.at(ns("./name"))&.text
|
68
|
+
agency1 = org&.at(ns("./abbreviation"))&.text || name
|
66
69
|
publisher << name if name
|
67
70
|
agency = iso?(org) ? "ISO/#{agency}" : "#{agency}#{agency1}/"
|
68
71
|
end
|
@@ -71,21 +74,21 @@ module IsoDoc
|
|
71
74
|
|
72
75
|
def agency(xml)
|
73
76
|
agency, publisher = agency1(xml)
|
74
|
-
set(:agency, agency.sub(%r{/$},
|
75
|
-
set(:publisher, @i18n.multiple_and(publisher, @labels[
|
77
|
+
set(:agency, agency.sub(%r{/$}, ""))
|
78
|
+
set(:publisher, @i18n.multiple_and(publisher, @labels["and"]))
|
76
79
|
agency_addr(xml)
|
77
80
|
end
|
78
81
|
|
79
82
|
def agency_addr(xml)
|
80
83
|
a = xml.at(ns("//bibdata/contributor[xmlns:role/@type = 'publisher'][1]/"\
|
81
84
|
"organization")) or return
|
82
|
-
|
85
|
+
{ subdivision: "./subdivision", pub_phone: "./phone[not(@type = 'fax')]",
|
86
|
+
pub_fax: "./phone[@type = 'fax']", pub_email: "./email",
|
87
|
+
pub_uri: "./uri" }.each do |k, v|
|
88
|
+
n = a.at(ns(v)) and set(k, n.text)
|
89
|
+
end
|
83
90
|
n = a.at(ns("./address/formattedAddress")) and
|
84
91
|
set(:pub_address, n.children.to_xml)
|
85
|
-
n = a.at(ns("./phone[not(@type = 'fax')]")) and set(:pub_phone, n.text)
|
86
|
-
n = a.at(ns("./phone[@type = 'fax']")) and set(:pub_fax, n.text)
|
87
|
-
n = a.at(ns("./email")) and set(:pub_email, n.text)
|
88
|
-
n = a.at(ns("./uri")) and set(:pub_uri, n.text)
|
89
92
|
end
|
90
93
|
end
|
91
94
|
end
|