Class: Metanorma::Ietf::Processor
- Inherits:
-
Processor
- Object
- Processor
- Metanorma::Ietf::Processor
- Defined in:
- lib/metanorma/ietf/processor.rb
Instance Method Summary collapse
- #extract_options(isodocxml) ⇒ Object
-
#initialize ⇒ Processor
constructor
A new instance of Processor.
- #input_to_isodoc(file, filename) ⇒ Object
- #output(isodoc_node, outname, format, options = {}) ⇒ Object
- #output_formats ⇒ Object
- #version ⇒ Object
-
#which(cmd) ⇒ Object
From mislav: stackoverflow.com/questions/2108727 /which-in-ruby-checking-if-program-exists-in-path-from-ruby.
- #xml2rfc_present? ⇒ Boolean
Constructor Details
#initialize ⇒ Processor
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 (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, ={}) case format when :rfc IsoDoc::Ietf::RfcConvert.new().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, ) 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, ) 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, ) unless @done_rfc system("xml2rfc --html #{rfcname} -o #{outname}") else super end end |
#output_formats ⇒ Object
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 |
#version ⇒ Object
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
51 52 53 |
# File 'lib/metanorma/ietf/processor.rb', line 51 def xml2rfc_present? !which("xml2rfc").nil? end |