Module: Metanorma::Compile::CompileOptions

Included in:
Metanorma::Compile
Defined in:
lib/metanorma/compile/compile_options.rb

Instance Method Summary collapse

Instance Method Details

#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 extract_dir_options(options, options_in_file, filename)
  filename.is_a?(Tempfile) and return
  dir = filename.sub(%r(/[^/]+$), "/")
  options_in_file[:relaton] and
    options[:relaton] ||= File.join(dir,
                                    options_in_file[:relaton])
  options_in_file[:sourcecode] and
    options[:sourcecode] ||= File.join(dir,
                                       options_in_file[: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 extract_extension_options(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



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/metanorma/compile/compile_options.rb', line 75

def extract_extensions(options)
  options[:extension_keys] ||=
    @processor.output_formats.reduce([]) { |memo, (k, _)| memo << k }
  options[:extension_keys].reduce([]) do |memo, e|
    if @processor.output_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 extract_flavor_options(options, options_in_file)
  options[:type] ||= options_in_file[:type]
  options[:type] = options[:type]&.to_sym
  options[:supplied_type] = options[:type]
  t = @registry.alias(options[:type]) and options[: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 extract_options(filename, options)
  o = options_in_file(filename)
  extract_flavor_options(options, o)
  extract_dir_options(options, o, filename)
  extract_extension_options(options, o)
  options[:format] ||= :asciidoc
  options[:filename] = filename
  options[:fontlicenseagreement] ||= "no-install-fonts"
  options[:novalid] = o[:novalid] if o[:novalid]
  options
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 extract_xml_options(file)
  xml = Nokogiri::XML(file, &:huge)
  if xml.root
    @registry.root_tags.each do |k, v|
      return { type: k } if v == xml.root.name
    end
  end
  {}
end

#font_install(opt) ⇒ Object



87
88
89
90
91
# File 'lib/metanorma/compile/compile_options.rb', line 87

def font_install(opt)
  @fontist_installed or
    Util::FontistHelper.install_fonts(@processor, opt)
  @fontist_installed = true
end

#get_extensions(options) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/metanorma/compile/compile_options.rb', line 65

def get_extensions(options)
  ext = extract_extensions(options)
  !ext.include?(:presentation) && ext.any? do |e|
    @processor.use_presentation_xml(e)
  end and ext << :presentation
  !ext.include?(:rxl) && options[: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 options_in_file(filename)
  content = read_file(filename)
  Metanorma::Input::Asciidoc.new.extract_metanorma_options(content)
    .merge(extract_xml_options(content))
end

#require_libraries(options) ⇒ Object



6
7
8
# File 'lib/metanorma/compile/compile_options.rb', line 6

def require_libraries(options)
  options&.dig(:require)&.each { |r| require r }
end