metanorma 2.1.4 → 2.2.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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/lib/metanorma/collection/collection.rb +10 -4
  4. data/lib/metanorma/collection/config/config.rb +21 -0
  5. data/lib/metanorma/collection/config/manifest.rb +4 -1
  6. data/lib/metanorma/collection/document/document.rb +2 -0
  7. data/lib/metanorma/collection/filelookup/filelookup.rb +15 -6
  8. data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +4 -3
  9. data/lib/metanorma/collection/manifest/manifest.rb +7 -11
  10. data/lib/metanorma/collection/renderer/fileparse.rb +12 -39
  11. data/lib/metanorma/collection/renderer/fileprocess.rb +26 -10
  12. data/lib/metanorma/collection/renderer/navigation.rb +1 -1
  13. data/lib/metanorma/collection/renderer/renderer.rb +14 -1
  14. data/lib/metanorma/collection/renderer/utils.rb +8 -10
  15. data/lib/metanorma/collection/sectionsplit/collection.rb +1 -0
  16. data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +84 -49
  17. data/lib/metanorma/collection/util/util.rb +24 -11
  18. data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +2 -3
  19. data/lib/metanorma/compile/assets/icc-boilerplate.adoc +41 -0
  20. data/lib/metanorma/compile/compile.rb +148 -172
  21. data/lib/metanorma/compile/compile_options.rb +108 -82
  22. data/lib/metanorma/compile/extract.rb +76 -56
  23. data/lib/metanorma/compile/flavor.rb +54 -0
  24. data/lib/metanorma/compile/output_filename.rb +75 -0
  25. data/lib/metanorma/compile/output_filename_config.rb +27 -0
  26. data/lib/metanorma/compile/relaton_drop.rb +56 -0
  27. data/lib/metanorma/compile/render.rb +178 -0
  28. data/lib/metanorma/compile/validator.rb +26 -0
  29. data/lib/metanorma/compile/writeable.rb +12 -0
  30. data/lib/metanorma/input/asciidoc.rb +13 -6
  31. data/lib/metanorma/registry/registry.rb +11 -8
  32. data/lib/metanorma/version.rb +1 -1
  33. data/metanorma.gemspec +2 -1
  34. metadata +24 -3
  35. data/lib/metanorma/compile/compile_validate.rb +0 -68
@@ -1,21 +1,38 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
  require "nokogiri"
3
5
  require "htmlentities"
4
6
  require "yaml"
5
7
  require "fontist"
6
8
  require "fontist/manifest/install"
7
- require_relative "compile_validate"
9
+ require "metanorma-taste"
10
+ require_relative "writeable"
11
+ require_relative "validator"
8
12
  require_relative "compile_options"
9
13
  require_relative "../util/fontist_helper"
10
14
  require_relative "../util/util"
11
15
  require_relative "extract"
12
16
  require_relative "../collection/sectionsplit/sectionsplit"
13
17
  require_relative "../util/worker_pool"
18
+ require_relative "output_filename"
19
+ require_relative "output_filename_config"
20
+ require_relative "flavor"
21
+ require_relative "relaton_drop"
22
+ require_relative "render"
14
23
 
15
24
  module Metanorma
16
25
  class Compile
26
+ include Validator
27
+ include CompileOptions
28
+ include Flavor
29
+ include Writeable
30
+
31
+ DEFAULT_NUM_WORKERS = 3
32
+
17
33
  # @return [Array<String>]
18
- attr_reader :errors, :processor
34
+ attr_reader :errors
35
+ attr_reader :processor
19
36
 
20
37
  def initialize
21
38
  @registry = Metanorma::Registry.instance
@@ -25,22 +42,48 @@ module Metanorma
25
42
  @log = Metanorma::Utils::Log.new
26
43
  end
27
44
 
45
+ # Main compile method that orchestrates the document conversion process
46
+ # @param filename [String] path to the input file
47
+ # @param options [Hash] compilation options
28
48
  def compile(filename, options = {})
