metanorma 1.2.8 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72a5ff12b5b2793f4d8b8ced7b5cdc747a7b59cb938300f1e288150787d82951
4
- data.tar.gz: 2a8f1a0fda7ceed680324833c18ab595d9de381aab36f3a5848040743029dfc8
3
+ metadata.gz: c6503cb40980d520fe14a15845b75b748a6cdd40c9206e2218676ac9f2500ff5
4
+ data.tar.gz: cb169e73038bae1a2c8d70170af1eb4956342056bd4d2c88341f0f08d86462ee
5
5
  SHA512:
6
- metadata.gz: d8ad8063e83a0d51494cb9d69f552676b27ac2022c9d477af6e12902bc2a9c7ceddc07d51965c594ab3ddf92839da6071d8a407836774e26c676b2fd3c9d584d
7
- data.tar.gz: 18b394b6fd082a3072d543b120656ee181a68ce4c1a4cf3f0551f53719e07a96ec1b2140d61fac86e328370464e024df38872a0d85bc0b95aee588bb3e844982
6
+ metadata.gz: 66fb9df1d800763aafccdbb696d755627dfda9d29530200d048f91b59f46e081ff3ffe5f5504579d54ef2667ae33d821d1642329bf21eec6b04e1503e992454c
7
+ data.tar.gz: d46d5ba951e50d47e75cd86c627c65958a490a4cb6e74ba4f61523b301caa53ae6eddc57a72dd58653b0b5a2894110ff5e0d55d795ac764ef303d0f607424667
@@ -168,6 +168,7 @@ module Metanorma
168
168
  return unless Array(@directives).include? "documents-inline"
169
169
 
170
170
  documents.each_with_index do |(_, d), i|
171
+ next if d.attachment
171
172
  id = format("doc%<index>09d", index: i)
172
173
  builder.send("doc-container", id: id) { |b| d.to_xml b }
173
174
  end
