metanorma 2.0.0 → 2.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.
- checksums.yaml +4 -4
- data/.envrc +1 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +23 -2
- data/Gemfile +17 -0
- data/Gemfile.devel +10 -0
- data/README.adoc +1 -1
- data/lib/metanorma/collection/artifact_store.rb +142 -0
- data/lib/metanorma/collection/collection.rb +160 -122
- data/lib/metanorma/collection/config/bibdata.rb +3 -3
- data/lib/metanorma/collection/config/compile_options.rb +4 -5
- data/lib/metanorma/collection/config/config.rb +81 -83
- data/lib/metanorma/collection/config/converters.rb +92 -8
- data/lib/metanorma/collection/config/directive.rb +9 -3
- data/lib/metanorma/collection/config/doc_container.rb +28 -0
- data/lib/metanorma/collection/config/manifest.rb +59 -29
- data/lib/metanorma/collection/config/namespaces.rb +12 -0
- data/lib/metanorma/collection/document/document.rb +56 -15
- data/lib/metanorma/collection/filelookup/filelookup.rb +185 -77
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +99 -27
- data/lib/metanorma/collection/filelookup/utils.rb +52 -0
- data/lib/metanorma/collection/helpers.rb +82 -0
- data/lib/metanorma/collection/log.rb +24 -0
- data/lib/metanorma/collection/manifest/manifest.rb +45 -14
- data/lib/metanorma/collection/multilingual/multilingual.rb +660 -0
- data/lib/metanorma/collection/renderer/filelocation.rb +166 -0
- data/lib/metanorma/collection/renderer/fileparse.rb +135 -115
- data/lib/metanorma/collection/renderer/fileprocess.rb +185 -37
- data/lib/metanorma/collection/renderer/navigation.rb +21 -7
- data/lib/metanorma/collection/renderer/render_word.rb +15 -10
- data/lib/metanorma/collection/renderer/renderer.rb +236 -32
- data/lib/metanorma/collection/renderer/svg.rb +107 -0
- data/lib/metanorma/collection/renderer/utils.rb +110 -39
- data/lib/metanorma/collection/sectionsplit/collection.rb +110 -0
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +198 -115
- data/lib/metanorma/collection/util/disambig_files.rb +4 -5
- data/lib/metanorma/collection/util/util.rb +155 -18
- data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +47 -33
- data/lib/metanorma/compile/assets/icc-boilerplate.adoc +41 -0
- data/lib/metanorma/compile/compile.rb +181 -156
- data/lib/metanorma/compile/compile_options.rb +186 -79
- data/lib/metanorma/compile/extract.rb +75 -58
- data/lib/metanorma/compile/flavor.rb +28 -0
- data/lib/metanorma/compile/output_filename.rb +75 -0
- data/lib/metanorma/compile/output_filename_config.rb +27 -0
- data/lib/metanorma/compile/relaton_drop.rb +56 -0
- data/lib/metanorma/compile/render.rb +226 -0
- data/lib/metanorma/compile/validator.rb +26 -0
- data/lib/metanorma/compile/writeable.rb +12 -0
- data/lib/metanorma/util/fontist_helper.rb +35 -19
- data/lib/metanorma/version.rb +1 -1
- data/lib/metanorma.rb +1 -7
- data/metanorma.gemspec +15 -21
- data/plans/collection-rendering-architecture-review.md +516 -0
- metadata +65 -113
- data/.hound.yml +0 -5
- data/lib/metanorma/asciidoctor_extensions/glob_include_processor.rb +0 -22
- data/lib/metanorma/asciidoctor_extensions.rb +0 -1
- data/lib/metanorma/compile/compile_validate.rb +0 -68
- data/lib/metanorma/config/config.rb +0 -23
- data/lib/metanorma/input/asciidoc.rb +0 -107
- data/lib/metanorma/input/base.rb +0 -9
- data/lib/metanorma/input.rb +0 -7
- data/lib/metanorma/processor/processor.rb +0 -54
- data/lib/metanorma/processor.rb +0 -6
- data/lib/metanorma/registry/registry.rb +0 -63
- data/lib/metanorma/shale_monkeypatch.rb +0 -15
- data/lib/metanorma/util/util.rb +0 -45
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module Metanorma
|
|
2
|
+
class Collection
|
|
3
|
+
class << self
|
|
4
|
+
# @param Block [Proc]
|
|
5
|
+
# @note allow user-specific function to run in pre-parse model stage
|
|
6
|
+
def set_pre_parse_model(&block)
|
|
7
|
+
@pre_parse_model_proc = block
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# @param Block [Proc]
|
|
11
|
+
# @note allow user-specific function to resolve identifier
|
|
12
|
+
def set_identifier_resolver(&block)
|
|
13
|
+
@identifier_resolver = block
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @param Block [Proc]
|
|
17
|
+
# @note allow user-specific function to resolve fileref
|
|
18
|
+
# NOTE: MUST ALWAYS RETURN PATH relative to working directory
|
|
19
|
+
# (initial YAML file location). @fileref_resolver.call(ref_folder, fileref)
|
|
20
|
+
# fileref is not what is in the YAML, but the resolved path
|
|
21
|
+
# relative to the working directory
|
|
22
|
+
def set_fileref_resolver(&block)
|
|
23
|
+
@fileref_resolver = block
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def unset_fileref_resolver
|
|
27
|
+
@fileref_resolver = nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @param collection_model [Hash{String=>String}]
|
|
31
|
+
def pre_parse_model(collection_model)
|
|
32
|
+
@pre_parse_model_proc or return
|
|
33
|
+
@pre_parse_model_proc.call(collection_model)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @param identifier [String]
|
|
37
|
+
# @return [String]
|
|
38
|
+
def resolve_identifier(identifier)
|
|
39
|
+
@identifier_resolver or return identifier
|
|
40
|
+
@identifier_resolver.call(identifier)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @param fileref [String]
|
|
44
|
+
# @return [String]
|
|
45
|
+
def resolve_fileref(ref_folder, fileref)
|
|
46
|
+
warn ref_folder
|
|
47
|
+
warn fileref
|
|
48
|
+
unless @fileref_resolver
|
|
49
|
+
(Pathname.new fileref).absolute? or
|
|
50
|
+
fileref = File.join(ref_folder, fileref)
|
|
51
|
+
return fileref
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
@fileref_resolver.call(ref_folder, fileref)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @param filepath
|
|
58
|
+
# @raise [FileNotFoundException]
|
|
59
|
+
def check_file_existence(filepath)
|
|
60
|
+
unless File.exist?(filepath)
|
|
61
|
+
error_message = "#{filepath} not found!"
|
|
62
|
+
::Metanorma::Util.log("[metanorma] Error: #{error_message}", :error)
|
|
63
|
+
raise FileNotFoundException.new error_message.to_s
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def parse(file)
|
|
68
|
+
# need @dirname initialised before collection object initialisation
|
|
69
|
+
@dirname = File.expand_path(File.dirname(file))
|
|
70
|
+
config = case file
|
|
71
|
+
when /\.xml$/
|
|
72
|
+
::Metanorma::Collection::Config::Config.from_xml(File.read(file))
|
|
73
|
+
when /.ya?ml$/
|
|
74
|
+
y = YAML.safe_load(File.read(file))
|
|
75
|
+
pre_parse_model(y)
|
|
76
|
+
::Metanorma::Collection::Config::Config.from_yaml(y.to_yaml)
|
|
77
|
+
end
|
|
78
|
+
new(file: file, config: config)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Metanorma
|
|
2
|
+
class Collection
|
|
3
|
+
METANORMA_LOG_MESSAGES = {
|
|
4
|
+
# rubocop:disable Naming/VariableNumber
|
|
5
|
+
"METANORMA_1": { category: "Cross-References",
|
|
6
|
+
error: "Missing cross-reference: %s",
|
|
7
|
+
severity: 2 },
|
|
8
|
+
"METANORMA_2": { category: "Cross-References",
|
|
9
|
+
error: "[metanorma] Cannot find crossreference to document %s in document %s.",
|
|
10
|
+
severity: 2 },
|
|
11
|
+
"METANORMA_3": { category: "Cross-References",
|
|
12
|
+
error: "<strong>** Unresolved reference to document %s from eref</strong>",
|
|
13
|
+
severity: 2 },
|
|
14
|
+
"METANORMA_4": { category: "Rendering",
|
|
15
|
+
error: "Collection member %s: expected output " \
|
|
16
|
+
"file not generated: %s",
|
|
17
|
+
severity: 0 },
|
|
18
|
+
"METANORMA_5": { category: "Rendering",
|
|
19
|
+
error: "Collection member %s: rendering error: %s",
|
|
20
|
+
severity: 0 },
|
|
21
|
+
}.freeze
|
|
22
|
+
# rubocop:enable Naming/VariableNumber
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require "metanorma-core"
|
|
4
4
|
|
|
5
5
|
module Metanorma
|
|
6
6
|
class Collection
|
|
7
7
|
class Manifest
|
|
8
8
|
# @return [Metanorma::Collection]
|
|
9
|
-
attr_reader :collection, :config
|
|
9
|
+
attr_reader :collection, :config, :lang, :script
|
|
10
10
|
|
|
11
11
|
# @param level [String]
|
|
12
12
|
# @param dir [String]
|
|
@@ -20,9 +20,16 @@ module Metanorma
|
|
|
20
20
|
@config = manifest_postprocess(config)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# Ordered pipeline of in-place tree-walks over the manifest; the order is
|
|
24
|
+
# load-bearing. expand_yaml must run early because it grafts nested
|
|
25
|
+
# `fileref` manifests into this tree, so every later pass sees the full
|
|
26
|
+
# entry set; bibdata sets @lang/@script used downstream; compile_adoc
|
|
27
|
+
# turns .adoc sources into .xml before filexist verifies them. Each pass
|
|
28
|
+
# recurses the manifest independently (see the architecture review plan).
|
|
23
29
|
def manifest_postprocess(config)
|
|
24
30
|
manifest_bibdata(config)
|
|
25
31
|
manifest_expand_yaml(config, @dir)
|
|
32
|
+
manifest_output_filenames(config)
|
|
26
33
|
manifest_compile_adoc(config)
|
|
27
34
|
manifest_filexist(config)
|
|
28
35
|
manifest_sectionsplit(config)
|
|
@@ -38,6 +45,17 @@ module Metanorma
|
|
|
38
45
|
|
|
39
46
|
GUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
|
40
47
|
|
|
48
|
+
def manifest_output_filenames(config, parent = nil)
|
|
49
|
+
config.output_filename ||=
|
|
50
|
+
parent&.output_filename # || "{basename}.{document-num}"
|
|
51
|
+
config.sectionsplit_filename ||= parent&.sectionsplit_filename ||
|
|
52
|
+
"{basename_legacy}.{sectionsplit-num}"
|
|
53
|
+
# "{basename}-{document-num}.{sectionsplit-num}"
|
|
54
|
+
Array(config.entry).each do |f|
|
|
55
|
+
manifest_output_filenames(f, config)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
41
59
|
def manifest_identifier(config)
|
|
42
60
|
no_id = populate_id_from_doc(config)
|
|
43
61
|
config.identifier =
|
|
@@ -67,15 +85,15 @@ module Metanorma
|
|
|
67
85
|
i = x.at("//xmlns:bibdata/xmlns:docidentifier[@primary = 'true']") ||
|
|
68
86
|
x.at("//xmlns:bibdata/xmlns:docidentifier")
|
|
69
87
|
i or return nil
|
|
70
|
-
@
|
|
88
|
+
@flavor = @collection.flavor
|
|
71
89
|
load_isodoc
|
|
72
90
|
Util::key(@isodoc.docid_prefix(i["type"], i.text))
|
|
73
91
|
end
|
|
74
92
|
|
|
75
93
|
def load_isodoc
|
|
76
94
|
@isodoc and return
|
|
77
|
-
@collection.compile.load_flavor(@
|
|
78
|
-
@isodoc = Util::load_isodoc(@
|
|
95
|
+
@collection.compile.load_flavor(@flavor)
|
|
96
|
+
@isodoc = Util::load_isodoc(@flavor)
|
|
79
97
|
@isodoc.i18n_init(@lang, @script, nil) # for @i18n.all_parts in docid
|
|
80
98
|
end
|
|
81
99
|
|
|
@@ -127,9 +145,15 @@ module Metanorma
|
|
|
127
145
|
end
|
|
128
146
|
|
|
129
147
|
def update_filepaths(entry, prefix)
|
|
148
|
+
# `manifest_expand_yaml_entry` hands us the loaded sub-manifest's
|
|
149
|
+
# `entry` collection directly, which is an Array of entries.
|
|
150
|
+
if entry.is_a?(Array)
|
|
151
|
+
entry.each { |e| update_filepaths(e, prefix) }
|
|
152
|
+
return
|
|
153
|
+
end
|
|
130
154
|
entry.file && !(Pathname.new entry.file).absolute? and
|
|
131
155
|
entry.file = File.join(prefix, entry.file)
|
|
132
|
-
entry
|
|
156
|
+
entry&.entry&.each do |f|
|
|
133
157
|
update_filepaths(f, prefix)
|
|
134
158
|
end
|
|
135
159
|
end
|
|
@@ -153,7 +177,7 @@ module Metanorma
|
|
|
153
177
|
def set_adoc2xml(fileref)
|
|
154
178
|
File.join(
|
|
155
179
|
File.dirname(fileref),
|
|
156
|
-
File.basename(fileref).gsub(
|
|
180
|
+
File.basename(fileref).gsub(/\.adoc$/, ".xml"),
|
|
157
181
|
)
|
|
158
182
|
end
|
|
159
183
|
|
|
@@ -161,15 +185,22 @@ module Metanorma
|
|
|
161
185
|
# @raise [AdocFileNotFoundException]
|
|
162
186
|
def compile_adoc_file(file)
|
|
163
187
|
f = (Pathname.new file).absolute? ? file : File.join(@dir, file)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...", :info)
|
|
188
|
+
File.exist?(f) or raise AdocFileNotFoundException.new "#{f} not found!"
|
|
189
|
+
compile_adoc_file?(file) or return
|
|
190
|
+
::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...", :warning)
|
|
169
191
|
::Metanorma::Compile.new
|
|
170
|
-
.compile(f, agree_to_terms: true,
|
|
192
|
+
.compile(f, agree_to_terms: true, install_fonts: false,
|
|
171
193
|
extension_keys: [:xml])
|
|
172
|
-
::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...done!",
|
|
194
|
+
::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...done!",
|
|
195
|
+
:warning)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def compile_adoc_file?(file)
|
|
199
|
+
!File.exist?(file.sub(/\.adoc$/, ".xml")) and return true
|
|
200
|
+
@collection.directives.detect do |d|
|
|
201
|
+
d.key == "recompile-xml" && d.value == "false"
|
|
202
|
+
end and return false
|
|
203
|
+
true
|
|
173
204
|
end
|
|
174
205
|
|
|
175
206
|
def documents(mnf = @config)
|