Class: Metanorma::Ietf::Processor
- Inherits:
-
Processor
- Object
- Processor
- Metanorma::Ietf::Processor
- Defined in:
- lib/metanorma/ietf/processor.rb
Instance Method Summary collapse
- #check_xml2rfc_present?(format) ⇒ Boolean
- #extract_options(_isodocxml) ⇒ Object
-
#initialize ⇒ Processor
constructor
rubocop:disable Lint/MissingSuper.
- #output(isodoc_node, inname, outname, format, options = {}) ⇒ Object
- #output_formats ⇒ Object
- #use_presentation_xml(_ext) ⇒ Object
- #version ⇒ Object
-
#which(cmd) ⇒ Object
From mislav: stackoverflow.com/questions/2108727 /which-in-ruby-checking-if-program-exists-in-path-from-ruby.
- #xml2rfc(isodoc_node, inname, outname, format, options) ⇒ Object
Constructor Details
#initialize ⇒ Processor
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
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 (_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, = {}) () case format when :rfc outname ||= inname.sub(/\.xml$/, ".rfc.xml") RfcConvert.new().convert(inname, isodoc_node, nil, outname) @done_rfc = true when :txt, :pdf, :html xml2rfc(isodoc_node, inname, outname, format, ) else super end end |
#output_formats ⇒ Object
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 |
#version ⇒ Object
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, ) check_xml2rfc_present?(format) rfcname = inname.sub(/\.xml$/, ".rfc.xml") unless @done_rfc && File.exist?(rfcname) output(isodoc_node, inname, rfcname, :rfc, ) 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 |