Module: Metanorma::Compile::CompileOptions
- Included in:
- Metanorma::Compile
- Defined in:
- lib/metanorma/compile/compile_options.rb
Instance Method Summary collapse
-
#effective_output_formats(options) ⇒ Object
The processor's output formats merged with the suffixes of any taste-contributed document-model formats, so those formats pass extension validation and get an output suffix.
- #extract_dir_options(options, options_in_file, filename) ⇒ Object
- #extract_extension_options(opt, doc_opt) ⇒ Object
- #extract_extensions(options) ⇒ Object
- #extract_flavor_options(options, options_in_file) ⇒ Object
- #extract_options(filename, options) ⇒ Object
- #extract_xml_options(file) ⇒ Object
- #font_install(opt) ⇒ Object
- #get_extensions(options) ⇒ Object
- #options_in_file(filename) ⇒ Object
- #require_libraries(options) ⇒ Object
-
#taste_transformers(options) ⇒ Object
Document-model transformer specs contributed by the active taste (+options+), or
{}. -
#uses_presentation_xml?(ext, options) ⇒ Boolean
Whether
extis generated from presentation XML, honouring both the processor's own answer and a taste transformer's:presentationflag.
Instance Method Details
#effective_output_formats(options) ⇒ Object
The processor's output formats merged with the suffixes of any taste-contributed document-model formats, so those formats pass extension validation and get an output suffix.
80 81 82 83 84 85 |
# File 'lib/metanorma/compile/compile_options.rb', line 80 def effective_output_formats() @processor.output_formats.merge( taste_transformers() .transform_values { |spec| spec[:suffix] }.compact, ) end |
#extract_dir_options(options, options_in_file, filename) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metanorma/compile/compile_options.rb', line 54 def (, , filename) filename.is_a?(Tempfile) and return dir = filename.sub(%r(/[^/]+$), "/") [:relaton] and [:relaton] ||= File.join(dir, [:relaton]) [:sourcecode] and [:sourcecode] ||= File.join(dir, [:sourcecode]) end |
#extract_extension_options(opt, doc_opt) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/metanorma/compile/compile_options.rb', line 32 def (opt, doc_opt) opt[:extension_keys] == [:all] and opt[:extension_keys] = [] ext = opt[:extension_keys] || [] doc_opt[:extensions] == "all" and doc_opt[:extensions] = "" ext1 = (doc_opt[:extensions] || "").split(/, */).map(&:to_sym) !ext1.empty? && ext.empty? and opt[:extension_keys] = ext1 opt[:extension_keys]&.empty? and opt[:extension_keys] = nil end |
#extract_extensions(options) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/metanorma/compile/compile_options.rb', line 104 def extract_extensions() formats = effective_output_formats() [:extension_keys] ||= formats.reduce([]) { |memo, (k, _)| memo << k } [:extension_keys].reduce([]) do |memo, e| if formats[e] then memo << e else unsupported_format_error(e) memo end end end |
#extract_flavor_options(options, options_in_file) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/metanorma/compile/compile_options.rb', line 47 def (, ) [:type] ||= [:type] [:type] = [:type]&.to_sym [:supplied_type] = [:type] t = @registry.alias([:type]) and [:type] = t end |
#extract_options(filename, options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/metanorma/compile/compile_options.rb', line 20 def (filename, ) o = (filename) (, o) (, o, filename) (, o) [:format] ||= :asciidoc [:filename] = filename [:fontlicenseagreement] ||= "no-install-fonts" [:novalid] = o[:novalid] if o[:novalid] end |
#extract_xml_options(file) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/metanorma/compile/compile_options.rb', line 10 def (file) xml = Nokogiri::XML(file, &:huge) if xml.root @registry..each do |k, v| return { type: k } if v == xml.root.name end end {} end |
#font_install(opt) ⇒ Object
117 118 119 120 121 |
# File 'lib/metanorma/compile/compile_options.rb', line 117 def font_install(opt) @fontist_installed or Util::FontistHelper.install_fonts(@processor, opt) @fontist_installed = true end |
#get_extensions(options) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/metanorma/compile/compile_options.rb', line 94 def get_extensions() ext = extract_extensions() !ext.include?(:presentation) && ext.any? do |e| uses_presentation_xml?(e, ) end and ext << :presentation !ext.include?(:rxl) && [:site_generate] and ext << :rxl ext end |
#options_in_file(filename) ⇒ Object
41 42 43 44 45 |
# File 'lib/metanorma/compile/compile_options.rb', line 41 def (filename) content = read_file(filename) Metanorma::Input::Asciidoc.new.(content) .merge((content)) end |
#require_libraries(options) ⇒ Object
6 7 8 |
# File 'lib/metanorma/compile/compile_options.rb', line 6 def require_libraries() &.dig(:require)&.each { |r| require r } end |
#taste_transformers(options) ⇒ Object
Document-model transformer specs contributed by the active taste
(+options+), or {}. Lets a taste (e.g. OIML) make its
own output format selectable and choose its presentation/semantic leg,
via the taste-aware metanorma-core Processor (metanorma-core#12).
69 70 71 72 73 74 75 |
# File 'lib/metanorma/compile/compile_options.rb', line 69 def taste_transformers() taste = [:supplied_type] return {} unless taste && defined?(Metanorma::TasteRegister) && Metanorma::TasteRegister.respond_to?(:document_transformers_for) Metanorma::TasteRegister.document_transformers_for(taste) || {} end |
#uses_presentation_xml?(ext, options) ⇒ Boolean
Whether ext is generated from presentation XML, honouring both the
processor's own answer and a taste transformer's :presentation flag.
89 90 91 92 |
# File 'lib/metanorma/compile/compile_options.rb', line 89 def uses_presentation_xml?(ext, ) @processor.use_presentation_xml(ext) || (taste_transformers()[ext] || {})[:presentation] == true end |