Class: RDoc::Parser::Tdoc
- Inherits:
-
Simple
- Object
- Simple
- RDoc::Parser::Tdoc
- Defined in:
- lib/rdoc/parsers/tdoc.rb
Constant Summary collapse
- LINST =
'^[#|\s]*'
- LINSTM =
'[#|\s]*'
- EXTENSIONS =
{:tests => '.rdoc',:requires => '.rb'}
Instance Method Summary collapse
-
#initialize(top_level, file_name, content, options, stats) ⇒ Tdoc
constructor
A new instance of Tdoc.
- #process_includes(file_name) ⇒ Object
Constructor Details
#initialize(top_level, file_name, content, options, stats) ⇒ Tdoc
Returns a new instance of Tdoc.
6 7 8 9 |
# File 'lib/rdoc/parsers/tdoc.rb', line 6 def initialize(top_level, file_name, content, , stats) super @content=process_includes(file_name) end |
Instance Method Details
#process_includes(file_name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rdoc/parsers/tdoc.rb', line 10 def process_includes(file_name) content=File.read(file_name) test_name=File.basename(file_name,'.rdoc') test_dir=File.dirname(file_name) content.gsub!(/(#{LINST}):include:\s*(.+)/) do |foo| indent=$1 fn=$2 if fn.match(/#{EXTENSIONS[:requires]}/) "\nThe following examples require the file '#{fn}', whose contents follow:\n#{process_includes(fn).gsub(/^/,indent + ' ')}\n" else process_includes(fn).gsub(/^/,indent) end end content.sub!(/(#{LINST})setup\s+(.*?)#{LINSTM}end\s+/m) {|foo| indent=$1 "The following code: \n#{$2.gsub(/^/,indent+' ')}\nprecedes each of the following examples.\n\n" } Dir.glob("#{test_dir}/#{test_name}.rb").each do |fn| tests=content.split(/#{LINST}[Ee]xamples?:/,2) content="#{tests[0]}\nThe following examples require the file '#{fn}', whose contents follow:\n#{process_includes(fn).gsub(/^/,' ')}\nExamples: #{tests[1]}" end Dir.glob("#{test_dir}/#{test_name}/*.rdoc").each do |fn| content+="\n#{process_includes(fn)}\n" end content end |