Class: Metanorma::Ietf::Processor

Inherits:
Processor
  • Object
show all
Defined in:
lib/metanorma/ietf/processor.rb

Instance Method Summary collapse

Constructor Details

#initializeProcessor

rubocop:disable Lint/MissingSuper



11
12
13
14
15
# File 'lib/metanorma/ietf/processor.rb', line 11

def initialize # rubocop:disable Lint/MissingSuper
  @short = :ietf
  @input_format = :asciidoc
  @asciidoctor_backend = :ietf
end

Instance Method Details

#check_xml2rfc_present?(format) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
# File 'lib/metanorma/ietf/processor.rb', line 53

def check_xml2rfc_present?(format)
  if which("xml2rfc").nil?
    raise "[metanorma-ietf] Fatal: unable to generate #{format}," \
          " the command `xml2rfc` is not found in path."
  end
end

#extract_options(_isodocxml) ⇒ Object



32
33
34
# File 'lib/metanorma/ietf/processor.rb', line 32

def extract_options(_isodocxml)
  {}
end

#output(isodoc_node, inname, outname, format, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/metanorma/ietf/processor.rb', line 60

def output(isodoc_node, inname, outname, format, options = {})
  options_preprocess(options)
  case format
  when :rfc
    outname ||= inname.sub(/\.xml$/, ".rfc.xml")
    RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
    @done_rfc = true
  when :txt, :pdf, :html
    xml2rfc(isodoc_node, inname, outname, format, options)
  else
    super
  end
end

#output_formatsObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/metanorma/ietf/processor.rb', line 17

def output_formats
  {
    rxl: "rxl",
    xml: "xml",
    rfc: "rfc.xml",
    html: "html",
    txt: "txt",
    pdf: "pdf",
  }
end

#use_presentation_xml(_ext) ⇒ Object



49
50
51
# File 'lib/metanorma/ietf/processor.rb', line 49

def use_presentation_xml(_ext)
  false
end

#versionObject



28
29
30
# File 'lib/metanorma/ietf/processor.rb', line 28

def version
  "Metanorma::Ietf #{::Metanorma::Ietf::VERSION}"
end

#which(cmd) ⇒ Object

From mislav: stackoverflow.com/questions/2108727

/which-in-ruby-checking-if-program-exists-in-path-from-ruby


38
39
40
41
42
43
44
45
46
47
# File 'lib/metanorma/ietf/processor.rb', line 38

def which(cmd)
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end

#xml2rfc(isodoc_node, inname, outname, format, options) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/metanorma/ietf/processor.rb', line 74

def xml2rfc(isodoc_node, inname, outname, format, options)
  check_xml2rfc_present?(format)

  rfcname = inname.sub(/\.xml$/, ".rfc.xml")
  unless @done_rfc && File.exist?(rfcname)
    output(isodoc_node, inname, rfcname, :rfc, options)
  end

  outext = { txt: ".txt", pdf: ".pdf", html: ".html" }[format]
  outflag = { txt: "--text", pdf: "--pdf", html: "--html" }[format]

  outname ||= inname.sub(/\.xml$/, outext)
  system("xml2rfc", outflag, rfcname, "-o", outname)
end