29
- options_process(filename, options)
49
+ process_options!(filename, options)
30
50
  @processor = @registry.find_processor(options[:type].to_sym)
31
- (file, isodoc = process_input(filename, options)) or return nil
32
- extensions = get_extensions(options) or return nil
33
- relaton_export(isodoc, options)
34
- extract(isodoc, options[:extract], options[:extract_type])
35
- process_exts(filename, extensions, file, isodoc, options)
51
+
52
+ # Step 1: Generate Semantic XML
53
+ semantic_result = generate_semantic_xml(filename, options)
54
+ return nil unless semantic_result
55
+
56
+ source_file, semantic_xml = semantic_result
57
+
58
+ # Step 2: Prepare output paths
59
+ xml = Nokogiri::XML(semantic_xml, &:huge)
60
+ bibdata = extract_relaton_metadata(xml)
61
+ output_paths = prepare_output_paths(filename, bibdata, options)
62
+
63
+ # Step 3: Determine which output formats to generate
64
+ extensions = get_extensions(options)
65
+ return nil unless extensions
66
+
67
+ # Step 4: Extract information from Semantic XML if requested
68
+ extract_information(semantic_xml, bibdata, options)
69
+
70
+ # Step 5: Generate output formats from Semantic XML
71
+ generate_outputs(
72
+ source_file,
73
+ semantic_xml,
74
+ bibdata,
75
+ extensions,
76
+ output_paths,
77
+ options,
78
+ )
36
79
  ensure
37
80
  clean_exit(options)
38
81
  end
39
82
 
40
- def options_process(filename, options)
83
+ def process_options!(filename, options)
41
84
  require_libraries(options)
42
- options = options_extract(filename, options)
43
- validate_options(options)
85
+ options = extract_options(filename, options)
86
+ validate_options!(options)
44
87
  @log.save_to(filename, options[:output_dir])
45
88
  options[:log] = @log
46
89
  end
@@ -50,7 +93,11 @@ module Metanorma
50
93
  @log.write
51
94
  end
52
95
 
53
- def process_input(filename, options)
96
+ # Step 1: Generate Semantic XML from input file
97
+ # @param filename [String] input file path
98
+ # @param options [Hash] compilation options
99
+ # @return [Array, nil] tuple of [source_file, semantic_xml] or nil on failure
100
+ def generate_semantic_xml(filename, options)
54
101
  case extname = File.extname(filename)
55
102
  when ".adoc" then process_input_adoc(filename, options)
56
103
  when ".xml" then process_input_xml(filename, options)
@@ -61,184 +108,113 @@ module Metanorma
61
108
  end
62
109
  end
63
110
 
