Class: Asciidoctor::DocTest::IO::XML
- Defined in:
- lib/asciidoctor/doctest/io/xml.rb
Overview
Subclass of Base for XML-based backends.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#group_names, #initialize, #pair_with, #read_examples, #update_examples, #write_examples
Constructor Details
This class inherits a constructor from Asciidoctor::DocTest::IO::Base
Instance Method Details
#parse(input, group_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/asciidoctor/doctest/io/xml.rb', line 28 def parse(input, group_name) examples = [] current = create_example(nil) in_comment = false input.each_line do |line| line.chomp! if line =~ /^<!--\s*\.([^ \n]+)/ name = $1 current.content.chomp! examples << (current = create_example([group_name, name])) in_comment = true elsif in_comment if line =~ /^\s*:([^:]+):(.*)/ current[$1.to_sym] = $2.blank? ? true : $2.strip else desc = line.rstrip.chomp('-->').strip (current.desc ||= '').concat!(desc, "\n") unless desc.empty? end else current.content.concat!(line, "\n") end in_comment &= !line.end_with?('-->') end examples end |
#serialize(examples) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/asciidoctor/doctest/io/xml.rb', line 56 def serialize(examples) Array(examples).map { |exmpl| header = [ ".#{exmpl.local_name}", exmpl.desc.presence, *(exmpl.opts) ].compact header_str = header.one? ? (header.first + ' ') : (header.join("\n") + "\n") [ "<!-- #{header_str}-->", exmpl.content.presence ].compact.join("\n") + "\n" }.join("\n") end |