Class: OptparseLite::PlaybackTag
- Inherits:
-
NanDoc::Filters::CustomTag
- Object
- NanDoc::Filters::CustomTag
- OptparseLite::PlaybackTag
- Includes:
- NanDoc::SpecDoc::Playback::Terminal::ColorToHtml, NanDoc::StringMethods, Nanoc3::Helpers::HTMLEscape
- Defined in:
- lib/optparse-lite/test/nandoc-custom-tags/playback.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.=~(whole_file) ⇒ Object
10 11 12 |
# File 'lib/optparse-lite/test/nandoc-custom-tags/playback.rb', line 10 def =~ whole_file /\(see: test[^ ]*\.rb - playback - ["']/ =~ whole_file end |
Instance Method Details
#name ⇒ Object
14 15 16 |
# File 'lib/optparse-lite/test/nandoc-custom-tags/playback.rb', line 14 def name 'optparse lite custom tag - playback' end |
#run(content) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/optparse-lite/test/nandoc-custom-tags/playback.rb', line 17 def run content = content.gsub( /\(see: (test[^ ]*\.rb) - playback - ["']([^"']+)["'](?: - (.+))?\)/ ) do html = show_playback($1, $2, $3) html end end |
#show_playback(testfile, testname, xtra) ⇒ Object
26 27 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 55 56 57 58 59 60 61 |
# File 'lib/optparse-lite/test/nandoc-custom-tags/playback.rb', line 26 def show_playback testfile, testname, xtra opts = if xtra JSON.parse(xtra) or fail("failed to parse json: #{xtra}") else {} end proj = NanDoc::Project.instance proxy = proj.test_framework_proxy_for_file(testfile) sexp = proxy.sexp_get testfile, testname scn = NanDoc::SpecDoc::Playback::SexpScanner.new(sexp) scn.scan_assert(:method) doc = NanDoc::Html::Tags.new while true do app = scn.scan_assert(:app)[1] name = app.spec.invocation_name argv = scn.scan_assert(:argv)[1] # command = "./#{name} #{argv.shelljoin}" # shelljoin is ugly and dumb command = "./#{name} #{myshelljoin(argv)}" out = scn.scan_assert(:out)[1] cmd_html = prompt_highlight2('~ > ', command) doc.push_smart("pre", 'terminal', cmd_html, opts) opts.clear colored = terminal_color_to_html(out) || html_escape(out) doc.content.push colored if scn.current && scn.current.first == :app doc.content.push "\n\n" # stay -- rare tests that do multiple commands else break end end html = doc.to_html html end |