64
- def process_input_adoc(filename, options)
65
- Util.log("[metanorma] Processing: AsciiDoc input.", :info)
66
- file = read_file(filename)
67
- options[:asciimath] and
68
- file.sub!(/^(=[^\n]+\n)/, "\\1:mn-keep-asciimath:\n")
69
- dir = File.dirname(filename)
70
- dir != "." and
71
- file = file.gsub(/^include::/, "include::#{dir}/")
72
- .gsub(/^embed::/, "embed::#{dir}/")
73
- [file, @processor.input_to_isodoc(file, filename, options)]
74
- end
75
-
76
- def process_input_xml(filename, _options)
77
- Util.log("[metanorma] Processing: Metanorma XML input.", :info)
78
- # TODO NN: this is a hack -- we should provide/bridge the
79
- # document attributes in Metanorma XML
80
- ["", read_file(filename)]
81
- end
82
-
83
- def read_file(filename)
84
- File.read(filename, encoding: "utf-8").gsub("\r\n", "\n")
85
- end
86
-
87
- def relaton_export(isodoc, options)
88
- return unless options[:relaton]
89
-
90
- xml = Nokogiri::XML(isodoc, &:huge)
91
- bibdata = xml.at("//bibdata") || xml.at("//xmlns:bibdata")
92
- # docid = bibdata&.at("./xmlns:docidentifier")&.text || options[:filename]
93
- # outname = docid.sub(/^\s+/, "").sub(/\s+$/, "").gsub(/\s+/, "-") + ".xml"
94
- File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
95
- end
96
-
97
- def export_output(fname, content, **options)
98
- mode = options[:binary] ? "wb" : "w:UTF-8"
99
- File.open(fname, mode) { |f| f.write content }
100
- end
101
-
102
- def wrap_html(options, file_extension, outfilename)
103
- if options[:wrapper] && /html$/.match(file_extension)
104
- outfilename = outfilename.sub(/\.html$/, "")
105
- FileUtils.mkdir_p outfilename
106
- FileUtils.mv "#{outfilename}.html", outfilename
107
- FileUtils.mv "#{outfilename}_images", outfilename, force: true
111
+ # Step 2: Prepare output paths for generated files
112
+ # Use default filename template if empty string is provided.
113
+ #
114
+ # @param filename [String] input file path
115
+ # @param bibdata [Nokogiri::XML::Element] the bibliographic data element
116
+ # @param options [Hash] compilation options
117
+ # @return [Hash] paths for different output formats
118
+ def prepare_output_paths(filename, bibdata, options)
119
+ basename = if options[:filename_template].nil?
120
+ filename.sub(/\.[^.]+$/, "")
121
+ else
122
+ drop = RelatonDrop.new(bibdata)
123
+ config = OutputFilenameConfig.new(options[:filename_template])
124
+ config.generate_filename(drop)
125
+ end
126
+ @output_filename = OutputFilename.new(
127
+ basename,
128
+ options[:output_dir],
129
+ @processor,
130
+ )
131
+ {
132
+ xml: @output_filename.semantic_xml,
133
+ orig_filename: filename,
134
+ presentationxml: @output_filename.presentation_xml,
135
+ }
136
+ end
137
+
138
+ # Step 4: Extract information from Semantic XML
139
+ # @param semantic_xml [String] semantic XML content
140
+ # @param options [Hash] compilation options
141
+ def extract_information(semantic_xml, bibdata, options)
142
+ # Extract Relaton bibliographic data
143
+ export_relaton_from_bibdata(bibdata, options) if options[:relaton]
144
+
145
+ # Extract other components (sourcecode, images, requirements)
146
+ if options[:extract]
147
+ Extract.extract(
148
+ semantic_xml,
149
+ options[:extract],
150
+ options[:extract_type],
151
+ )
108
152
  end
109
153
  end
110
154
 
111
- # isodoc is Raw Metanorma XML
112
- def process_exts(filename, extensions, file, isodoc, options)
113
- f = File.expand_path(change_output_dir(options))
114
- fnames = { xml: f.sub(/\.[^.]+$/, ".xml"), f: f,
115
- orig_filename: File.expand_path(filename),
116
- presentationxml: f.sub(/\.[^.]+$/, ".presentation.xml") }
155
+ # Step 5: Generate output formats from Semantic XML
156
+ # @param source_file [String] source file content
157
+ # @param semantic_xml [String] semantic XML content
158
+ # @param bibdata [Nokogiri::XML::Element] the bibliographic data element
159
+ # @param extensions [Array<Symbol>] output formats to generate
160
+ # @param output_paths [Hash] paths for output files
161
+ # @param options [Hash] compilation options
162
+ def generate_outputs(
163
+ source_file, semantic_xml, bibdata, extensions, output_paths, options
164
+ )
117
165
  if extensions == %i(presentation)
118
- process_ext(:presentation, file, isodoc, fnames, options)
166
+ # Just generate presentation XML
167
+ generate_presentation_xml(
168
+ source_file, semantic_xml, bibdata, output_paths, options
169
+ )
119
170
  else
120
- process_exts_queue(fnames, extensions, file, isodoc, options)
171
+ # Generate multiple output formats with parallel processing
172
+ generate_outputs_parallel(
173
+ source_file, semantic_xml, bibdata, extensions, output_paths, options
174
+ )
121
175
  end
122
176
  end
123
177
 
