Class: OptparseLite::AppTag

Inherits:
NanDoc::Filters::CustomTag
  • Object
show all
Includes:
NanDoc::SpecDoc::Playback::Terminal::ColorToHtml, NanDoc::StringMethods
Defined in:
lib/optparse-lite/test/nandoc-custom-tags/app.rb,
lib/optparse-lite/test/nandoc-custom-tags/app.rb

Defined Under Namespace

Classes: TagParser

Constant Summary collapse

ColorizeRuby =
::Syntax::Convertors::HTML.for_syntax('ruby')

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/app.rb', line 10

def =~ whole_file
  /\(see: test[^ ]*\.rb - app - ["']/ =~ whole_file
end

Instance Method Details

#nameObject



14
15
16
# File 'lib/optparse-lite/test/nandoc-custom-tags/app.rb', line 14

def name
  'optparse lite custom tag - app'
end

#run(content) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/optparse-lite/test/nandoc-custom-tags/app.rb', line 17

def run content
  numetal = content.gsub(
    /\(see: (test[^ ]*\.rb) - app - ["']([^"']+)["'](.*)\)/
  ) do
    show_app_code($1, $2, $3)
  end
end

#show_app_code(testfile, label, rest) ⇒ Object



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/app.rb', line 27

def show_app_code testfile, label, rest
  opts = parse_rest_assert(rest)
  NanDoc::Project.instance.require_test_file testfile
  recs = NanDoc::SpecDoc::Recordings.get_for_key(:generic)
  scn = NanDoc::SpecDoc::Playback::SexpScanner.new(recs)
  scn.skip_to_after_assert :story, label
  aa = scn.offset
  scn.skip_to_after_assert :story_stop
  bb = scn.offset - 2
  these = scn.sexp[aa..bb]
  meth = NanDoc::SpecDoc::Playback::Method.new
  doc = NanDoc::Html::Tags.new
  html_opts = opts[:epilogue] ? {} : opts # hack
  doc.push_smart 'pre', 'ruby', '', html_opts
  # the below is written inline in the tests, because we can
  # if opts[:prologue]
  #   code = "#!/usr/bin/env ruby\n\n"
  #   doc.push_smart('pre','ruby', code) # no colorize!
  # end
  meth.run_sexp doc, these
  if opts[:epilogue]
    # scan back
    j = scn.offset - 1
    j -=1 while scn.sexp[j] && scn.sexp[j][0] != :optparse_app_module
    if ! scn.sexp[j]
      fail("primus sucks")
    end
    mod = scn.sexp[j][1]
    use_mod = module_basename(mod)
    ruby = "\n#{use_mod}.run"
    doc.content.push "<br />"<<ColorizeRuby.convert(ruby, false)
  end
  html = doc.to_html
  html
end

#tag_parserObject



24
25
26
# File 'lib/optparse-lite/test/nandoc-custom-tags/app.rb', line 24

def tag_parser
  TagParser.new
end