metanorma 2.0.0 → 2.1.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metanorma/collection/collection.rb +43 -14
  3. data/lib/metanorma/collection/config/bibdata.rb +2 -2
  4. data/lib/metanorma/collection/config/compile_options.rb +4 -5
  5. data/lib/metanorma/collection/config/config.rb +41 -73
  6. data/lib/metanorma/collection/config/converters.rb +27 -1
  7. data/lib/metanorma/collection/config/directive.rb +9 -3
  8. data/lib/metanorma/collection/config/manifest.rb +33 -27
  9. data/lib/metanorma/collection/document/document.rb +12 -10
  10. data/lib/metanorma/collection/filelookup/filelookup.rb +25 -13
  11. data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +57 -20
  12. data/lib/metanorma/collection/manifest/manifest.rb +22 -10
  13. data/lib/metanorma/collection/multilingual/multilingual.rb +660 -0
  14. data/lib/metanorma/collection/renderer/fileparse.rb +119 -104
  15. data/lib/metanorma/collection/renderer/fileprocess.rb +6 -2
  16. data/lib/metanorma/collection/renderer/navigation.rb +1 -1
  17. data/lib/metanorma/collection/renderer/render_word.rb +8 -7
  18. data/lib/metanorma/collection/renderer/renderer.rb +41 -20
  19. data/lib/metanorma/collection/renderer/svg.rb +52 -0
  20. data/lib/metanorma/collection/renderer/utils.rb +55 -18
  21. data/lib/metanorma/collection/sectionsplit/collection.rb +100 -0
  22. data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +104 -101
  23. data/lib/metanorma/collection/util/util.rb +25 -10
  24. data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +42 -28
  25. data/lib/metanorma/compile/compile.rb +12 -2
  26. data/lib/metanorma/compile/compile_options.rb +2 -0
  27. data/lib/metanorma/compile/compile_validate.rb +4 -4
  28. data/lib/metanorma/compile/extract.rb +2 -4
  29. data/lib/metanorma/input/asciidoc.rb +11 -30
  30. data/lib/metanorma/registry/registry.rb +2 -2
  31. data/lib/metanorma/version.rb +1 -1
  32. data/metanorma.gemspec +5 -4
  33. metadata +41 -25
  34. data/lib/metanorma/shale_monkeypatch.rb +0 -15
@@ -1,4 +1,5 @@
1
1
  require_relative "../sectionsplit/sectionsplit"
2
+ # require "concurrent-ruby"
2
3
 
3
4
  module Metanorma
4
5
  class Collection
@@ -16,11 +17,25 @@ module Metanorma
16
17
 
17
18
  def process_section_split_instance(key, manifest)
18
19
  s, sectionsplit_manifest = sectionsplit(key)
20
+ # section_split_instance_threads(s, manifest, key)
19
21
  s.each_with_index do |f1, i|
20
22
  add_section_split_instance(f1, manifest, key, i)
21
23
  end
22
- manifest["#{key}:index.html"] =
23
- add_section_split_cover(sectionsplit_manifest, key)
24
+ a = add_section_split_attachments(sectionsplit_manifest, key) and
25
+ manifest["#{key}:attachments"] = a
26
+ add_section_split_cover(manifest, sectionsplit_manifest, key)
27
+ end
28
+
29
+ def section_split_instance_threads(s, manifest, key)
30
+ @mutex = Mutex.new
31
+ pool = Concurrent::FixedThreadPool.new(4)
32
+ s.each_with_index do |f1, i|
33
+ pool.post do
34
+ add_section_split_instance(f1, manifest, key, i)
35
+ end
36
+ end
37
+ pool.shutdown
38
+ pool.wait_for_termination
24
39
  end
25
40
 
26
41
  def cleanup_section_split_instance(key, manifest)
@@ -29,37 +44,57 @@ module Metanorma
29
44
  @files[key][:indirect_key] = @sectionsplit.key
30
45
  end
31
46
 
32
- def add_section_split_cover(manifest, ident)
47
+ def add_section_split_cover(manifest, sectionsplit_manifest, ident)
33
48
  cover = @sectionsplit