124
- def process_exts_queue(fnames, extensions, file, isodoc, options)
125
- @queue = ::Metanorma::Util::WorkersPool
126
- .new(ENV["METANORMA_PARALLEL"]&.to_i || 3)
127
- gather_and_install_fonts(file, options.dup, extensions)
128
- process_exts_run(fnames, file, isodoc, extensions, options)
129
- @queue.shutdown
178
+ def process_input_adoc_hdr(file, options)
179
+ hdr, rest = Metanorma::Input::Asciidoc.new.header(file)
180
+ attrs = hdr.split("\n")
181
+ options[:asciimath] and attrs << ":mn-keep-asciimath:"
182
+ process_input_adoc_overrides(attrs, options)
183
+ "#{attrs.join("\n")}\n\n#{rest}"
130
184
  end
131
185
 
132
- def process_exts_run(fnames, file, isodoc, extensions, options)
133
- Util.sort_extensions_execution(extensions).each do |ext|
134
- process_ext(ext, file, isodoc, fnames, options) or break
135
- end
186
+ def process_input_adoc_overrides(attrs, options)
187
+ @registry.tastes.available_tastes.include?(options[:supplied_type]) or
188
+ return
189
+ c = Metanorma::TasteRegister.get(options[:supplied_type])
190
+ c.process_input_adoc_overrides(attrs, options)
136
191
  end
137
192
 
138
- def gather_and_install_fonts(file, options, extensions)
139
- Util.sort_extensions_execution(extensions).each do |ext|
140
- isodoc_options = get_isodoc_options(file, options, ext)
141
- font_install(isodoc_options.merge(options))
142
- end
143
- end
144
-
145
- def process_ext(ext, file, isodoc, fnames, options)
146
- fnames[:ext] = @processor.output_formats[ext]
147
- fnames[:out] = fnames[:f].sub(/\.[^.]+$/, ".#{fnames[:ext]}")
148
- isodoc_options = get_isodoc_options(file, options, ext)
149
- thread = true
150
- unless process_ext_simple(ext, isodoc, fnames, options,
151
- isodoc_options)
152
- thread = process_exts1(ext, fnames, isodoc, options, isodoc_options)
153
- end
154
- thread
155
- end
156
-
157
- def process_ext_simple(ext, isodoc, fnames, options, isodoc_options)
158
- if ext == :rxl
159
- relaton_export(isodoc, options.merge(relaton: fnames[:out]))
160
- elsif options[:passthrough_presentation_xml] && ext == :presentation
161
- #f = File.exist?(fnames[:f]) ? fnames[:f] : fnames[:orig_filename]
162
- f = File.exist?(fnames[:orig_filename]) ? fnames[:orig_filename] : fnames[:f]
163
- FileUtils.cp f, fnames[:presentationxml]
164
- elsif ext == :html && options[:sectionsplit]
165
- sectionsplit_convert(fnames[:xml], isodoc, fnames[:out],
166
- isodoc_options)
167
- else return false
168
- end
169
- true
170
- end
171
-
172
- def process_exts1(ext, fnames, isodoc, options, isodoc_options)
173
- if @processor.use_presentation_xml(ext)
174
- @queue.schedule(ext, fnames.dup, options.dup,
175
- isodoc_options.dup) do |a, b, c, d|
176
- process_output_threaded(a, b, c, d)
177
- end
178
- else
179
- process_output_unthreaded(ext, fnames, isodoc, isodoc_options)
180
- end
181
- end
182
-
183
- def process_output_threaded(ext, fnames1, options1, isodoc_options1)
184
- @processor.output(nil, fnames1[:presentationxml], fnames1[:out], ext,
185
- isodoc_options1)
186
- wrap_html(options1, fnames1[:ext], fnames1[:out])
187
- rescue StandardError => e
188
- strict = ext == :presentation || isodoc_options1[:strict] == true
189
- isodoc_error_process(e, strict, false)
190
- end
191
-
192
- def process_output_unthreaded(ext, fnames, isodoc, isodoc_options)
193
- @processor.output(isodoc, fnames[:xml], fnames[:out], ext,
194
- isodoc_options)
195
- true # return as Thread
196
- rescue StandardError => e
197
- strict = ext == :presentation || isodoc_options[:strict] == "true"
198
- isodoc_error_process(e, strict, true)
199
- ext != :presentation
193
+ def process_input_adoc_includes(file, filename)
194
+ dir = File.dirname(filename)
195
+ dir != "." and
196
+ file = file.gsub(/^include::/, "include::#{dir}/")
197
+ .gsub(/^embed::/, "embed::#{dir}/")
198
+ file
200
199
  end
