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



46
47
48
49
50
51
52
53
54
# File 'lib/metanorma/compile/compile_options.rb', line 46

def extract_dir_options(options, options_in_file, filename)
  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_extensions(options) ⇒ Object



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

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



39
40
41
42
43
44
# File 'lib/metanorma/compile/compile_options.rb', line 39

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
31
# 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)
  options[:extension_keys] ||= o[:extensions]&.split(/, */)&.map(&:to_sym)
  options[:extension_keys] = nil if options[:extension_keys] == [:all]
  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



78
79
80
81
82
# File 'lib/metanorma/compile/compile_options.rb', line 78

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

#get_extensions(options) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/metanorma/compile/compile_options.rb', line 56

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



33
34
35
36
37
# File 'lib/metanorma/compile/compile_options.rb', line 33

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