class Metanorma::FontistUtils

Public Class Methods

fontist_font_locations(processor, options) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 96
def self.fontist_font_locations(processor, options)
  if missing_fontist_manifest?(processor) || options[:no_install_fonts]
    return nil
  end

  dump_fontist_manifest_locations(processor.fonts_manifest)
rescue Fontist::Errors::FormulaIndexNotFoundError
  raise unless options[:continue_without_fonts]

  nil
end
install_fonts(processor, options) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 81
def self.install_fonts(processor, options)
  return unless validate_install_fonts(processor, options)

  @@updated_formulas_repo = false
  manifest = processor.fonts_manifest
  agree_to_terms, can_without_fonts, no_progress = validate_options(options)

  install_fonts_safe(
    manifest,
    agree_to_terms,
    can_without_fonts,
    no_progress
  )
end

Private Class Methods

dump_fontist_manifest_locations(manifest) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 66
def dump_fontist_manifest_locations(manifest)
  location_manifest = Fontist::Manifest::Locations.from_hash(
    manifest
  )
  location_manifest_file = Tempfile.new(["fontist_locations", ".yml"])
  location_manifest_file.write location_manifest.to_yaml
  location_manifest_file.flush
  location_manifest_file
end
fontist_install(manifest, agree, no_progress) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 58
def fontist_install(manifest, agree, no_progress)
  Fontist::Manifest::Install.from_hash(
    manifest,
    confirmation: agree ? "yes" : "no",
    no_progress: no_progress
  )
end
install_fonts_safe(manifest, agree, continue, no_progress) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 27
def install_fonts_safe(manifest, agree, continue, no_progress)
  fontist_install(manifest, agree, no_progress)
rescue Fontist::Errors::LicensingError
  if continue
    Util.log(
      "[fontist] Processing will continue without fonts installed",
      :debug
    )
  else
    Util.log("[fontist] Aborting without proper fonts installed," \
             " make sure that you have set option --agree-to-terms",
             :fatal)
  end
rescue Fontist::Errors::FontError => e
  log_level = continue ? :warning : :fatal
  Util.log("[fontist] '#{e.font}' font is not supported. " \
           "Please report this issue at github.com/metanorma/metanorma" \
           "/issues to report this issue.", log_level)
rescue Fontist::Errors::FormulaIndexNotFoundError
  if @@updated_formulas_repo
    Util.log(
      "[fontist] Bug: formula index not found after 'fontist update'",
      :fatal
    )
  end
  Util.log("[fontist] Missing formula index. Fetching it...", :debug)
  Fontist::Formula.update_formulas_repo
  @@updated_formulas_repo = true
  install_fonts_safe(manifest, agree, continue, no_progress)
end
missing_fontist_manifest?(processor) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 76
def missing_fontist_manifest?(processor)
  !processor.respond_to?(:fonts_manifest) || processor.fonts_manifest.nil?
end
validate_install_fonts(processor, options) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 14
def validate_install_fonts(processor, options)
  if options[:no_install_fonts]
    Util.log("[fontist] Skip font installation because" \
             " --no-install-fonts argument passed", :debug)
    return false
  elsif missing_fontist_manifest?(processor)
    Util.log("[fontist] Skip font installation because "\
             "font_manifest is missing", :debug)
    return false
  end
  true
end
validate_options(options) click to toggle source
# File lib/metanorma/fontist_utils.rb, line 6
def validate_options(options)
  agree_to_terms = options[:agree_to_terms] || false
  continue_without_fonts = options[:continue_without_fonts] || false
  no_progress = options[:no_progress] || false

  [agree_to_terms, continue_without_fonts, no_progress]
end