Class: Metanorma::Ietf::Processor

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

Instance Method Summary collapse

Constructor Details

#initializeProcessor

Returns a new instance of Processor.



8
9
10
11
12
# File 'lib/metanorma/ietf/processor.rb', line 8

def initialize
  @short = :ietf
  @input_format = :asciidoc
  @asciidoctor_backend = :ietf
end

Instance Method Details

#extract_options(isodocxml) ⇒ Object



34
35
36
# File 'lib/metanorma/ietf/processor.rb', line 34

def extract_options(isodocxml)
  {}
end

#input_to_isodoc(file, filename) ⇒ Object



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

def input_to_isodoc(file, filename)
  # This is XML RFC v3 output in text
  Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
end

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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/metanorma/ietf/processor.rb', line 55

def output(isodoc_node, outname, format, options={})
  case format
  when :rfc
    IsoDoc::Ietf::RfcConvert.new(options).convert(outname, isodoc_node)
    @done_rfc = true

  when :txt
    unless xml2rfc_present?
      warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
      return
    end

    rfcname = outname.sub(/\.txt$/, ".rfc.xml")
    output(isodoc_node, outname, :rfc, options) unless @done_rfc

    system("xml2rfc --text #{rfcname} -o #{outname}")

  when :pdf
    unless xml2rfc_present?
      warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
      return
    end

    rfcname = outname.sub(/\.pdf$/, ".rfc.xml")
    output(isodoc_node, outname, :rfc, options) unless @done_rfc

    system("xml2rfc --pdf #{rfcname} -o #{outname}")

  when :html
    unless xml2rfc_present?
      warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path."
      return
    end

    rfcname = outname.sub(/\.html$/, ".rfc.xml")
    output(isodoc_node, outname, :rfc, options) unless @done_rfc

    system("xml2rfc --html #{rfcname} -o #{outname}")

  else
    super
  end
end

#output_formatsObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/metanorma/ietf/processor.rb', line 14

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

#versionObject



25
26
27
# File 'lib/metanorma/ietf/processor.rb', line 25

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


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

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_present?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/metanorma/ietf/processor.rb', line 51

def xml2rfc_present?
  !which("xml2rfc").nil?
end