34
- .section_split_cover(manifest, @parent.dir_name_cleanse(ident),
49
+ .section_split_cover(sectionsplit_manifest,
50
+ @parent.dir_name_cleanse(ident),
35
51
  one_doc_collection?)
36
52
  @files[ident][:out_path] = cover
37
- { attachment: true, index: false, out_path: cover,
38
- ref: File.join(File.dirname(manifest.file), cover) }
53
+ src = File.join(File.dirname(sectionsplit_manifest.file), cover)
54
+ m = { attachment: true, index: false, out_path: cover, ref: src }
55
+ manifest["#{ident}:index.html"] = m
56
+ one_doc_collection? and
57
+ add_cover_one_doc_coll(manifest, sectionsplit_manifest, ident, m)
58
+ end
59
+
60
+ def add_cover_one_doc_coll(manifest, sectionsplit_manifest, key, entry)
61
+ idx = File.join(File.dirname(sectionsplit_manifest.file), "index.html")
62
+ FileUtils.cp entry[:ref], idx
63
+ manifest["#{key}:index1.html"] =
64
+ entry.merge(out_path: "index.html", ref: idx)
39
65
  end
40
66
 
41
67
  def one_doc_collection?
42
- return false
43
68
  docs = 0
44
69
  @files.each_value do |v|
45
70
  v[:attachment] and next
46
71
  v[:presentationxml] and next
47
72
  docs += 1
48
73
  end
49
- docs > 1
74
+ docs <= 1
75
+ end
76
+
77
+ def add_section_split_attachments(manifest, ident)
78
+ attachments = @sectionsplit
79
+ .section_split_attachments(out: File.dirname(manifest.file))
80
+ attachments or return
81
+ @files[ident][:out_path] = attachments
82
+ { attachment: true, index: false, out_path: attachments,
83
+ ref: File.join(File.dirname(manifest.file), attachments) }
50
84
  end
51
85
 
52
86
  def add_section_split_instance(file, manifest, key, idx)
53
- presfile, newkey, xml =
54
- add_section_split_instance_prep(file, key)
55
- manifest[newkey] =
56
- { parentid: key, presentationxml: true, type: "fileref",
57
- rel_path: file[:url], out_path: File.basename(file[:url]),
58
- anchors: read_anchors(xml), ids: read_ids(xml),
59
- sectionsplit_output: true,
60
- bibdata: @files[key][:bibdata], ref: presfile }
87
+ presfile, newkey, xml = add_section_split_instance_prep(file, key)
88
+ anchors = read_anchors(xml)
89
+ m = { parentid: key, presentationxml: true, type: "fileref",
90
+ rel_path: file[:url], out_path: File.basename(file[:url]),
91
+ anchors: anchors, anchors_lookup: anchors_lookup(anchors),
92
+ ids: read_ids(xml),
93
+ sectionsplit_output: true, indirect_key: @sectionsplit.key,
94
+ bibdata: @files[key][:bibdata], ref: presfile }
95
+ m[:bare] = true unless idx.zero?
96
+ manifest[newkey] = m
61
97
  @files_to_delete << file[:url]
62
- manifest[newkey][:bare] = true unless idx.zero?
63
98
  end
64
99
 
65
100
  def add_section_split_instance_prep(file, key)
@@ -73,9 +108,11 @@ module Metanorma
73
108
  def sectionsplit(ident)
74
109
  file = @files[ident][:ref]
75
110
  @sectionsplit = ::Metanorma::Collection::Sectionsplit
76
- .new(input: file, base: @files[ident][:out_path], dir: File.dirname(file),
77
- output: @files[ident][:out_path], compile_opts: @parent.compile_options,
78
- fileslookup: self, ident: ident, isodoc: @isodoc)
111
+ .new(input: file, base: @files[ident][:out_path],
112
+ dir: File.dirname(file), output: @files[ident][:out_path],
113
+ compile_opts: @parent.compile_options,
114
+ fileslookup: self, ident: ident, isodoc: @isodoc,
115
+ document_suffix: @files[ident][:document_suffix])
79
116
  coll = @sectionsplit.sectionsplit.sort_by { |f| f[:order] }
80
117
  xml = Nokogiri::XML(File.read(file, encoding: "UTF-8"), &:huge)
81
118
  [coll, @sectionsplit
@@ -6,7 +6,7 @@ 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]
@@ -14,6 +14,7 @@ module Metanorma
14
14
  # @param docref [Array<Hash{String=>String}>]
15
15
  # @param manifest [Array<Metanorma::Collection::Manifest>]
16
16
  def initialize(config, collection, dir)
17
+ #require "debug"; binding.b
17
18
  @collection = collection
18
19
  @dir = dir
19
20
  @disambig = ::Metanorma::Collection::Util::DisambigFiles.new
@@ -21,6 +22,7 @@ module Metanorma
21
22
  end
22
23
 
23
24
  def manifest_postprocess(config)
25
+ #require "debug"; binding.b
24
26
  manifest_bibdata(config)
25
27
  manifest_expand_yaml(config, @dir)
26
28
  manifest_compile_adoc(config)
@@ -67,15 +69,15 @@ module Metanorma
67
69
  i = x.at("//xmlns:bibdata/xmlns:docidentifier[@primary = 'true']") ||
68
70
  x.at("//xmlns:bibdata/xmlns:docidentifier")
69
71
  i or return nil
70
- @doctype ||= i["type"]&.downcase || "standoc"
72
+ @flavor = @collection.flavor
71
73
  load_isodoc
72
74
  Util::key(@isodoc.docid_prefix(i["type"], i.text))
73
75
  end
74
76
 
75
77
  def load_isodoc
76
78
  @isodoc and return
77
- @collection.compile.load_flavor(@doctype)
78
- @isodoc = Util::load_isodoc(@doctype)
79
+ @collection.compile.load_flavor(@flavor)
80
+ @isodoc = Util::load_isodoc(@flavor)
79
81
  @isodoc.i18n_init(@lang, @script, nil) # for @i18n.all_parts in docid
80
82
  end
81
83
 
@@ -94,6 +96,7 @@ module Metanorma
94
96
 
95
97
  def manifest_filexist(config)
96
98
  if config.file
99
+ #require "debug"; binding.b
97
100
  file = @collection.class.resolve_fileref(@dir, config.file)
98
101
  @collection.class.check_file_existence(file)
99
102
  config.file = Pathname.new(file).relative_path_from(Pathname.new(@dir))
@@ -108,6 +111,7 @@ module Metanorma
108
111
  currdir = dir
109
112
  /\.ya?ml$/.match?(e.file) and
110
113
  currdir = manifest_expand_yaml_entry(e, dir)
114
+ #require "debug"; binding.b
111
115
  manifest_expand_yaml(e, currdir)
112
116
  end
113
117
  config
@@ -118,8 +122,10 @@ module Metanorma
118
122
  currdir = File.dirname(f)
119
123
  @collection.class.check_file_existence(f)
120
124
  entry.file = nil
125
+ #require 'debug'; binding.b
121
126
  entry.entry = ::Metanorma::Collection::Config::Config.from_yaml(File.read(f)).manifest
122
127
  if currdir != dir
128
+ #require "debug"; binding.b
123
129
  prefix = Pathname.new(currdir).relative_path_from(Pathname.new(dir))
124
130
  update_filepaths(entry.entry, prefix.to_s)
125
131
  end
@@ -127,6 +133,7 @@ module Metanorma
127
133
  end
128
134
 
129
135
  def update_filepaths(entry, prefix)
136
+ #require "debug"; binding.b
130
137
  entry.file && !(Pathname.new entry.file).absolute? and
131
138
  entry.file = File.join(prefix, entry.file)
132
139
  entry.entry.each do |f|
@@ -153,7 +160,7 @@ module Metanorma
153
160
  def set_adoc2xml(fileref)
154
161
  File.join(
155
162
  File.dirname(fileref),
156
- File.basename(fileref).gsub(/.adoc$/, ".xml"),
163
+ File.basename(fileref).gsub(/\.adoc$/, ".xml"),
157
164
  )
158
165
  end
159
166
 
@@ -161,17 +168,22 @@ module Metanorma
161
168
  # @raise [AdocFileNotFoundException]
162
169
  def compile_adoc_file(file)
163
170
  f = (Pathname.new file).absolute? ? file : File.join(@dir, file)
164
- unless File.exist? f
165
- raise AdocFileNotFoundException.new "#{f} not found!"
166
- end
167
-
171
+ File.exist?(f) or raise AdocFileNotFoundException.new "#{f} not found!"
172
+ compile_adoc_file?(file) or return
168
173
  ::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...", :info)
169
174
  ::Metanorma::Compile.new
170
- .compile(f, agree_to_terms: true, no_install_fonts: true,
175
+ .compile(f, agree_to_terms: true, install_fonts: false,
171
176
  extension_keys: [:xml])
172
177
  ::Metanorma::Util.log("[metanorma] Info: Compiling #{f}...done!", :info)
173
178
  end
174
179
 
180
+ def compile_adoc_file?(file)
181
+ @collection.directives.detect do |d|
182
+ d.key == "recompile-xml"
183
+ end and return true
184
+ !File.exist?(file.sub(/\.adoc$/, ".xml"))
185
+ end
186
+
175
187
  def documents(mnf = @config)
176
188
  Array(mnf.entry).each_with_object({}) do |dr, m|
177
189
  if dr.file