@@ -0,0 +1,213 @@
1
+ module Metanorma
2
+ # XML collection renderer
3
+ class CollectionRenderer
4
+ # map locality type and label (e.g. "clause" "1") to id = anchor for
5
+ # a document
6
+ # Note: will only key clauses, which have unambiguous reference label in
7
+ # locality. Notes, examples etc with containers are just plunked against
8
+ # UUIDs, so that their IDs can at least be registered to be tracked
9
+ # as existing.
10
+ def read_anchors(xml)
11
+ ret = {}
12
+ xrefs = @isodoc.xref_init(@lang, @script, @isodoc, @isodoc.i18n, {})
13
+ xrefs.parse xml
14
+ xrefs.get.each do |k, v|
15
+ ret[v[:type]] ||= {}
16
+ index = v[:container] || v[:label].nil? || v[:label].empty? ?
17
+ UUIDTools::UUID.random_create.to_s : v[:label]
18
+ ret[v[:type]][index] = k
19
+ end
20
+ ret
21
+ end
22
+
23
+ # @param id [String]
24
+ # @param read [Boolean]
25
+ # @return [Array<String, nil>]
26
+ def xml_file(id, read)
27
+ file = @xml.at(ns("//doc-container[@id = '#{id}']")).to_xml if read
28
+ filename = "#{id}.html"
29
+ [file, filename]
30
+ end
31
+
32
+ # @param bib [Nokogiri::XML::Element]
33
+ # @param identifier [String]
34
+ def update_bibitem(bib, identifier) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
35
+ docid = bib&.at(ns("./docidentifier"))&.text
36
+ unless @files[docid]
37
+ error = "[metanorma] Cannot find crossreference to document #{docid} "\
38
+ "in document #{identifier}."
39
+ @log.add("Cross-References", nil, error)
40
+ Util.log(error, :warning)
41
+ return
42
+ end
43
+ id = bib["id"]
44
+ newbib = bib.replace(@files[docid][:bibdata])
45
+ newbib.name = "bibitem"
46
+ newbib["id"] = id
47
+ newbib["hidden"] = "true"
48
+ newbib&.at(ns("./ext"))&.remove
49
+ _file, url = targetfile(@files[docid], false, !@files[docid][:attachment])
50
+ uri_node = Nokogiri::XML::Node.new "uri", newbib
51
+ uri_node[:type] = "citation"
52
+ uri_node.content = url
53
+ newbib.at(ns("./docidentifier")).previous = uri_node
54
+ end
55
+
56
+ # Resolves direct links to other files in collection
57
+ # (repo(current-metanorma-collection/x),
58
+ # and indirect links to other files in collection
59
+ # (bibitem[@type = 'internal'] pointing to a file anchor
60
+ # in another file in the collection)
61
+ # @param file [String] XML content
62
+ # @param identifier [String] docid
63
+ # @param internal_refs [Hash{String=>Hash{String=>String}] schema name to anchor to filename
64
+ # @return [String] XML content
65
+ def update_xrefs(file, identifier, internal_refs)
66
+ docxml = Nokogiri::XML(file)
67
+ update_indirect_refs_to_docs(docxml, internal_refs)
68
+ add_document_suffix(identifier, docxml)
69
+ update_direct_refs_to_docs(docxml, identifier)
70
+ svgmap_resolve(datauri_encode(docxml))
71
+ docxml.xpath(ns("//references[not(./bibitem[not(@hidden) or @hidden = 'false'])]")).each do |f|
72
+ f["hidden"] = "true"
73
+ end
74
+ docxml.to_xml
75
+ end
76
+
77
+ def datauri_encode(docxml)
78
+ docxml.xpath(ns("//image")).each do |i|
79
+ i["src"] = Metanorma::Utils::datauri(i["src"])
80
+ end
81
+ docxml
82
+ end
83
+
84
+ def svgmap_resolve(docxml)
85
+ isodoc = IsoDoc::Convert.new({})
86
+ docxml.xpath(ns("//svgmap//eref")).each do |e|
87
+ href = isodoc.eref_target(e)
88
+ next if href == "##{e['bibitemid']}"
89
+
90
+ if href.match(/^#/)
91
+ next unless docxml.at("//*[@id = '#{href.sub(/^#/, '')}']")
92
+ end
93
+ e["target"] = href.strip
94
+ e.name = "link"
95
+ e&.elements&.remove
96
+ end
97
+ Metanorma::Utils::svgmap_rewrite(docxml, "")
98
+ end
99
+
100
+ # repo(current-metanorma-collection/ISO 17301-1:2016)
101
+ # replaced by bibdata of "ISO 17301-1:2016" in situ as bibitem.
102
+ # Any erefs to that bibitem id are replaced with relative URL
103
+ # Preferably with anchor, and is a job to realise dynamic lookup
104
+ # of localities.
105
+ def update_direct_refs_to_docs(docxml, identifier)
106
+ docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
107
+ docid = b&.at(ns("./docidentifier[@type = 'repository']"))&.text
108
+ next unless docid && %r{^current-metanorma-collection/}.match(docid)
109
+ update_bibitem(b, identifier)
110
+ update_anchors(b, docxml, docid)
111
+ end
112
+ end
113
+
114
+ # Resolve erefs to a container of ids in another doc,
115
+ # to an anchor eref (direct link)
116
+ def update_indirect_refs_to_docs(docxml, internal_refs)
117
+ internal_refs.each do |schema, ids|
118
+ ids.each do |id, file|
119
+ update_indirect_refs_to_docs1(docxml, schema, id, file)
120
+ end
121
+ end
122
+ end
123
+
124
+ def update_indirect_refs_to_docs1(docxml, schema, id, file)
125
+ docxml.xpath(ns("//eref[@bibitemid = '#{schema}_#{id}']")).each do |e|
126
+ e["citeas"] = file
127
+ end
128
+ docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/"\
129
+ "docidentifier[@type = 'repository']")) or return
130
+ docid.children = "current-metanorma-collection/#{file}"
131
+ docid.previous = "<docidentifier type='X'>#{file}</docidentifier>"
132
+ end
133
+
134
+ # update crossrefences to other documents, to include disambiguating document suffix on id
135
+ def update_anchors(bib, docxml, _id) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
136
+ docid = bib&.at(ns("./docidentifier"))&.text
137
+ docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
138
+ if @files[docid]
139
+ update_anchor_loc(bib, e, docid)
140
+ else
141
+ e << "<strong>** Unresolved reference to document #{docid}, id #{e['bibitemid']}</strong>"
142
+ end
143
+ end
144
+ end
145
+
146
+ def update_anchor_loc(bib, e, docid)
147
+ loc = e.at(ns(".//locality[@type = 'anchor']")) or
148
+ return update_anchor_create_loc(bib, e, docid)
149
+ document_suffix = Metanorma::Utils::to_ncname(docid)
150
+ ref = loc.at(ns("./referenceFrom")) || return
151
+ anchor = "#{ref.text}_#{document_suffix}"
152
+ return unless @files[docid][:anchors].inject([]) do |m, (_, x)|
153
+ m+= x.values
154
+ end.include?(anchor)
155
+ ref.content = anchor
156
+ end
157
+
158
+ # if there is a crossref to another document, with no anchor, retrieve the
159
+ # anchor given the locality, and insert it into the crossref
160
+ def update_anchor_create_loc(bib, e, docid)
161
+ ins = e.at(ns("./localityStack")) || return
162
+ type = ins&.at(ns("./locality/@type"))&.text
163
+ ref = ins&.at(ns("./locality/referenceFrom"))&.text
164
+ (anchor = @files[docid][:anchors][type][ref]) || return
165
+ ref_from = Nokogiri::XML::Node.new "referenceFrom", bib
166
+ ref_from.content = anchor.sub(/^_/, "")
167
+ locality = Nokogiri::XML::Node.new "locality", bib
168
+ locality[:type] = "anchor"
169
+ locality.add_child ref_from
170
+ ins << locality
171
+ end
172
+
173
+ # gather internal bibitem references
174
+ def gather_internal_refs
175
+ @files.each_with_object({}) do |(_, x), refs|
176
+ next if x[:attachment]
177
+ file, _ = targetfile(x, true)
178
+ Nokogiri::XML(file)
179
+ .xpath(ns("//bibitem[@type = 'internal']/"\
180
+ "docidentifier[@type = 'repository']")).each do |d|
181
+ a = d.text.split(%r{/}, 2)
182
+ a.size > 1 or next
183
+ refs[a[0]] ||= {}
184
+ refs[a[0]][a[1]] = true
185
+ end
186
+ end
187
+ end
188
+
189
+ # resolve file location for the target of each internal reference
190
+ def locate_internal_refs
191
+ refs = gather_internal_refs
192
+ @files.each do |identifier, x|
193
+ next if x[:attachment]
194
+
195
+ file, _filename = targetfile(x, true)
196
+ docxml = Nokogiri::XML(file)
197
+ refs.each do |schema, ids|
198
+ ids.each_key do |id|
199
+ n = docxml.at("//*[@id = '#{id}']") and
200
+ n.at("./ancestor-or-self::*[@type = '#{schema}']") and
201
+ refs[schema][id] = identifier
202
+ end
203
+ end
204
+ end
205
+ refs.each do |schema, ids|
206
+ ids.each do |id, key|
207
+ key == true and refs[schema][id] = "Missing:#{schema}:#{id}"
208
+ end
209
+ end
210
+ refs
211
+ end
212
+ end
213
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "isodoc"
4
4
  require "metanorma-utils"