201
200
 
202
- # assume we pass in Presentation XML, but we want to recover Semantic XML
203
- def sectionsplit_convert(input_filename, file, output_filename = nil,
204
- opts = {})
205
- @isodoc ||= IsoDoc::PresentationXMLConvert.new({})
206
- input_filename += ".xml" unless input_filename.match?(/\.xml$/)
207
- File.exist?(input_filename) or
208
- File.open(input_filename, "w:UTF-8") { |f| f.write(file) }
209
- presxml = File.read(input_filename, encoding: "utf-8")
210
- _xml, filename, dir = @isodoc.convert_init(presxml, input_filename, false)
211
-
212
- ::Metanorma::Collection::Sectionsplit.new(
213
- input: input_filename,
214
- isodoc: @isodoc,
215
- xml: presxml,
216
- base: File.basename(output_filename || filename),
217
- output: output_filename || filename,
218
- dir: dir,
219
- compile_opts: opts,
220
- ).build_collection
201
+ def process_input_adoc(filename, options)
202
+ Util.log("[metanorma] Processing: AsciiDoc input.", :info)
203
+ file = read_file(filename)
204
+ file = process_input_adoc_hdr(file, options)
205
+ file = process_input_adoc_includes(file, filename)
206
+ [file, @processor.input_to_isodoc(file, filename, options)]
221
207
  end
222
208
 
223
- private
224
-
225
- def isodoc_error_process(err, strict, must_abort)
226
- if strict || err.message.include?("Fatal:")
227
- @errors << err.message
228
- else
229
- puts err.message
230
- end
231
- puts err.backtrace.join("\n")
232
- must_abort and 1
209
+ def process_input_xml(filename, _options)
210
+ Util.log("[metanorma] Processing: Metanorma XML input.", :info)
211
+ # TODO NN: this is a hack -- we should provide/bridge the
212
+ # document attributes in Metanorma XML
213
+ ["", read_file(filename)]
233
214
  end
234
215
 
235
- # @param options [Hash]
236
- # @return [String]
237
- def change_output_dir(options)
238
- if options[:output_dir]
239
- File.join options[:output_dir], File.basename(options[:filename])
240
- else options[:filename]
241
- end
216
+ def read_file(filename)
217
+ File.read(filename, encoding: "utf-8").gsub("\r\n", "\n")
242
218
  end
243
219
  end
244
220
  end
@@ -2,104 +2,130 @@ require "csv"
2
2
 
3
3
  module Metanorma
4
4
  class Compile
5
- def require_libraries(options)
6
- options&.dig(:require)&.each { |r| require r }
7
- end
5
+ module CompileOptions
6
+ def require_libraries(options)
7
+ options&.dig(:require)&.each { |r| require r }
8
+ end
8
9
 
9
- def xml_options_extract(file)
10
- xml = Nokogiri::XML(file, &:huge)
11
- if xml.root
12
- @registry.root_tags.each do |k, v|
13
- return { type: k } if v == xml.root.name
10
+ def extract_xml_options(file)
11
+ xml = Nokogiri::XML(file, &:huge)
12
+ if xml.root
13
+ @registry.root_tags.each do |k, v|
14
+ return { type: k } if v == xml.root.name
15
+ end
14
16
  end
17
+ {}
15
18
  end
16
- {}
17
- end
18
19
 
