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.
- #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_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
29 30 31 |
# File 'lib/metanorma/ietf/processor.rb', line 29 def (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, ={}) case format when :rfc outname ||= inname.sub(/\.xml$/, ".rfc.xml") IsoDoc::Ietf::RfcConvert.new().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, ) 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_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 |
#use_presentation_xml(ext) ⇒ Object
46 47 48 |
# File 'lib/metanorma/ietf/processor.rb', line 46 def use_presentation_xml(ext) false 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
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
50 51 52 |
# File 'lib/metanorma/ietf/processor.rb', line 50 def xml2rfc_present? !which("xml2rfc").nil? end |