5
+ require_relative "collection_fileparse"
5
6
 
6
7
  module Metanorma
7
8
  # XML collection renderer
@@ -15,11 +16,9 @@ module Metanorma
15
16
  files = {}
16
17
  @xml.xpath(ns("//docref")).each do |d|
17
18
  identifier = d.at(ns("./identifier")).text
18
- files[identifier] = if d["fileref"]
19
- { type: "fileref",
20
- ref: File.join(path, d["fileref"]) }
21
- else { type: "id", ref: d["id"] }
22
- end
19
+ files[identifier] = file_entry(d, path)
20
+ next if files[identifier][:attachment]
21
+
23
22
  file, _filename = targetfile(files[identifier], true)
24
23
  xml = Nokogiri::XML(file)
25
24
  add_document_suffix(identifier, xml)
@@ -29,6 +28,17 @@ module Metanorma
29
28
  files
30
29
  end
31
30
 
31
+ def file_entry(docref, path)
32
+ ret = if docref["fileref"]
33
+ { type: "fileref", ref: File.join(path, docref["fileref"]),
34
+ rel_path: docref["fileref"] }
35
+ else
36
+ { type: "id", ref: docref["id"] }
37
+ end
38
+ ret[:attachment] = docref["attachment"] if docref["attachment"]
39
+ ret
40
+ end
41
+
32
42
  def add_suffix_to_attributes(doc, suffix, tag_name, attribute_name)