19
- def options_extract(filename, options)
20
- content = read_file(filename)
21
- o = Metanorma::Input::Asciidoc.new.extract_metanorma_options(content)
22
- .merge(xml_options_extract(content))
23
- options[:type] ||= o[:type]&.to_sym
24
- t = @registry.alias(options[:type]) and options[:type] = t
25
- dir = filename.sub(%r(/[^/]+$), "/")
26
- options[:relaton] ||= File.join(dir, o[:relaton]) if o[:relaton]
27
- options[:sourcecode] ||= File.join(dir, o[:sourcecode]) if o[:sourcecode]
28
- options[:extension_keys] ||= o[:extensions]&.split(/, */)&.map(&:to_sym)
29
- options[:extension_keys] = nil if options[:extension_keys] == [:all]
30
- options[:format] ||= :asciidoc
31
- options[:filename] = filename
32
- options[:fontlicenseagreement] ||= "no-install-fonts"
33
- options[:novalid] = o[:novalid] if o[:novalid]
34
- options
35
- end
20
+ def extract_options(filename, options)
21
+ o = options_in_file(filename)
22
+ extract_flavor_options(options, o)
23
+ extract_dir_options(options, o, filename)
24
+ options[:extension_keys] ||= o[:extensions]&.split(/, */)&.map(&:to_sym)
25
+ options[:extension_keys] = nil if options[:extension_keys] == [:all]
26
+ options[:format] ||= :asciidoc
27
+ options[:filename] = filename
28
+ options[:fontlicenseagreement] ||= "no-install-fonts"
29
+ options[:novalid] = o[:novalid] if o[:novalid]
30
+ options
31
+ end
36
32
 
37
- def get_extensions(options)
38
- ext = extract_extensions(options)
39
- !ext.include?(:presentation) && ext.any? do |e|
40
- @processor.use_presentation_xml(e)
41
- end and ext << :presentation
42
- !ext.include?(:rxl) && options[:site_generate] and
43
- ext << :rxl
44
- ext
45
- end
33
+ def options_in_file(filename)
34
+ content = read_file(filename)
35
+ Metanorma::Input::Asciidoc.new.extract_metanorma_options(content)
36
+ .merge(extract_xml_options(content))
37
+ end
38
+
39
+ def extract_flavor_options(options, options_in_file)
40
+ options[:type] ||= options_in_file[:type]
41
+ options[:type] = options[:type]&.to_sym
42
+ options[:supplied_type] = options[:type]
43
+ t = @registry.alias(options[:type]) and options[:type] = t
44
+ end
45
+
46
+ def extract_dir_options(options, options_in_file, filename)
47
+ dir = filename.sub(%r(/[^/]+$), "/")
48
+ options_in_file[:relaton] and
49
+ options[:relaton] ||= File.join(dir,
50
+ options_in_file[:relaton])
51
+ options_in_file[:sourcecode] and
52
+ options[:sourcecode] ||= File.join(dir,
53
+ options_in_file[:sourcecode])
54
+ end
55
+
56
+ def get_extensions(options)
57
+ ext = extract_extensions(options)
58
+ !ext.include?(:presentation) && ext.any? do |e|
59
+ @processor.use_presentation_xml(e)
60
+ end and ext << :presentation
61
+ !ext.include?(:rxl) && options[:site_generate] and
62
+ ext << :rxl
63
+ ext
64
+ end
46
65
 
47
- def extract_extensions(options)
48
- options[:extension_keys] ||=
49
- @processor.output_formats.reduce([]) { |memo, (k, _)| memo << k }
50
- options[:extension_keys].reduce([]) do |memo, e|
51
- if @processor.output_formats[e] then memo << e
52
- else
53
- unsupported_format_error(e)
54
- memo
66
+ def extract_extensions(options)
67
+ options[:extension_keys] ||=
68
+ @processor.output_formats.reduce([]) { |memo, (k, _)| memo << k }
69
+ options[:extension_keys].reduce([]) do |memo, e|
70
+ if @processor.output_formats[e] then memo << e
71
+ else
72
+ unsupported_format_error(e)
73
+ memo
74
+ end
55
75
  end
