metanorma 1.7.6 → 2.0.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/Gemfile +5 -1
- data/lib/metanorma/array_monkeypatch.rb +9 -0
- data/lib/metanorma/asciidoctor_extensions/glob_include_processor.rb +13 -11
- data/lib/metanorma/collection/collection.rb +225 -0
- data/lib/metanorma/collection/config/bibdata.rb +12 -0
- data/lib/metanorma/collection/config/compile_options.rb +13 -0
- data/lib/metanorma/collection/config/config.rb +163 -0
- data/lib/metanorma/collection/config/converters.rb +30 -0
- data/lib/metanorma/collection/config/directive.rb +10 -0
- data/lib/metanorma/collection/config/manifest.rb +88 -0
- data/lib/metanorma/collection/document/document.rb +133 -0
- data/lib/metanorma/collection/filelookup/filelookup.rb +250 -0
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +87 -0
- data/lib/metanorma/collection/manifest/manifest.rb +237 -0
- data/lib/metanorma/collection/renderer/fileparse.rb +247 -0
- data/lib/metanorma/collection/renderer/fileprocess.rb +173 -0
- data/lib/metanorma/collection/renderer/navigation.rb +133 -0
- data/lib/metanorma/collection/renderer/render_word.rb +133 -0
- data/lib/metanorma/collection/renderer/renderer.rb +157 -0
- data/lib/metanorma/collection/renderer/utils.rb +183 -0
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +218 -0
- data/lib/metanorma/collection/util/disambig_files.rb +37 -0
- data/lib/metanorma/collection/util/util.rb +72 -0
- data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +222 -0
- data/lib/metanorma/{compile.rb → compile/compile.rb} +17 -11
- data/lib/metanorma/{compile_options.rb → compile/compile_options.rb} +9 -5
- data/lib/metanorma/{compile_validate.rb → compile/compile_validate.rb} +1 -1
- data/lib/metanorma/{extract.rb → compile/extract.rb} +2 -2
- data/lib/metanorma/{config.rb → config/config.rb} +1 -1
- data/lib/metanorma/input/asciidoc.rb +3 -3
- data/lib/metanorma/input/base.rb +1 -5
- data/lib/metanorma/processor/processor.rb +54 -0
- data/lib/metanorma/processor.rb +1 -49
- data/lib/metanorma/{registry.rb → registry/registry.rb} +0 -1
- data/lib/metanorma/shale_monkeypatch.rb +15 -0
- data/lib/metanorma/util/fontist_helper.rb +130 -0
- data/lib/metanorma/util/util.rb +45 -0
- data/lib/metanorma/util/worker_pool.rb +39 -0
- data/lib/metanorma/version.rb +1 -1
- data/lib/metanorma.rb +13 -8
- data/metanorma.gemspec +2 -1
- metadata +51 -26
- data/Gemfile.devel +0 -2
- data/lib/metanorma/collection.rb +0 -243
- data/lib/metanorma/collection_fileparse.rb +0 -254
- data/lib/metanorma/collection_fileprocess.rb +0 -157
- data/lib/metanorma/collection_manifest.rb +0 -139
- data/lib/metanorma/collection_render_utils.rb +0 -169
- data/lib/metanorma/collection_render_word.rb +0 -131
- data/lib/metanorma/collection_renderer.rb +0 -230
- data/lib/metanorma/document.rb +0 -133
- data/lib/metanorma/files_lookup.rb +0 -208
- data/lib/metanorma/files_lookup_sectionsplit.rb +0 -84
- data/lib/metanorma/fontist_utils.rb +0 -122
- data/lib/metanorma/sectionsplit.rb +0 -216
- data/lib/metanorma/sectionsplit_links.rb +0 -189
- data/lib/metanorma/util.rb +0 -127
- data/lib/metanorma/worker_pool.rb +0 -29
@@ -0,0 +1,45 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Util
|
3
|
+
class << self
|
4
|
+
def log(message, type = :info)
|
5
|
+
log_types = Metanorma.configuration.logs.map(&:to_s) || []
|
6
|
+
|
7
|
+
if log_types.include?(type.to_s)
|
8
|
+
puts(message)
|
9
|
+
end
|
10
|
+
|
11
|
+
if type == :fatal
|
12
|
+
exit(1)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# dependency ordering
|
17
|
+
def sort_extensions_execution_ord(ext)
|
18
|
+
case ext
|
19
|
+
when :xml then 0
|
20
|
+
when :rxl then 1
|
21
|
+
when :presentation then 2
|
22
|
+
else
|
23
|
+
99
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def sort_extensions_execution(ext)
|
28
|
+
ext.sort do |a, b|
|
29
|
+
sort_extensions_execution_ord(a) <=> sort_extensions_execution_ord(b)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def recursive_string_keys(hash)
|
34
|
+
case hash
|
35
|
+
when Hash then hash.map do |k, v|
|
36
|
+
[k.to_s, recursive_string_keys(v)]
|
37
|
+
end.to_h
|
38
|
+
when Enumerable then hash.map { |v| recursive_string_keys(v) }
|
39
|
+
else
|
40
|
+
hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Metanorma
|
2
|
+
module Util
|
3
|
+
class WorkersPool
|
4
|
+
def initialize(workers)
|
5
|
+
init_vars(workers)
|
6
|
+
@threads = Array.new(@workers) do
|
7
|
+
init_thread
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_vars(workers)
|
12
|
+
@workers = workers
|
13
|
+
@queue = SizedQueue.new(@workers)
|
14
|
+
end
|
15
|
+
|
16
|
+
def init_thread
|
17
|
+
Thread.new do
|
18
|
+
catch(:exit) do
|
19
|
+
loop do
|
20
|
+
job, args = @queue.pop
|
21
|
+
job.call *args
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def schedule(*args, &block)
|
28
|
+
@queue << [block, args]
|
29
|
+
end
|
30
|
+
|
31
|
+
def shutdown
|
32
|
+
@workers.times do
|
33
|
+
schedule { throw :exit }
|
34
|
+
end
|
35
|
+
@threads.map(&:join)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/metanorma/version.rb
CHANGED
data/lib/metanorma.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
class Array
|
4
|
+
alias orig_filter filter
|
5
|
+
end
|
6
|
+
|
3
7
|
require "metanorma/version"
|
4
8
|
require "asciidoctor"
|
5
|
-
require "metanorma/util"
|
6
|
-
require "metanorma/config"
|
9
|
+
require "metanorma/util/util"
|
10
|
+
require "metanorma/config/config"
|
7
11
|
require "metanorma/input"
|
8
|
-
require "metanorma/registry"
|
9
|
-
require "metanorma/processor"
|
12
|
+
require "metanorma/registry/registry"
|
13
|
+
require "metanorma/processor/processor"
|
10
14
|
require "metanorma/asciidoctor_extensions"
|
11
|
-
require "metanorma/compile"
|
12
|
-
require "metanorma/collection"
|
13
|
-
require "metanorma/
|
14
|
-
require "metanorma/
|
15
|
+
require "metanorma/compile/compile"
|
16
|
+
require "metanorma/collection/collection"
|
17
|
+
require "metanorma/collection/manifest/manifest"
|
18
|
+
require "metanorma/collection/renderer/renderer"
|
19
|
+
require "metanorma/collection/document/document"
|
15
20
|
require "vectory"
|
16
21
|
|
17
22
|
# Metanorma module
|
data/metanorma.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_runtime_dependency "isodoc", ">= 2.6.3"
|
30
30
|
spec.add_runtime_dependency "mn2pdf", "~> 1"
|
31
31
|
spec.add_runtime_dependency "nokogiri"
|
32
|
-
spec.add_runtime_dependency "
|
32
|
+
spec.add_runtime_dependency "shale"
|
33
33
|
|
34
34
|
# get relaton-cli to avoid circular reference with metanorma-standoc
|
35
35
|
# spec.add_dependency "relaton-cli"
|
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
40
40
|
spec.add_development_dependency "metanorma-iso"
|
41
41
|
spec.add_development_dependency "mnconvert"
|
42
|
+
spec.add_development_dependency "pry"
|
42
43
|
spec.add_development_dependency "rake", "~> 13.0"
|
43
44
|
spec.add_development_dependency "rspec", "~> 3.0"
|
44
45
|
spec.add_development_dependency "rspec-command", "~> 1.0"
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04
|
11
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: shale
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: rake
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -265,38 +279,49 @@ files:
|
|
265
279
|
- CHANGELOG.adoc
|
266
280
|
- CODE_OF_CONDUCT.md
|
267
281
|
- Gemfile
|
268
|
-
- Gemfile.devel
|
269
282
|
- LICENSE.txt
|
270
283
|
- README.adoc
|
271
284
|
- lib/metanorma.rb
|
285
|
+
- lib/metanorma/array_monkeypatch.rb
|
272
286
|
- lib/metanorma/asciidoctor_extensions.rb
|
273
287
|
- lib/metanorma/asciidoctor_extensions/glob_include_processor.rb
|
274
|
-
- lib/metanorma/collection.rb
|
275
|
-
- lib/metanorma/
|
276
|
-
- lib/metanorma/
|
277
|
-
- lib/metanorma/
|
278
|
-
- lib/metanorma/
|
279
|
-
- lib/metanorma/
|
280
|
-
- lib/metanorma/
|
281
|
-
- lib/metanorma/
|
282
|
-
- lib/metanorma/
|
283
|
-
- lib/metanorma/
|
284
|
-
- lib/metanorma/
|
285
|
-
- lib/metanorma/
|
286
|
-
- lib/metanorma/
|
287
|
-
- lib/metanorma/
|
288
|
-
- lib/metanorma/
|
289
|
-
- lib/metanorma/
|
288
|
+
- lib/metanorma/collection/collection.rb
|
289
|
+
- lib/metanorma/collection/config/bibdata.rb
|
290
|
+
- lib/metanorma/collection/config/compile_options.rb
|
291
|
+
- lib/metanorma/collection/config/config.rb
|
292
|
+
- lib/metanorma/collection/config/converters.rb
|
293
|
+
- lib/metanorma/collection/config/directive.rb
|
294
|
+
- lib/metanorma/collection/config/manifest.rb
|
295
|
+
- lib/metanorma/collection/document/document.rb
|
296
|
+
- lib/metanorma/collection/filelookup/filelookup.rb
|
297
|
+
- lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb
|
298
|
+
- lib/metanorma/collection/manifest/manifest.rb
|
299
|
+
- lib/metanorma/collection/renderer/fileparse.rb
|
300
|
+
- lib/metanorma/collection/renderer/fileprocess.rb
|
301
|
+
- lib/metanorma/collection/renderer/navigation.rb
|
302
|
+
- lib/metanorma/collection/renderer/render_word.rb
|
303
|
+
- lib/metanorma/collection/renderer/renderer.rb
|
304
|
+
- lib/metanorma/collection/renderer/utils.rb
|
305
|
+
- lib/metanorma/collection/sectionsplit/sectionsplit.rb
|
306
|
+
- lib/metanorma/collection/util/disambig_files.rb
|
307
|
+
- lib/metanorma/collection/util/util.rb
|
308
|
+
- lib/metanorma/collection/xrefprocess/xrefprocess.rb
|
309
|
+
- lib/metanorma/compile/compile.rb
|
310
|
+
- lib/metanorma/compile/compile_options.rb
|
311
|
+
- lib/metanorma/compile/compile_validate.rb
|
312
|
+
- lib/metanorma/compile/extract.rb
|
313
|
+
- lib/metanorma/config/config.rb
|
290
314
|
- lib/metanorma/input.rb
|
291
315
|
- lib/metanorma/input/asciidoc.rb
|
292
316
|
- lib/metanorma/input/base.rb
|
293
317
|
- lib/metanorma/processor.rb
|
294
|
-
- lib/metanorma/
|
295
|
-
- lib/metanorma/
|
296
|
-
- lib/metanorma/
|
297
|
-
- lib/metanorma/util.rb
|
318
|
+
- lib/metanorma/processor/processor.rb
|
319
|
+
- lib/metanorma/registry/registry.rb
|
320
|
+
- lib/metanorma/shale_monkeypatch.rb
|
321
|
+
- lib/metanorma/util/fontist_helper.rb
|
322
|
+
- lib/metanorma/util/util.rb
|
323
|
+
- lib/metanorma/util/worker_pool.rb
|
298
324
|
- lib/metanorma/version.rb
|
299
|
-
- lib/metanorma/worker_pool.rb
|
300
325
|
- metanorma.gemspec
|
301
326
|
homepage: https://github.com/metanorma/metanorma
|
302
327
|
licenses:
|
@@ -317,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
317
342
|
- !ruby/object:Gem::Version
|
318
343
|
version: '0'
|
319
344
|
requirements: []
|
320
|
-
rubygems_version: 3.3.
|
345
|
+
rubygems_version: 3.3.27
|
321
346
|
signing_key:
|
322
347
|
specification_version: 4
|
323
348
|
summary: Metanorma is the standard of standards; the metanorma gem allows you to create
|
data/Gemfile.devel
DELETED
data/lib/metanorma/collection.rb
DELETED
@@ -1,243 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "relaton"
|
4
|
-
require "relaton/cli"
|
5
|
-
require "metanorma/collection_manifest"
|
6
|
-
require "metanorma-utils"
|
7
|
-
require_relative "util"
|
8
|
-
|
9
|
-
module Metanorma
|
10
|
-
# Metanorma collection of documents
|
11
|
-
class Collection
|
12
|
-
attr_reader :file
|
13
|
-
|
14
|
-
# @return [Array<String>] documents-inline to inject the XML into
|
15
|
-
# the collection manifest; documents-external to keeps them outside
|
16
|
-
attr_accessor :directives, :documents, :bibdatas, :coverpage, :dirname
|
17
|
-
attr_accessor :disambig, :manifest
|
18
|
-
|
19
|
-
# @param file [String] path to source file
|
20
|
-
# @param dirname [String] directory of source file
|
21
|
-
# @param directives [Array<String>] documents-inline to inject the XML into
|
22
|
-
# the collection manifest; documents-external to keeps them outside
|
23
|
-
# @param bibdata [RelatonBib::BibliographicItem]
|
24
|
-
# @param manifest [Metanorma::CollectionManifest]
|
25
|
-
# @param documents [Hash<String, Metanorma::Document>]
|
26
|
-
# @param prefatory [String]
|
27
|
-
# @param coverpage [String]
|
28
|
-
# @param final [String]
|
29
|
-
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
30
|
-
def initialize(**args)
|
31
|
-
@file = args[:file]
|
32
|
-
@dirname = File.dirname(@file)
|
33
|
-
@directives = args[:directives] || []
|
34
|
-
@bibdata = args[:bibdata]
|
35
|
-
@manifest = args[:manifest]
|
36
|
-
@manifest.collection = self
|
37
|
-
@coverpage = Util::hash_key_detect(@directives, "coverpage", @coverpage)
|
38
|
-
@coverpage_style = Util::hash_key_detect(@directives, "coverpage-style",
|
39
|
-
@coverpage_style)
|
40
|
-
@documents = args[:documents] || {}
|
41
|
-
@bibdatas = args[:documents] || {}
|
42
|
-
if @documents.any? && !@directives.include?("documents-inline")
|
43
|
-
@directives << "documents-inline"
|
44
|
-
end
|
45
|
-
@documents.merge! @manifest.documents(@dirname)
|
46
|
-
@bibdatas.merge! @manifest.documents(@dirname)
|
47
|
-
@documents.transform_keys { |k| Util::key(k) }
|
48
|
-
@bibdatas.transform_keys { |k| Util::key(k) }
|
49
|
-
@prefatory = args[:prefatory]
|
50
|
-
@final = args[:final]
|
51
|
-
@compile = Metanorma::Compile.new
|
52
|
-
@log = Metanorma::Utils::Log.new
|
53
|
-
@disambig = Util::DisambigFiles.new
|
54
|
-
end
|
55
|
-
|
56
|
-
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
|
57
|
-
def clean_exit
|
58
|
-
@log.write(File.join(@dirname,
|
59
|
-
"#{File.basename(@file, '.*')}.err.html"))
|
60
|
-
end
|
61
|
-
|
62
|
-
# @return [String] XML
|
63
|
-
def to_xml
|
64
|
-
b = Nokogiri::XML::Builder.new do |xml|
|
65
|
-
xml.send(:"metanorma-collection",
|
66
|
-
"xmlns" => "http://metanorma.org") do |mc|
|
67
|
-
collection_body(mc)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
b.to_xml
|
71
|
-
end
|
72
|
-
|
73
|
-
def collection_body(coll)
|
74
|
-
coll << @bibdata.to_xml(bibdata: true, date_format: :full)
|
75
|
-
@directives.each do |d|
|
76
|
-
coll << "<directives>#{obj_to_xml(d)}</directives>"
|
77
|
-
end
|
78
|
-
@manifest.to_xml coll
|
79
|
-
content_to_xml "prefatory", coll
|
80
|
-
doccontainer coll
|
81
|
-
content_to_xml "final", coll
|
82
|
-
end
|
83
|
-
|
84
|
-
def obj_to_xml(elem)
|
85
|
-
case elem
|
86
|
-
when ::Array
|
87
|
-
elem.each_with_object([]) do |v, m|
|
88
|
-
m << "<value>#{obj_to_xml(v)}</value>"
|
89
|
-
end.join
|
90
|
-
when ::Hash
|
91
|
-
elem.each_with_object([]) do |(k, v), m|
|
92
|
-
m << "<#{k}>#{obj_to_xml(v)}</#{k}>"
|
93
|
-
end.join
|
94
|
-
else elem end
|
95
|
-
end
|
96
|
-
|
97
|
-
def render(opts)
|
98
|
-
CollectionRenderer.render self, opts.merge(log: @log)
|
99
|
-
clean_exit
|
100
|
-
end
|
101
|
-
|
102
|
-
class << self
|
103
|
-
# @param file [String]
|
104
|
-
# @return [RelatonBib::BibliographicItem,
|
105
|
-
# RelatonIso::IsoBibliographicItem]
|
106
|
-
def parse(file)
|
107
|
-
case file
|
108
|
-
when /\.xml$/ then parse_xml(file)
|
109
|
-
when /.ya?ml$/ then parse_yaml(file)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
|
115
|
-
def parse_xml(file)
|
116
|
-
xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
|
117
|
-
(b = xml.at("/xmlns:metanorma-collection/xmlns:bibdata")) and
|
118
|
-
bd = Relaton::Cli.parse_xml(b)
|
119
|
-
mnf_xml = xml.at("/xmlns:metanorma-collection/xmlns:manifest")
|
120
|
-
mnf = CollectionManifest.from_xml mnf_xml
|
121
|
-
pref = pref_final_content xml.at("//xmlns:prefatory-content")
|
122
|
-
fnl = pref_final_content xml.at("//xmlns:final-content")
|
123
|
-
cov = pref_final_content xml.at("//xmlns:coverpage")
|
124
|
-
new(file: file, bibdata: bd, manifest: mnf,
|
125
|
-
directives: directives_from_xml(xml.xpath("//xmlns:directives")),
|
126
|
-
documents: docs_from_xml(xml, mnf),
|
127
|
-
bibdatas: docs_from_xml(xml, mnf),
|
128
|
-
prefatory: pref, final: fnl, coverpage: cov)
|
129
|
-
end
|
130
|
-
|
131
|
-
# TODO refine
|
132
|
-
def directives_from_xml(dir)
|
133
|
-
dir.each_with_object([]) do |d, m|
|
134
|
-
m << if d.at("./xmlns:value")
|
135
|
-
x.xpath("./xmlns:value").map(&:text)
|
136
|
-
elsif d.at("./*")
|
137
|
-
d.elements.each_with_object({}) do |e, ret|
|
138
|
-
ret[e.name] = e.children.to_xml
|
139
|
-
end
|
140
|
-
else d.children.to_xml
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def parse_yaml(file)
|
146
|
-
yaml = YAML.load_file file
|
147
|
-
if yaml["bibdata"]
|
148
|
-
bd = Relaton::Cli::YAMLConvertor.convert_single_file yaml["bibdata"]
|
149
|
-
end
|
150
|
-
mnf = CollectionManifest.from_yaml yaml["manifest"]
|
151
|
-
dirs = yaml["directives"]
|
152
|
-
pref = yaml["prefatory-content"]
|
153
|
-
fnl = yaml["final-content"]
|
154
|
-
new(file: file, directives: dirs, bibdata: bd, manifest: mnf,
|
155
|
-
prefatory: pref, final: fnl)
|
156
|
-
end
|
157
|
-
|
158
|
-
# @param xml [Nokogiri::XML::Document]
|
159
|
-
# @parma mnf [Metanorma::CollectionManifest]
|
160
|
-
# @return [Hash{String=>Metanorma::Document}]
|
161
|
-
def docs_from_xml(xml, mnf)
|
162
|
-
xml.xpath("//xmlns:doc-container//xmlns:bibdata")
|
163
|
-
.each_with_object({}) do |b, m|
|
164
|
-
bd = Relaton::Cli.parse_xml b
|
165
|
-
docref = mnf.docref_by_id bd.docidentifier.first.id
|
166
|
-
m[docref["identifier"]] = Document.new bd, docref["fileref"]
|
167
|
-
m
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# @param xml [Nokogiri::XML::Element, nil]
|
172
|
-
# @return [String, nil]
|
173
|
-
def pref_final_content(xml)
|
174
|
-
xml or return
|
175
|
-
<<~CONT
|
176
|
-
|
177
|
-
== #{xml.at('title')&.text}
|
178
|
-
#{xml.at('p')&.text}
|
179
|
-
CONT
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
private
|
184
|
-
|
185
|
-
# @return [String, nil]
|
186
|
-
attr_reader :prefatory, :final
|
187
|
-
|
188
|
-
# @return [String]
|
189
|
-
def dummy_header
|
190
|
-
<<~DUMMY
|
191
|
-
= X
|
192
|
-
A
|
193
|
-
|
194
|
-
DUMMY
|
195
|
-
end
|
196
|
-
|
197
|
-
# @param elm [String] 'prefatory' or 'final'
|
198
|
-
# @param builder [Nokogiri::XML::Builder]
|
199
|
-
def content_to_xml(elm, builder)
|
200
|
-
return unless (cnt = send(elm))
|
201
|
-
|
202
|
-
@compile.load_flavor(doctype)
|
203
|
-
out = sections(dummy_header + cnt.strip)
|
204
|
-
builder.send("#{elm}-content") { |b| b << out }
|
205
|
-
end
|
206
|
-
|
207
|
-
# @param cnt [String] prefatory/final content
|
208
|
-
# @return [String] XML
|
209
|
-
def sections(cnt)
|
210
|
-
c = Asciidoctor.convert(cnt, backend: doctype.to_sym, header_footer: true)
|
211
|
-
Nokogiri::XML(c, &:huge).at("//xmlns:sections").children.to_xml
|
212
|
-
end
|
213
|
-
|
214
|
-
# @param builder [Nokogiri::XML::Builder]
|
215
|
-
def doccontainer(builder)
|
216
|
-
Array(@directives).include? "documents-inline" or return
|
217
|
-
documents.each_with_index do |(_, d), i|
|
218
|
-
doccontainer1(builder, d, i)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
def doccontainer1(builder, doc, idx)
|
223
|
-
id = format("doc%<index>09d", index: idx)
|
224
|
-
builder.send(:"doc-container", id: id) do |b|
|
225
|
-
if doc.attachment
|
226
|
-
doc.bibitem and b << doc.bibitem.root.to_xml
|
227
|
-
b.attachment Vectory::Utils::datauri(doc.file)
|
228
|
-
else doc.to_xml b
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
def doctype
|
234
|
-
@doctype ||= fetch_doctype || "standoc"
|
235
|
-
end
|
236
|
-
|
237
|
-
def fetch_doctype
|
238
|
-
docid = @bibdata.docidentifier.first
|
239
|
-
docid or return
|
240
|
-
docid.type&.downcase || docid.id&.sub(/\s.*$/, "")&.downcase
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|