33
43
  doc.xpath(ns("//#{tag_name}[@#{attribute_name}]")).each do |elem|
34
44
  elem.attributes[attribute_name].value =
@@ -38,199 +48,42 @@ module Metanorma
38
48
 
39
49
  def add_document_suffix(identifier, doc)
40
50
  document_suffix = Metanorma::Utils::to_ncname(identifier)
41
- [%w[* id],
42
- %w[* bibitemid],
43
- %w[review from],
44
- %w[review to],
45
- %w[index to],
46
- %w[xref target],
47
- %w[callout target]]
48
- .each do |(tag_name, attribute_name)|
51
+ [%w[* id], %w[* bibitemid], %w[review from],
52
+ %w[review to], %w[index to], %w[xref target],
53
+ %w[callout target]]
54
+ .each do |(tag_name, attribute_name)|
49
55
  add_suffix_to_attributes(doc, document_suffix, tag_name, attribute_name)
50
56
  end
51
57
  end
52
58
 
53
- # map locality type and label (e.g. "clause" "1") to id = anchor for
54
- # a document
55
- def read_anchors(xml)
56
- ret = {}
57
- xrefs = @isodoc.xref_init(@lang, @script, @isodoc, @isodoc.i18n, {})
58
- xrefs.parse xml
59
- xrefs.get.each do |k, v|
60
- ret[v[:type]] ||= {}
61
- index = v[:container] || v[:label].nil? || v[:label].empty? ?
62
- UUIDTools::UUID.random_create.to_s : v[:label]
63
- # Note: will only key clauses, which have unambiguous reference label in locality.
64
- # Notes, examples etc with containers are just plunked agaisnt UUIDs, so that their
65
- # IDs can at least be registered to be tracked as existing.
66
- ret[v[:type]][index] = k
67
- end
68
- ret
69
- end
70
-
71
59
  # return file contents + output filename for each file in the collection,
72
60
  # given a docref entry
73
61
  # @param data [Hash]
74
62
  # @param read [Boolean]
75
63
  # @return [Array<String, nil>]
76
- def targetfile(data, read = false)
77
- if data[:type] == "fileref" then ref_file data[:ref], read
64
+ def targetfile(data, read = false, doc = true)
65
+ if data[:type] == "fileref" then ref_file data[:ref], read, doc
78
66
  else xml_file data[:id], read
79
67
  end
80
68
  end
81
69
 
82
70
  # @param ref [String]
83
71
  # @param read [Boolean]
72
+ # @param doc [Boolean]
84
73
  # @return [Array<String, nil>]
85
- def ref_file(ref, read)
74
+ def ref_file(ref, read, doc)
86
75
  file = File.read(ref, encoding: "utf-8") if read
87
- filename = ref.sub(/\.xml$/, ".html")
76
+ filename = ref.dup
77
+ filename.sub!(/\.xml$/, ".html") if doc
88
78
  [file, filename]
89
79
  end
90
80
 
