Class: Asciidoctor::DocTest::IO::Asciidoc
- Defined in:
- lib/asciidoctor/doctest/io/asciidoc.rb
Overview
Subclass of Base for reference input examples.
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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/asciidoctor/doctest/io/asciidoc.rb', line 27 def parse(input, group_name) examples = [] current = create_example(nil) input.each_line do |line| case line.chomp! when %r{^//\s*\.([^ \n]+)} local_name = $1 current.content.chomp! examples << (current = create_example([group_name, local_name])) when %r{^//\s*:([^:]+):(.*)} current[$1.to_sym] = $2.blank? ? true : $2.strip when %r{^//\s*(.*)\s*$} (current.desc ||= '').concat!($1, "\n") else current.content.concat!(line, "\n") end end examples end |
#serialize(examples) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/asciidoctor/doctest/io/asciidoc.rb', line 49 def serialize(examples) Array(examples).map { |exmpl| Array.new.push(".#{exmpl.local_name}") .push(*exmpl.desc.lines.map(&:chomp)) .push(*(exmpl.opts)) .map { |s| '// ' + s } .push(exmpl.content.presence) .compact .join("\n") .concat("\n") }.join("\n") end |