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



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

def extract_options(isodocxml)
  {}
end

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



54
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
# File 'lib/metanorma/ietf/processor.rb', line 54

def output(isodoc_node, inname, outname, format, options={})
  case format
  when :rfc
    outname ||= inname.sub(/\.xml$/, ".rfc.xml")
    IsoDoc::Ietf::RfcConvert.new(options).convert(inname, isodoc_node, nil, outname)
    @done_rfc = true

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

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

    outext = case format
      when :txt then ".txt"
      when :pdf then ".pdf"
      when :html then ".html"
    end

    outflag = case format
      when :txt then "--text"
      when :pdf then "--pdf"
      when :html then "--html"
    end

    outname ||= inname.sub(/\.xml$/, outext)
    system("xml2rfc #{outflag} #{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

#use_presentation_xml(ext) ⇒ Object



46
47
48
# File 'lib/metanorma/ietf/processor.rb', line 46

def use_presentation_xml(ext)
  false
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


35
36
37
38
39
40
41
42
43
44
# File 'lib/metanorma/ietf/processor.rb', line 35

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)


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

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