91
- # @param id [String]
92
- # @param read [Boolean]
93
- # @return [Array<String, nil>]
94
- def xml_file(id, read)
95
- file = @xml.at(ns("//doc-container[@id = '#{id}']")).to_xml if read
96
- filename = id + ".html"
97
- [file, filename]
98
- end
99
-
100
- # @param bib [Nokogiri::XML::Element]
101
- # @param identifier [String]
102
- def update_bibitem(bib, identifier) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
103
- docid = bib&.at(ns("./docidentifier"))&.text
104
- unless @files[docid]
105
- error = "[metanorma] Cannot find crossreference to document #{docid} in document #{identifier}."
106
- @log.add("Cross-References", nil, error)
107
- Util.log(error, :warning)
108
- return
109
- end
110
- id = bib["id"]
111
- newbib = bib.replace(@files[docid][:bibdata])
112
- newbib.name = "bibitem"
113
- newbib["id"] = id
114
- newbib["hidden"] = "true"
115
- newbib&.at(ns("./ext"))&.remove
116
- _file, url = targetfile(@files[docid], false)
117
- uri_node = Nokogiri::XML::Node.new "uri", newbib
118
- uri_node[:type] = "citation"
119
- uri_node.content = url
120
- newbib.at(ns("./docidentifier")).previous = uri_node
121
- end
122
-
123
- # Resolves direct links to other files in collection (repo(current-metanorma-collection/x),
124
- # and indirect links to other files in collection (bibitem[@type = 'internal'] pointing to a file anchor
125
- # in another file in the collection)
126
- # @param file [String] XML content
127
- # @param identifier [String] docid
128
- # @param internal_refs [Hash{String=>Hash{String=>String}] schema name to anchor to filename
129
- # @return [String] XML content
130
- def update_xrefs(file, identifier, internal_refs)
131
- docxml = Nokogiri::XML(file)
132
- update_indirect_refs_to_docs(docxml, internal_refs)
133
- add_document_suffix(identifier, docxml)
134
- update_direct_refs_to_docs(docxml, identifier)
135
- svgmap_resolve(datauri_encode(docxml))
136
- docxml.xpath(ns("//references[not(./bibitem[not(@hidden) or @hidden = 'false'])]")).each do |f|
137
- f["hidden"] = "true"
138
- end
139
- docxml.to_xml
140
- end
141
-
142
- def datauri_encode(docxml)
143
- docxml.xpath(ns("//image")).each { |i| i["src"] = Metanorma::Utils::datauri(i["src"]) }
144
- docxml
145
- end
146
-
147
- def svgmap_resolve(docxml)
148
- isodoc = IsoDoc::Convert.new({})
149
- docxml.xpath(ns("//svgmap//eref")).each do |e|
150
- href = isodoc.eref_target(e)
151
- next if href == "#" + e["bibitemid"]
152
- if href.match(/^#/)
153
- next unless docxml.at("//*[@id = '#{href.sub(/^#/, '')}']")
154
- end
155
- e["target"] = href.strip
156
- e.name = "link"
157
- e&.elements&.remove
158
- end
159
- Metanorma::Utils::svgmap_rewrite(docxml, "")
160
- end
161
-
162
- # repo(current-metanorma-collection/ISO 17301-1:2016)
163
- # replaced by bibdata of "ISO 17301-1:2016" in situ as bibitem.
164
- # Any erefs to that bibitem id are replaced with relative URL
165
- # Preferably with anchor, and is a job to realise dynamic lookup of localities.
166
- def update_direct_refs_to_docs(docxml, identifier)
167
- docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
168
- docid = b&.at(ns("./docidentifier[@type = 'repository']"))&.text
169
- next unless docid && %r{^current-metanorma-collection/}.match(docid)
170
- update_bibitem(b, identifier)
171
- update_anchors(b, docxml, docid)
172
- end
173
- end
174
-
175
- # Resolve erefs to a container of ids in another doc, to an anchor eref (direct link)
176
- def update_indirect_refs_to_docs(docxml, internal_refs)
177
- internal_refs.each do |schema, ids|
178
- ids.each do |id, file|
179
- update_indirect_refs_to_docs1(docxml, schema, id, file)
180
- end
181
- end
182
- end
183
-
184
- def update_indirect_refs_to_docs1(docxml, schema, id, file)
185
- docxml.xpath(ns("//eref[@bibitemid = '#{schema}_#{id}']")).each do |e|
186
- e["citeas"] = file
187
- end
188
- docid = docxml.at(ns("//bibitem[@id = '#{schema}_#{id}']/docidentifier[@type = 'repository']")) or return
189
- docid.children = "current-metanorma-collection/#{file}"
190
- docid.previous = "<docidentifier type='X'>#{file}</docidentifier>"
191
- end
192
-
193
- # update crossrefences to other documents, to include disambiguating document suffix on id
194
- def update_anchors(bib, docxml, _id) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
195
- docid = bib&.at(ns("./docidentifier"))&.text
196
- docxml.xpath("//xmlns:eref[@citeas = '#{docid}']").each do |e|
197
- if @files[docid]
198
- update_anchor_loc(bib, e, docid)
199
- else
200
- e << "<strong>** Unresolved reference to document #{docid}, id #{e['bibitemid']}</strong>"
201
- end
202
- end
203
- end
204
-
205
- def update_anchor_loc(bib, e, docid)
206
- loc = e.at(ns(".//locality[@type = 'anchor']")) or return update_anchor_create_loc(bib, e, docid)
207
- document_suffix = Metanorma::Utils::to_ncname(docid)
208
- ref = loc.at(ns("./referenceFrom")) || return
209
- anchor = "#{ref.text}_#{document_suffix}"
210
- return unless @files[docid][:anchors].inject([]) { |m, (_, x)| m+= x.values }.include?(anchor)
211
- ref.content = anchor
212
- end
213
-
214
- # if there is a crossref to another document, with no anchor, retrieve the
215
- # anchor given the locality, and insert it into the crossref
216
- def update_anchor_create_loc(bib, e, docid)
217
- ins = e.at(ns("./localityStack")) || return
218
- type = ins&.at(ns("./locality/@type"))&.text
219
- ref = ins&.at(ns("./locality/referenceFrom"))&.text
220
- (anchor = @files[docid][:anchors][type][ref]) || return
221
- ref_from = Nokogiri::XML::Node.new "referenceFrom", bib
222
- ref_from.content = anchor.sub(/^_/, "")
223
- locality = Nokogiri::XML::Node.new "locality", bib
224
- locality[:type] = "anchor"
225
- locality.add_child ref_from
226
- ins << locality
227
- end
228
-
229
81
  # compile and output individual file in collection
230
82
  def file_compile(f, filename, identifier)
231
83
  # warn "metanorma compile -x html #{f.path}"
232
84
  c = Compile.new
233
- c.compile f.path, { format: :asciidoc, extension_keys: @format }.merge(@compile_options)
85
+ c.compile f.path, { format: :asciidoc,
86
+ extension_keys: @format }.merge(@compile_options)
234
87
  @files[identifier][:outputs] = {}
235
88
  @format.each do |e|
236
89
  ext = c.processor.output_formats[e]
@@ -240,38 +93,11 @@ module Metanorma
240
93
  end
241
94
  end
242
95
 
243
- # gather internal bibitem references
244
- def gather_internal_refs
245
- @files.each_with_object({}) do |(identifier, x), refs|
246
- file, _ = targetfile(x, true)
247
- Nokogiri::XML(file).xpath(ns("//bibitem[@type = 'internal']/docidentifier[@type = 'repository']")).each do |d|
248
- a = d.text.split(%r{/}, 2)
249
- a.size > 1 or next
250
- refs[a[0]] ||= {}
251
- refs[a[0]][a[1]] = true
252
- end
253
- end
254
- end
255
-
256
- # resolve file location for the target of each internal reference
257
- def locate_internal_refs
258
- refs = gather_internal_refs
259
- @files.each do |identifier, x|
260
- file, filename = targetfile(x, true)
261
- docxml = Nokogiri::XML(file)
262
- refs.each do |schema, ids|
263
- ids.keys.each do |id|
264
- n = docxml.at("//*[@id = '#{id}']") and n.at("./ancestor-or-self::*[@type = '#{schema}']") and
265
- refs[schema][id] = identifier
266
- end
267
- end
268
- end
269
- refs.each do |schema, ids|
270
- ids.each do |id, key|
271
- key == true and refs[schema][id] = "Missing:#{schema}:#{id}"
272
- end
273
- end
274
- refs
96
+ def copy_file_to_dest(fileref)
97
+ _file, filename = targetfile(fileref, true, false)
98
+ dest = File.join(@outdir, fileref[:rel_path])
99
+ FileUtils.mkdir_p(File.dirname(dest))
100
+ FileUtils.cp filename, dest
275
101
  end
276
102
 
277
103
  # process each file in the collection
@@ -279,12 +105,15 @@ module Metanorma
279
105
  def files # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
280
106
  internal_refs = locate_internal_refs
281
107
  @files.each do |identifier, x|
282
- file, filename = targetfile(x, true)
283
- file = update_xrefs(file, identifier, internal_refs)
284
- Tempfile.open(["collection", ".xml"], encoding: "utf-8") do |f|
285
- f.write(file)
286
- f.close
287
- file_compile(f, filename, identifier)
108
+ if x[:attachment] then copy_file_to_dest(x)
109
+ else
110
+ file, filename = targetfile(x, true)
111
+ file = update_xrefs(file, identifier, internal_refs)
112
+ Tempfile.open(["collection", ".xml"], encoding: "utf-8") do |f|
113
+ f.write(file)
114
+ f.close
115
+ file_compile(f, filename, identifier)
116
+ end
288
117
  end
289
118
  end
290
119
  end