module Docbookrx

Public Class Methods

convert(str, opts = {}) click to toggle source
# File lib/docbookrx.rb, line 30
def self.convert(str, opts = {})
  xmldoc = nil
  Dir.chdir(opts[:cwd] || File.dirname(opts[:infile]||".")) do |path|
    xmldoc = self.read_xml(str, opts)
  end
  raise 'Not a parseable document' unless (root = xmldoc.root)
  visitor = DocbookVisitor.new opts
  xmldoc.accept visitor
  visitor.after
  visitor.lines * "\n"
end
convert_file(infile, opts = {}) click to toggle source
# File lib/docbookrx.rb, line 42
def self.convert_file infile, opts = {}
  outfile = if (ext = ::File.extname infile)
    %(#{infile[0...-ext.length]}.adoc)
  else
    %(#{infile}.adoc)
  end

  str = ::IO.read infile
  output = convert str, opts.merge({:infile => infile})
  ::IO.write outfile, output
  nil
end
read_xml(str, opts = {}) click to toggle source
# File lib/docbookrx.rb, line 8
def self.read_xml(str, opts = {})
  begin
    ::Nokogiri::XML(str) do |config|
      if opts[:strict]
        config.strict.dtdload
      else
        config.default_xml.dtdload
      end
      if opts[:noent]
        config.noent
      end
    end
  rescue Nokogiri::XML::SyntaxError => e
    filename = opts[:infile]
    if filename
      STDERR.puts "** Error - failed to parse #{filename}: #{e}"
    else
      STDERR.puts e
    end
    self
  end
end
root() click to toggle source
# File lib/docbookrx.rb, line 5
def self.root
  nil
end