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
TODO: we’re not yet using IsoDoc here.
-
#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.
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 = :rfc2 end |
Instance Method Details
#extract_options(isodocxml) ⇒ Object
TODO: we’re not yet using IsoDoc here
37 38 39 |
# File 'lib/metanorma/ietf/processor.rb', line 37 def (isodocxml) {} end |
#input_to_isodoc(file, filename) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/metanorma/ietf/processor.rb', line 27 def input_to_isodoc(file, filename) # TODO: storing these two variables for xmlrfc2. Remove when we have IsoDoc @file = file @filename = 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
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 |
# File 'lib/metanorma/ietf/processor.rb', line 54 def output(isodoc_node, outname, format, ={}) case format when :xmlrfc2 # TODO: we're using XML RFC v2 as the central format because our processor # is not updated to the new schema # xmlrfcdoc = Metanorma::Input::Asciidoc.new.process(@file, @filename, :rfc2) # File.open(outname, 'w') { |f| f << xmlrfcdoc } # TODO: When we have IsoDoc, we just translate IsoDoc to XML RFC v2 File.open(outname, 'w') { |f| f << isodoc_node } when :xmlrfc3 # TODO: When we have IsoDoc, we just translate IsoDoc to XML RFC v3 xmlrfcdoc = Metanorma::Input::Asciidoc.new.process(@file, @filename, :rfc3) File.open(outname, 'w') { |f| f << xmlrfcdoc } when :txt, :html Tempfile.open(outname) do |f| f << isodoc_node unless which("xml2rfc") warn "[metanorma-ietf] Error: unable to generate #{format}, the command `xml2rfc` is not found in path." return end # In xml2rfc, --text and --html are used format = :text if format == :txt # puts "xml2rfc --#{format} #{f.path} -o #{outname}" system("xml2rfc --#{format} #{f.path} -o #{outname}") end end end |
#output_formats ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/metanorma/ietf/processor.rb', line 14 def output_formats { xmlrfc2: "xml", xmlrfc3: "v3.xml", html: "html", txt: "txt" } end |
#version ⇒ Object
23 24 25 |
# File 'lib/metanorma/ietf/processor.rb', line 23 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
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/metanorma/ietf/processor.rb', line 43 def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) } end nil end |