lib/docbookrx/docbook_visitor.rb
# Very rough first pass at processing xi:include
Very rough first pass at processing xi:include
Very rough first pass at processing xi : include
def visit_include node
    include_infile = node.attr 'href'
    include_outfile = include_infile.sub '.xml', '.adoc'
    if ::File.readable? include_infile
      doc = ::Nokogiri::XML::Document.parse(::File.read include_infile)
      visitor = self.class.new
      doc.root.accept visitor
      result = visitor.lines
      result.shift while result.size > 0 && result.first.empty?
      ::File.open(include_outfile, 'w') {|f| f.write(visitor.lines * EOL) }
    else
      warn %(Include file not readable: #{include_infile})
    end
    append_blank_line
    append_line %(:leveloffset: #{@level - 1}) if @level > 1
    append_line %(include::#{include_outfile}[])
    append_line %(:leveloffset: 0) if @level > 1
    false
  end
def visit_include node include_infile = node . attr 'href' include_outfile = include_infile . sub '.xml' , '.adoc' if :: File . readable? include_infile doc = :: Nokogiri :: XML :: Document . parse ( :: File . read include_infile ) visitor = self . class . new doc . root . accept visitor result = visitor . lines result . shift while result . size > 0 && result . first . empty? :: File . open ( include_outfile , 'w' ) { | f | f . write ( visitor . lines * EOL ) } else warn %(Include file not readable: #{include_infile}) end append_blank_line append_line %(:leveloffset: #{@level - 1}) if @level > 1 append_line %(include::#{include_outfile}[]) append_line %(:leveloffset: 0) if @level > 1 false end
Very rough first pass at processing xi:include
Very rough first pass at processing xi : include
# QUESTION should we reuse this instance to traverse the new tree? # TODO pass in options that were passed to this visitor # TODO make leveloffset more context-aware
node
<not_specific>