metanorma 1.3.1 → 1.3.2
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/.hound.yml +3 -1
- data/.rubocop.yml +3 -7
- data/Rakefile +1 -1
- data/lib/metanorma/asciidoctor_extensions/glob_include_processor.rb +4 -6
- data/lib/metanorma/collection.rb +13 -7
- data/lib/metanorma/collection_fileparse.rb +38 -8
- data/lib/metanorma/collection_fileprocess.rb +25 -14
- data/lib/metanorma/collection_manifest.rb +5 -4
- data/lib/metanorma/compile.rb +1 -1
- data/lib/metanorma/config.rb +1 -1
- data/lib/metanorma/document.rb +22 -10
- data/lib/metanorma/input.rb +0 -1
- data/lib/metanorma/output.rb +0 -2
- data/lib/metanorma/output/utils.rb +2 -1
- data/lib/metanorma/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6da8527ed559d4b6833977c169022db5dfec3a9d93926257586d9e676a11e578
|
4
|
+
data.tar.gz: cf9cc8d31d2ae7cbd08787dcb3f4a79747e85fad5c142bc02fd377df91e467e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f86288c180813daf6ceed810dec2bfecc1cdb2605bf45de5f363cf0a7187babffa37095f208679fd1d1a3cdc6aeebfc879a5293f51c4f49ecc9c473a077295
|
7
|
+
data.tar.gz: bc111d4ca32a5b3135cf518c748370654b9f99803b4123de42b2603965bba4a1e6164e6b3307f7f9afa8b53b7b721b1b01941eee22fd3dd5d63d95a8597cb71e
|
data/.github/workflows/rake.yml
CHANGED
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,14 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# https://github.com/
|
3
|
-
# All project-specific additions and overrides should be specified in this file.
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
4
3
|
inherit_from:
|
5
4
|
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
6
5
|
|
7
6
|
# local repo-specific modifications
|
7
|
+
# ...
|
8
8
|
|
9
9
|
AllCops:
|
10
|
-
DisplayCopNames: false
|
11
|
-
StyleGuideCopsOnly: false
|
12
10
|
TargetRubyVersion: 2.4
|
13
|
-
Rails:
|
14
|
-
Enabled: true
|
data/Rakefile
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
module Metanorma::AsciidoctorExtensions
|
2
|
-
|
3
2
|
class GlobIncludeProcessor < ::Asciidoctor::Extensions::IncludeProcessor
|
4
|
-
def process
|
3
|
+
def process(_doc, reader, target_glob, attributes)
|
5
4
|
Dir[File.join reader.dir, target_glob].sort.reverse_each do |target|
|
6
5
|
content = IO.readlines target
|
7
|
-
content.unshift
|
6
|
+
content.unshift "" unless attributes["adjoin-option"]
|
8
7
|
reader.push_include content, target, target, 1, attributes
|
9
8
|
end
|
10
9
|
reader
|
11
10
|
end
|
12
11
|
|
13
|
-
def handles?
|
14
|
-
target.include?
|
12
|
+
def handles?(target)
|
13
|
+
target.include? "*"
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
|
20
18
|
Asciidoctor::Extensions.register do
|
data/lib/metanorma/collection.rb
CHANGED
@@ -44,9 +44,10 @@ module Metanorma
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def clean_exit
|
48
|
+
@log.write(File.join(File.dirname(@file),
|
49
|
+
"#{File.basename(@file, '.*')}.err"))
|
50
|
+
end
|
50
51
|
|
51
52
|
# @return [String] XML
|
52
53
|
def to_xml
|
@@ -110,7 +111,7 @@ module Metanorma
|
|
110
111
|
# @parma mnf [Metanorma::CollectionManifest]
|
111
112
|
# @return [Hash{String=>Metanorma::Document}]
|
112
113
|
def docs_from_xml(xml, mnf)
|
113
|
-
xml.xpath("//xmlns:doc-container
|
114
|
+
xml.xpath("//xmlns:doc-container//xmlns:bibdata")
|
114
115
|
.each_with_object({}) do |b, m|
|
115
116
|
bd = Relaton::Cli.parse_xml b
|
116
117
|
docref = mnf.docref_by_id bd.docidentifier.first.id
|
@@ -153,7 +154,7 @@ module Metanorma
|
|
153
154
|
|
154
155
|
require "metanorma-#{doctype}"
|
155
156
|
out = sections(dummy_header + cnt)
|
156
|
-
builder.send(elm
|
157
|
+
builder.send("#{elm}-content") { |b| b << out }
|
157
158
|
end
|
158
159
|
|
159
160
|
# @param cnt [String] prefatory/final content
|
@@ -168,9 +169,14 @@ module Metanorma
|
|
168
169
|
return unless Array(@directives).include? "documents-inline"
|
169
170
|
|
170
171
|
documents.each_with_index do |(_, d), i|
|
171
|
-
next if d.attachment
|
172
172
|
id = format("doc%<index>09d", index: i)
|
173
|
-
builder.send("doc-container", id: id)
|
173
|
+
builder.send("doc-container", id: id) do |b|
|
174
|
+
if d.attachment
|
175
|
+
d.bibitem and b << d.bibitem.root.to_xml
|
176
|
+
b.attachment Metanorma::Utils::datauri(d.file)
|
177
|
+
else d.to_xml b
|
178
|
+
end
|
179
|
+
end
|
174
180
|
end
|
175
181
|
end
|
176
182
|
|
@@ -13,8 +13,11 @@ module Metanorma
|
|
13
13
|
xrefs.parse xml
|
14
14
|
xrefs.get.each do |k, v|
|
15
15
|
ret[v[:type]] ||= {}
|
16
|
-
index = v[:container] || v[:label].nil? || v[:label].empty?
|
17
|
-
|
16
|
+
index = if v[:container] || v[:label].nil? || v[:label].empty?
|
17
|
+
UUIDTools::UUID.random_create.to_s
|
18
|
+
else
|
19
|
+
v[:label]
|
20
|
+
end
|
18
21
|
ret[v[:type]][index] = k
|
19
22
|
end
|
20
23
|
ret
|
@@ -46,7 +49,8 @@ module Metanorma
|
|
46
49
|
newbib["id"] = id
|
47
50
|
newbib["hidden"] = "true"
|
48
51
|
newbib&.at(ns("./ext"))&.remove
|
49
|
-
_file, url = targetfile(@files[docid],
|
52
|
+
_file, url = targetfile(@files[docid], relative: true, read: false,
|
53
|
+
doc: !@files[docid][:attachment])
|
50
54
|
uri_node = Nokogiri::XML::Node.new "uri", newbib
|
51
55
|
uri_node[:type] = "citation"
|
52
56
|
uri_node.content = url
|
@@ -87,9 +91,32 @@ module Metanorma
|
|
87
91
|
href = isodoc.eref_target(e)
|
88
92
|
next if href == "##{e['bibitemid']}"
|
89
93
|
|
90
|
-
|
91
|
-
|
94
|
+
# XML collection renderer
|
95
|
+
# map locality type and label (e.g. "clause" "1") to id = anchor for
|
96
|
+
# a document
|
97
|
+
# Note: will only key clauses, which have unambiguous reference label in
|
98
|
+
# locality. Notes, examples etc with containers are just plunked against
|
99
|
+
# UUIDs, so that their IDs can at least be registered to be tracked
|
100
|
+
# as existing.
|
101
|
+
# @param id [String]
|
102
|
+
# @param read [Boolean]
|
103
|
+
# @return [Array<String, nil>]
|
104
|
+
# @param bib [Nokogiri::XML::Element]
|
105
|
+
# @param identifier [String]
|
106
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
107
|
+
# Resolves direct links to other files in collection
|
108
|
+
# (repo(current-metanorma-collection/x),
|
109
|
+
# and indirect links to other files in collection
|
110
|
+
# (bibitem[@type = 'internal'] pointing to a file anchor
|
111
|
+
# in another file in the collection)
|
112
|
+
# @param file [String] XML content
|
113
|
+
# @param identifier [String] docid
|
114
|
+
# @param internal_refs [Hash{String=>Hash{String=>String}] schema name to anchor to filename
|
115
|
+
# @return [String] XML content
|
116
|
+
if href =~ /^#/ && !docxml.at("//*[@id = '#{href.sub(/^#/, '')}']")
|
117
|
+
next
|
92
118
|
end
|
119
|
+
|
93
120
|
e["target"] = href.strip
|
94
121
|
e.name = "link"
|
95
122
|
e&.elements&.remove
|
@@ -106,6 +133,7 @@ module Metanorma
|
|
106
133
|
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |b|
|
107
134
|
docid = b&.at(ns("./docidentifier[@type = 'repository']"))&.text
|
108
135
|
next unless docid && %r{^current-metanorma-collection/}.match(docid)
|
136
|
+
|
109
137
|
update_bibitem(b, identifier)
|
110
138
|
update_anchors(b, docxml, docid)
|
111
139
|
end
|
@@ -150,8 +178,9 @@ module Metanorma
|
|
150
178
|
ref = loc.at(ns("./referenceFrom")) || return
|
151
179
|
anchor = "#{ref.text}_#{document_suffix}"
|
152
180
|
return unless @files[docid][:anchors].inject([]) do |m, (_, x)|
|
153
|
-
m+= x.values
|
181
|
+
m += x.values
|
154
182
|
end.include?(anchor)
|
183
|
+
|
155
184
|
ref.content = anchor
|
156
185
|
end
|
157
186
|
|
@@ -174,7 +203,8 @@ module Metanorma
|
|
174
203
|
def gather_internal_refs
|
175
204
|
@files.each_with_object({}) do |(_, x), refs|
|
176
205
|
next if x[:attachment]
|
177
|
-
|
206
|
+
|
207
|
+
file, = targetfile(x, read: true)
|
178
208
|
Nokogiri::XML(file)
|
179
209
|
.xpath(ns("//bibitem[@type = 'internal']/"\
|
180
210
|
"docidentifier[@type = 'repository']")).each do |d|
|
@@ -192,7 +222,7 @@ module Metanorma
|
|
192
222
|
@files.each do |identifier, x|
|
193
223
|
next if x[:attachment]
|
194
224
|
|
195
|
-
file, _filename = targetfile(x, true)
|
225
|
+
file, _filename = targetfile(x, read: true)
|
196
226
|
docxml = Nokogiri::XML(file)
|
197
227
|
refs.each do |schema, ids|
|
198
228
|
ids.each_key do |id|
|
@@ -17,13 +17,16 @@ module Metanorma
|
|
17
17
|
@xml.xpath(ns("//docref")).each do |d|
|
18
18
|
identifier = d.at(ns("./identifier")).text
|
19
19
|
files[identifier] = file_entry(d, path)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
if files[identifier][:attachment]
|
21
|
+
files[identifier][:bibdata] = Metanorma::Document
|
22
|
+
.attachment_bibitem(identifier).root
|
23
|
+
else
|
24
|
+
file, _filename = targetfile(files[identifier], read: true)
|
25
|
+
xml = Nokogiri::XML(file)
|
26
|
+
add_document_suffix(identifier, xml)
|
27
|
+
files[identifier][:anchors] = read_anchors(xml)
|
28
|
+
files[identifier][:bibdata] = xml.at(ns("//bibdata"))
|
29
|
+
end
|
27
30
|
end
|
28
31
|
files
|
29
32
|
end
|
@@ -58,12 +61,20 @@ module Metanorma
|
|
58
61
|
|
59
62
|
# return file contents + output filename for each file in the collection,
|
60
63
|
# given a docref entry
|
61
|
-
# @param data [Hash]
|
62
|
-
# @param read [Boolean]
|
64
|
+
# @param data [Hash] docref entry
|
65
|
+
# @param read [Boolean] read the file in and return it
|
66
|
+
# @param doc [Boolean] I am a Metanorma document,
|
67
|
+
# so my URL should end with html or pdf or whatever
|
68
|
+
# @param relative [Boolean] Return path relative to YAML file,
|
69
|
+
# not relative to calling function
|
63
70
|
# @return [Array<String, nil>]
|
64
|
-
def targetfile(data,
|
65
|
-
|
66
|
-
|
71
|
+
def targetfile(data, options)
|
72
|
+
options = { read: false, doc: true, relative: false }.merge(options)
|
73
|
+
path = options[:relative] ? data[:rel_path] : data[:ref]
|
74
|
+
if data[:type] == "fileref"
|
75
|
+
ref_file path, options[:read], options[:doc]
|
76
|
+
else
|
77
|
+
xml_file data[:id], options[:read]
|
67
78
|
end
|
68
79
|
end
|
69
80
|
|
@@ -94,7 +105,7 @@ module Metanorma
|
|
94
105
|
end
|
95
106
|
|
96
107
|
def copy_file_to_dest(fileref)
|
97
|
-
_file, filename = targetfile(fileref, true, false)
|
108
|
+
_file, filename = targetfile(fileref, read: true, doc: false)
|
98
109
|
dest = File.join(@outdir, fileref[:rel_path])
|
99
110
|
FileUtils.mkdir_p(File.dirname(dest))
|
100
111
|
FileUtils.cp filename, dest
|
@@ -107,7 +118,7 @@ module Metanorma
|
|
107
118
|
@files.each do |identifier, x|
|
108
119
|
if x[:attachment] then copy_file_to_dest(x)
|
109
120
|
else
|
110
|
-
file, filename = targetfile(x, true)
|
121
|
+
file, filename = targetfile(x, read: true)
|
111
122
|
file = update_xrefs(file, identifier, internal_refs)
|
112
123
|
Tempfile.open(["collection", ".xml"], encoding: "utf-8") do |f|
|
113
124
|
f.write(file)
|
@@ -63,12 +63,13 @@ module Metanorma
|
|
63
63
|
docs = @docref.each_with_object({}) do |dr, m|
|
64
64
|
next m unless dr["fileref"]
|
65
65
|
|
66
|
-
m[dr["identifier"]] = Document.parse_file(
|
66
|
+
m[dr["identifier"]] = Document.parse_file(
|
67
|
+
File.join(dir, dr["fileref"]),
|
68
|
+
dr["attachment"], dr["identifier"]
|
69
|
+
)
|
67
70
|
m
|
68
71
|
end
|
69
|
-
@manifest.reduce(docs)
|
70
|
-
mem.merge mnf.documents(dir)
|
71
|
-
end
|
72
|
+
@manifest.reduce(docs) { |mem, mnf| mem.merge mnf.documents(dir) }
|
72
73
|
end
|
73
74
|
|
74
75
|
# @param builder [Nokogiri::XML::Builder]
|
data/lib/metanorma/compile.rb
CHANGED
@@ -223,7 +223,7 @@ module Metanorma
|
|
223
223
|
@processor.output(nil, presentationxml_name, outfilename, ext, isodoc_options) :
|
224
224
|
@processor.output(isodoc, xml_name, outfilename, ext, isodoc_options)
|
225
225
|
rescue StandardError => e
|
226
|
-
if e.message.
|
226
|
+
if e.message.include? "Fatal:"
|
227
227
|
@errors << e.message
|
228
228
|
else
|
229
229
|
puts e.message
|
data/lib/metanorma/config.rb
CHANGED
data/lib/metanorma/document.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Metanorma
|
2
2
|
class Document
|
3
3
|
# @return [Strin]
|
4
|
-
attr_reader :file, :attachment
|
4
|
+
attr_reader :file, :attachment, :bibitem
|
5
5
|
|
6
6
|
# @param bibitem [RelatonBib::BibliographicItem]
|
7
7
|
def initialize(bibitem, file, options = {})
|
@@ -14,9 +14,12 @@ module Metanorma
|
|
14
14
|
class << self
|
15
15
|
# @param file [String] file path
|
16
16
|
# @param attachment [Bool] is an attachment
|
17
|
+
# @param identifier [String] is the identifier assigned the file
|
18
|
+
# in the collection file
|
17
19
|
# @return [Metanorma::Document]
|
18
|
-
def parse_file(file, attachment)
|
19
|
-
new
|
20
|
+
def parse_file(file, attachment, identifier = nil)
|
21
|
+
new(bibitem(file, attachment, identifier), file,
|
22
|
+
{ attachment: attachment })
|
20
23
|
end
|
21
24
|
|
22
25
|
# #param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
|
@@ -31,6 +34,12 @@ module Metanorma
|
|
31
34
|
new(doc, filename, raw: true)
|
32
35
|
end
|
33
36
|
|
37
|
+
def attachment_bibitem(identifier)
|
38
|
+
Nokogiri::XML(
|
39
|
+
"<bibdata><docidentifier>#{identifier}</docidentifier></bibdata>",
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
34
43
|
private
|
35
44
|
|
36
45
|
# #param xml [Nokogiri::XML::Document, Nokogiri::XML::Element]
|
@@ -51,13 +60,16 @@ module Metanorma
|
|
51
60
|
# @param file [String]
|
52
61
|
# @return [RelatonBib::BibliographicItem,
|
53
62
|
# RelatonIso::IsoBibliographicItem]
|
54
|
-
def bibitem(file)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
63
|
+
def bibitem(file, attachment, identifier)
|
64
|
+
if attachment then attachment_bibitem(identifier)
|
65
|
+
else
|
66
|
+
case format(file)
|
67
|
+
when :xml
|
68
|
+
from_xml Nokogiri::XML(File.read(file, encoding: "UTF-8"))
|
69
|
+
when :yaml
|
70
|
+
yaml = File.read(file, encoding: "UTF-8")
|
71
|
+
Relaton::Cli::YAMLConvertor.convert_single_file(yaml)
|
72
|
+
end
|
61
73
|
end
|
62
74
|
end
|
63
75
|
end
|
data/lib/metanorma/input.rb
CHANGED
data/lib/metanorma/output.rb
CHANGED
@@ -7,7 +7,8 @@ module Metanorma
|
|
7
7
|
def file_path(url_path)
|
8
8
|
file_url = url_path
|
9
9
|
file_url = "file://#{url_path}" if Pathname.new(file_url).absolute?
|
10
|
-
|
10
|
+
%r{^file://}.match?(file_url) or
|
11
|
+
file_url = "file://#{Dir.pwd}/#{url_path}"
|
11
12
|
file_url
|
12
13
|
end
|
13
14
|
end
|
data/lib/metanorma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|