class Metanorma::Ietf::Processor
Public Class Methods
new()
click to toggle source
# File lib/metanorma/ietf/processor.rb, line 11 def initialize # rubocop:disable Lint/MissingSuper @short = :ietf @input_format = :asciidoc @asciidoctor_backend = :ietf end
Public Instance Methods
check_xml2rfc_present?(format)
click to toggle source
# 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)
click to toggle source
# File lib/metanorma/ietf/processor.rb, line 32 def extract_options(_isodocxml) {} end
output(isodoc_node, inname, outname, format, options = {})
click to toggle source
Calls superclass method
# File lib/metanorma/ietf/processor.rb, line 60 def output(isodoc_node, inname, outname, format, 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_formats()
click to toggle source
# 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)
click to toggle source
# File lib/metanorma/ietf/processor.rb, line 49 def use_presentation_xml(_ext) false end
version()
click to toggle source
# File lib/metanorma/ietf/processor.rb, line 28 def version "Metanorma::Ietf #{::Metanorma::Ietf::VERSION}" end
which(cmd)
click to toggle source
From mislav: stackoverflow.com/questions/2108727
/which-in-ruby-checking-if-program-exists-in-path-from-ruby
# 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)
click to toggle source
# File lib/metanorma/ietf/processor.rb, line 73 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