56
76
  end
57
- end
58
77
 
59
- def font_install(opt)
60
- @fontist_installed or
61
- Util::FontistHelper.install_fonts(@processor, opt)
62
- @fontist_installed = true
63
- end
78
+ def font_install(opt)
79
+ @fontist_installed or
80
+ Util::FontistHelper.install_fonts(@processor, opt)
81
+ @fontist_installed = true
82
+ end
64
83
 
65
- private
84
+ private
66
85
 
67
- def unsupported_format_error(ext)
68
- message = "[metanorma] Error: #{ext} format is not supported " \
69
- "for this standard."
70
- @errors << message
71
- Util.log(message, :error)
72
- end
86
+ def unsupported_format_error(ext)
87
+ message = "[metanorma] Error: #{ext} format is not supported " \
88
+ "for this standard."
89
+ @errors << message
90
+ Util.log(message, :error)
91
+ end
92
+
93
+ def get_isodoc_options(file, options, ext)
94
+ ret = @processor.extract_options(file)
95
+ get_isodoc_i18nyaml(options, ret)
96
+ copy_isodoc_options_attrs(options, ret)
97
+ font_manifest_mn2pdf(options, ret, ext)
98
+ ret[:output_formats]&.select! do |k, _|
99
+ options[:extension_keys].include?(k)
100
+ end
101
+ ret[:log] = @log
102
+ ret
103
+ end
73
104
 
74
- def get_isodoc_options(file, options, ext)
75
- ret = @processor.extract_options(file)
76
- dir = options[:filename].sub(%r(/[^/]+$), "/")
77
- ret[:i18nyaml] &&= File.join(dir, ret[:i18nyaml])
78
- copy_isodoc_options_attrs(options, ret)
79
- font_manifest_mn2pdf(options, ret, ext)
80
- ret[:output_formats]&.select! do |k, _|
81
- options[:extension_keys].include?(k)
105
+ def get_isodoc_i18nyaml(options, ret)
106
+ dir = File.dirname(options[:filename])
107
+ ret[:i18nyaml] or return
108
+ (Pathname.new ret[:i18nyaml]).absolute? or
109
+ ret[:i18nyaml] = File.join(dir, ret[:i18nyaml])
82
110
  end
83
- ret[:log] = @log
84
- ret
85
- end
86
111
 
87
- def copy_isodoc_options_attrs(options, ret)
88
- ret[:datauriimage] = true if options[:datauriimage]
89
- ret[:sourcefilename] = options[:filename]
90
- %i(bare sectionsplit install_fonts baseassetpath aligncrosselements
91
- tocfigures toctables tocrecommendations strict)
92
- .each { |x| ret[x] ||= options[x] }
93
- end
112
+ def copy_isodoc_options_attrs(options, ret)
113
+ ret[:datauriimage] = true if options[:datauriimage]
114
+ ret[:sourcefilename] = options[:filename]
115
+ %i(bare sectionsplit install_fonts baseassetpath aligncrosselements
116
+ tocfigures toctables tocrecommendations strict)
117
+ .each { |x| ret[x] ||= options[x] }
118
+ end
94
119
 
95
- def font_manifest_mn2pdf(options, ret, ext)
96
- custom_fonts = Util::FontistHelper
97
- .has_custom_fonts?(@processor, options, ret)
120
+ def font_manifest_mn2pdf(options, ret, ext)
121
+ custom_fonts = Util::FontistHelper
122
+ .has_custom_fonts?(@processor, options, ret)
98
123
 
99
- ext == :pdf && custom_fonts and
100
- ret[:mn2pdf] = {
101
- font_manifest: Util::FontistHelper.location_manifest(@processor, ret),
102
- }
124
+ ext == :pdf && custom_fonts and
125
+ ret[:mn2pdf] = {
126
+ font_manifest: Util::FontistHelper.location_manifest(@processor, ret),
127
+ }
128
+ end
103
129
  end
104
130
  end
105
131
  end