nandoc 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/README +5 -4
  2. data/Rakefile +1 -1
  3. data/bin/nandoc +2 -1
  4. data/doc/FAQ.md +3 -0
  5. data/doc/PROVISO.md +39 -0
  6. data/doc/commands/diff.md +49 -0
  7. data/doc/svg/less-fonts.svg +2 -2
  8. data/lib/nandoc/cli/README.md +6 -0
  9. data/lib/nandoc/cli/command-methods.rb +38 -0
  10. data/lib/nandoc/cli/option-methods/exclusive-options.rb +56 -0
  11. data/lib/nandoc/cli/option-methods/option-enum.rb +64 -0
  12. data/lib/nandoc/cli/option-methods.rb +35 -0
  13. data/lib/nandoc/cli.rb +3 -0
  14. data/lib/nandoc/commands/create-nandoc-site.rb +9 -12
  15. data/lib/nandoc/commands/diff.rb +14 -11
  16. data/lib/nandoc/commands.rb +9 -0
  17. data/lib/nandoc/{config.rb → core/config.rb} +18 -9
  18. data/lib/nandoc/core/project.rb +50 -0
  19. data/lib/nandoc/doc/hack-free-zone-defined.md +33 -0
  20. data/lib/nandoc/erb/agent.rb +5 -5
  21. data/lib/nandoc/{test/minitest-extlib.rb → extlib/minitest.rb} +1 -1
  22. data/lib/nandoc/filters/builtin-tags/fence/terminal.rb +24 -0
  23. data/lib/nandoc/filters/builtin-tags/fence-dispatcher.rb +43 -0
  24. data/lib/nandoc/filters/builtin-tags/fences.rb +4 -0
  25. data/lib/nandoc/filters/builtin-tags/see-test.rb +67 -0
  26. data/lib/nandoc/filters/builtin-tags.rb +11 -0
  27. data/lib/nandoc/filters/custom-tag.rb +43 -0
  28. data/lib/nandoc/filters/custom-tags.rb +19 -0
  29. data/lib/nandoc/filters/tag-parse-instance-methods.rb +11 -0
  30. data/lib/nandoc/filters/tag-parser.rb +206 -0
  31. data/lib/nandoc/filters.rb +11 -585
  32. data/lib/nandoc/{cri-hacks.rb → hacks/cri-hacks.rb} +4 -3
  33. data/lib/nandoc/{data-source.rb → hacks/data-source.rb} +5 -4
  34. data/lib/nandoc/{item-class-hacks.rb → hacks/item-class-hacks.rb} +3 -1
  35. data/lib/nandoc/hacks.rb +6 -0
  36. data/lib/nandoc/helpers/menu-bouncy.rb +1 -1
  37. data/lib/nandoc/helpers/site-map.rb +3 -0
  38. data/lib/nandoc/helpers.rb +1 -1
  39. data/lib/nandoc/html/tags.rb +65 -0
  40. data/lib/nandoc/html.rb +6 -0
  41. data/lib/nandoc/parse-readme.rb +4 -0
  42. data/lib/nandoc/spec-doc/agent-instance-methods.rb +24 -0
  43. data/lib/nandoc/spec-doc/code-snippet.rb +59 -0
  44. data/lib/nandoc/spec-doc/generic-agent.rb +40 -0
  45. data/lib/nandoc/spec-doc/mock-prompt.rb +3 -9
  46. data/lib/nandoc/spec-doc/parse-trace.rb +25 -0
  47. data/lib/nandoc/spec-doc/{mini-test/spec-instance-methods.rb → playback/html/foo-bar.rb} +0 -0
  48. data/lib/nandoc/spec-doc/playback/html.rb +2 -0
  49. data/lib/nandoc/spec-doc/playback/players/method.rb +64 -0
  50. data/lib/nandoc/spec-doc/playback/players/ruby.rb +158 -0
  51. data/lib/nandoc/spec-doc/playback/players/terminal.rb +93 -0
  52. data/lib/nandoc/spec-doc/playback/players.rb +4 -0
  53. data/lib/nandoc/spec-doc/playback/support/playback-methods.rb +44 -0
  54. data/lib/nandoc/spec-doc/playback/support/sexp-scanner.rb +61 -0
  55. data/lib/nandoc/spec-doc/playback/support.rb +3 -0
  56. data/lib/nandoc/spec-doc/playback/terminal/color-to-html.rb +100 -0
  57. data/lib/nandoc/spec-doc/playback.rb +3 -0
  58. data/lib/nandoc/spec-doc/recordings.rb +55 -0
  59. data/lib/nandoc/spec-doc/ruby2ruby-standin.rb +37 -0
  60. data/lib/nandoc/spec-doc/test-case-agent.rb +1 -1
  61. data/lib/nandoc/spec-doc/{mini-test.rb → test-framework/mini-test/proxy.rb} +9 -31
  62. data/lib/nandoc/spec-doc/{test-framework-proxy.rb → test-framework/proxy.rb} +27 -50
  63. data/lib/nandoc/spec-doc.rb +57 -13
  64. data/lib/nandoc/{test → support}/diff-to-string.rb +0 -0
  65. data/lib/nandoc/support/regexp-enhance.rb +6 -0
  66. data/lib/nandoc/support/regexp.rb +12 -0
  67. data/lib/nandoc/support/secret-parent.rb +21 -0
  68. data/lib/nandoc/support/shared-attr-reader.rb +32 -0
  69. data/lib/nandoc/support/site-merge.rb +1 -1
  70. data/lib/nandoc/support/site-methods.rb +4 -4
  71. data/lib/nandoc/support/stream-colorizer.rb +1 -1
  72. data/lib/nandoc/support/string-methods.rb +56 -0
  73. data/lib/nandoc.rb +12 -35
  74. data/proto/README.md +4 -2
  75. data/test/test.rb +1 -0
  76. metadata +58 -25
  77. data/doc/bar/baz.md +0 -4
  78. data/doc/bar/bliff.md +0 -8
  79. data/doc/foo.md +0 -5
  80. data/doc/getting-started.rb +0 -13
  81. data/lib/nandoc/spec-doc/support-modules.rb +0 -158
  82. data/lib/nandoc/spec-doc/test-framework-dispatcher.rb +0 -15
  83. data/lib/nandoc/support-modules.rb +0 -273
  84. data/lib/nandoc/treebis/NOGIT-DOCS/NEWS.md +0 -5
  85. data/lib/nandoc/treebis/NOGIT-README.md +0 -65
  86. data/lib/nandoc/treebis/nandoc.persistent.json +0 -3
@@ -0,0 +1,61 @@
1
+ module NanDoc::SpecDoc::Playback
2
+ class SexpScanner
3
+ def initialize sexp
4
+ @sexp = sexp
5
+ @offset = 0
6
+ @last = @sexp.size - 1
7
+ end
8
+ def chimp arr
9
+ arr.size == 1 ? arr.first : arr
10
+ end
11
+ def current
12
+ @sexp[@offset]
13
+ end
14
+ def eos?
15
+ @offset > @last
16
+ end
17
+ def rest
18
+ @sexp[@offset..-1]
19
+ end
20
+ attr_reader :sexp
21
+ def scan a, *b
22
+ current = self.current or return nil
23
+ search = [a,*b]
24
+ ret = nil
25
+ if current[0..search.size-1] == search
26
+ ret = current
27
+ @offset += 1
28
+ end
29
+ ret
30
+ end
31
+ def scan_assert a, *b
32
+ ret = scan(a, *b)
33
+ if ! ret
34
+ fail("expecting #{a.inspect} had #{current.inspect}")
35
+ end
36
+ ret
37
+ end
38
+ def skip_to_after a, *b
39
+ search = [a, *b]
40
+ last = search.size - 1
41
+ idx = @sexp.index{ |n| n[0..last] == search }
42
+ ret = false
43
+ if idx
44
+ @offset = idx + 1
45
+ ret = @offset
46
+ end
47
+ ret
48
+ end
49
+ def skip_to_after_assert a, *b
50
+ idx = skip_to_after(a, *b)
51
+ if ! idx
52
+ search = [a, *b]
53
+ last = search.size - 1
54
+ nn = @sexp.select{ |n| n[0..last] == search }
55
+ nn = nn.map{ |n| chimp(n[1..-1]).inspect }
56
+ fail("#{chimp(search).inspect} not found. had:(#{nn.join(', ')})")
57
+ end
58
+ idx
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ me = File.dirname(__FILE__)+'/support'
2
+ require me + '/playback-methods.rb'
3
+ require me + '/sexp-scanner.rb'
@@ -0,0 +1,100 @@
1
+ module NanDoc; end
2
+ module NanDoc::SpecDoc; end
3
+ module NanDoc::SpecDoc::Playback; end
4
+ class NanDoc::SpecDoc::Playback::Terminal; end
5
+ module NanDoc::SpecDoc::Playback::Terminal::ColorToHtml
6
+
7
+
8
+ include Nanoc3::Helpers::HTMLEscape
9
+ alias_method :h, :html_escape
10
+
11
+
12
+ # look for things that look like prompts and make them brighter
13
+ # @todo html escape vis-a-vis blah
14
+ def prompt_highlight str
15
+ lines = str.split("\n")
16
+ linez = lines.map do |line|
17
+ line.sub( %r!\A(~[^>]*>)?(.*)\Z! ) do
18
+ tags = [];
19
+ tags.push "<span class='prompt'>#{h($1)}</span>" if $1
20
+ tags.push "<span class='normal'>#{h($2)}</span>" unless $2.empty?
21
+ tags.join('')
22
+ end
23
+ end
24
+ html = linez.join("\n")
25
+ html
26
+ end
27
+
28
+ def prompt_highlight2 prompt, cmd
29
+ "<span class='prompt'>#{h(prompt)}</span>"<<
30
+ "<span class='normal'>#{h(cmd)}</span>\n"
31
+ end
32
+
33
+ # this sucks.
34
+ #
35
+ # the other side of these associations lives in trollop-subset.css
36
+ Code2CssClass = {
37
+ '1' => 'bright', '30' => 'black', '31' => 'red', '32' => 'green',
38
+ '33' => 'yellow', '34' => 'blue', '35' => 'magenta', '36' => 'cyan',
39
+ '37' => 'white'
40
+ }
41
+ def terminal_color_to_html str
42
+ return nil unless str.index("\e[") # save a whale
43
+ scn = StringScanner.new(str)
44
+ sexp = []
45
+ while true
46
+ foo = scn.scan(/(.*?)(?=\e\[)/m)
47
+ if ! foo
48
+ blork = scn.scan_until(/\Z/m) or fail("worglebezoik")
49
+ sexp.push([:content, blork]) unless blork.empty?
50
+ break;
51
+ end
52
+ foo or fail("oopfsh")
53
+ sexp.push([:content, foo]) unless foo.empty?
54
+ bar = scn.scan(/\e\[/) or fail("goff")
55
+ baz = scn.scan(/\d+(?:;\d+)*/)
56
+ baz or fail("narghh")
57
+ if '0'==baz
58
+ sexp.push([:pop])
59
+ else
60
+ sexp.push([:push, *baz.split(';')])
61
+ end
62
+ biff = scn.scan(/m/) or fail("noiflphh")
63
+ end
64
+ html = terminal_colorized_sexp_to_html sexp
65
+ html
66
+ end
67
+ private
68
+ def terminal_code_to_css_class code
69
+ Code2CssClass[code] or
70
+ fail("sorry, no known code for #{code.inspect}. "<<
71
+ "(maybe you should make one?)")
72
+ end
73
+ def terminal_colorized_sexp_to_html sexp
74
+ i = -1;
75
+ last = sexp.length - 1;
76
+ parts = []
77
+ catch(:done) do
78
+ while (i+=1) <= last
79
+ codes = nil
80
+ while i <= last && sexp[i].first == :push
81
+ codes ||= []
82
+ codes.concat sexp[i][1..-1]
83
+ i += 1
84
+ end
85
+ if codes
86
+ classes = codes.map{|c| terminal_code_to_css_class(c) }*' '
87
+ parts.push "<span class='#{classes}'>"
88
+ end
89
+ throw :done if i > last
90
+ case sexp[i].first
91
+ when :content; parts.push(sexp[i][1])
92
+ when :pop; parts.push('</span>')
93
+ else; fail('fook');
94
+ end
95
+ end
96
+ end
97
+ html = parts*''
98
+ html
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ me = File.dirname(__FILE__) + '/playback'
2
+ require me + '/support'
3
+ require me + '/players'
@@ -0,0 +1,55 @@
1
+ module NanDoc::SpecDoc
2
+
3
+ class Recordings < Array
4
+ #
5
+ # everything that nandoc does during test runs gets written
6
+ # to one of these. It's like a Sexp structure.
7
+ #
8
+
9
+ @for_test_case = {}
10
+ @for_key = {}
11
+
12
+ class << self
13
+ attr_accessor :for_test_case, :for_key
14
+ def get test_case
15
+ @for_test_case[test_case.class] ||= new(test_case.class)
16
+ end
17
+ def get_for_key key
18
+ @for_key[key] ||= new(key)
19
+ end
20
+ def report_test_case_not_found tc
21
+ msgs = ["no recordings found for #{tc}"]
22
+ msgs.join(' ')
23
+ end
24
+ end
25
+
26
+ def add name, *data
27
+ # this might change if we need to group by method name
28
+ push [name, *data]
29
+ end
30
+
31
+ def get_first_sexp_for_test_method meth
32
+ first = index([:method, meth]) or return nil
33
+ last = (first+1..length-1).detect do |i|
34
+ self[i].first == :method && self[i][1] != meth
35
+ end
36
+ last = last ? (last - 1) : (length - 1)
37
+ ret = self[first..last]
38
+ ret
39
+ end
40
+
41
+ def initialize test_case
42
+ @test_case = test_case
43
+ end
44
+
45
+ def note &block
46
+ push [:note, block]
47
+ end
48
+
49
+ def report_recording_not_found meth_name
50
+ "no recordings found for #{meth_name}"
51
+ end
52
+
53
+ attr_reader :test_case
54
+ end
55
+ end
@@ -0,0 +1,37 @@
1
+ module NanDoc::SpecDoc
2
+ module Ruby2RubyStandin
3
+ def leading_indent str
4
+ /\A([ \t]*)/ =~ str && $1
5
+ end
6
+ def re_for_line_with_same_indent_as str
7
+ ind = leading_indent(str)
8
+ re = /\A#{Regexp.escape(ind)}(?=[^ \t])/
9
+ re
10
+ end
11
+ def re_for_here here
12
+ /\A[ \t]*#{Regexp.escape(here)}[ \t]*\n?\Z/
13
+ end
14
+ def re_for_unindent_gsub indent
15
+ re = /\A#{Regexp.escape(indent)}/
16
+ re
17
+ end
18
+ def reindent_content raw_content, indent
19
+ return raw_content if indent == ''
20
+ # of all non-blank lines find the minimum indent.
21
+ x = raw_content.scan(/^[[:space:]]+(?=[^[:space:]])/).map(&:length).min
22
+ # if for some reason the content has less indent than the fences,
23
+ # don't alter any of it.
24
+ return raw_content if x < indent.length
25
+ re = /^#{Regexp.new(indent)}/
26
+ unindented_content = raw_content.gsub(re, '')
27
+ unindented_content
28
+ end
29
+ def string_diff_assert long, short
30
+ idx = long.index(short) or fail("short not found in long -- "<<
31
+ "#{short.inspect} in #{long.inspect}")
32
+ head = long[0,idx] # usu. ''
33
+ tail = long[idx + short.length..-1]
34
+ head + tail
35
+ end
36
+ end
37
+ end
@@ -51,7 +51,7 @@ module NanDoc::SpecDoc
51
51
  end
52
52
  private
53
53
  def recordings
54
- Recordings.get(@test_case)
54
+ ::NanDoc::SpecDoc::Recordings.get(@test_case)
55
55
  end
56
56
  end
57
57
  end
@@ -1,16 +1,17 @@
1
- require 'stringio'
2
- require File.expand_path('../../test/minitest-extlib.rb', __FILE__)
1
+ require 'nandoc/spec-doc/test-framework/proxy'
3
2
 
4
- module NanDoc::SpecDoc::MiniTest
5
- class Proxy < ::NanDoc::SpecDoc::TestFrameworkProxy
3
+ module NanDoc::SpecDoc::TestFramework::MiniTest
4
+ class Proxy < ::NanDoc::SpecDoc::TestFramework::Proxy
5
+ #
6
+ # our central nexus interflux for all interactions that require mini-test
7
+ #
8
+
9
+ private
6
10
 
7
- def initialize(*a)
8
- super(*a)
11
+ def initialize
9
12
  @hacked_minitest = false
10
13
  end
11
14
 
12
- private
13
-
14
15
  #
15
16
  # given
16
17
  # @param [String] the natural sounding string name as it appears in
@@ -79,27 +80,4 @@ module NanDoc::SpecDoc::MiniTest
79
80
  return 0
80
81
  end
81
82
  end
82
-
83
-
84
- #
85
- # These are the methods that will be available to nandoc-enhanced tests.
86
- # For now it is recommended to leave this as just the one method nandoc(),
87
- # which will return the TestCaseAgent.
88
- #
89
- module SpecInstanceMethods
90
- class << self
91
- def include_to mod
92
- unless mod.ancestors.include?(::MiniTest::Spec)
93
- fail(
94
- "Sorry, for now SpecDoc can only extend MiniTest::Spec "<<
95
- " tests. Couldn't extend #{mod}."
96
- )
97
- end
98
- mod.send(:include, self)
99
- end
100
- end
101
- def nandoc
102
- @nandoc_agent ||= ::NanDoc::SpecDoc::TestCaseAgent.new(self)
103
- end
104
- end
105
83
  end
@@ -1,41 +1,14 @@
1
- module NanDoc::SpecDoc
2
- class TestFrameworkProxy
1
+ module NanDoc::SpecDoc::TestFramework
2
+ class Proxy
3
+ protected
3
4
  # abstract baseclass, an agent that runs tests
4
5
 
5
- def initialize gem_root
6
- @gem_root = gem_root
7
- end
8
-
9
- def get_sexp testfile, testname
10
- TestFrameworkProxy.sexp_cache[testfile][testname] ||= begin
11
- build_sexp testfile, testname
12
- end
13
- end
14
-
15
- def build_sexp testfile, testname
16
- load_file testfile
17
- test_case, meth_name = find_test testname
18
- run_test_case_method testfile, testname, test_case, meth_name
19
- recs = ::NanDoc::SpecDoc::Recordings.for_test_case[test_case] or
20
- fail(::NanDoc::SpecDoc::Recordings.
21
- report_test_case_not_found(test_case))
22
- sexp = recs.get_first_sexp_for_test_method(meth_name) or
23
- fail recs.report_recording_not_found(meth_name)
24
- sexp
25
- end
26
-
27
6
  @sexp_cache = Hash.new{ |h,k| h[k] = {} }
28
7
  class << self
29
8
  attr_reader :sexp_cache
30
9
  end
31
10
 
32
- protected
33
-
34
- #
35
- # the stream to write to when things like a specdoc test run fails
36
- #
37
- def err
38
- $stderr
11
+ def initialize
39
12
  end
40
13
 
41
14
  def handle_failed_tests runner, testfile, testname
@@ -48,31 +21,35 @@ module NanDoc::SpecDoc
48
21
  exit(1);
49
22
  end
50
23
 
51
- def load_file testfile
52
- path = testdir + '/' + testfile
53
- fail("test file not found: #{path.inspect}") unless File.file?(path)
54
- # if you need to, do a diff
55
- require path
24
+ # the stream to write to when things like a specdoc test run fails
25
+ def err
26
+ $stderr
27
+ end
28
+
29
+ def sexp_build testfile, testname
30
+ NanDoc::Project.instance.require_test_file(testfile)
31
+ test_case, meth_name = find_test testname
32
+ run_test_case_method testfile, testname, test_case, meth_name
33
+ recs = ::NanDoc::SpecDoc::Recordings.for_test_case[test_case] or
34
+ fail(::NanDoc::SpecDoc::Recordings.
35
+ report_test_case_not_found(test_case))
36
+ sexp = recs.get_first_sexp_for_test_method(meth_name) or
37
+ fail recs.report_recording_not_found(meth_name)
38
+ sexp
39
+ end
40
+
41
+ public
42
+ def sexp_get testfile, testname
43
+ Proxy.sexp_cache[testfile][testname] ||= begin
44
+ sexp_build testfile, testname
45
+ end
56
46
  end
57
47
 
58
- #
48
+ protected
59
49
  # default way to read what the test run wrote to stdout
60
- #
61
50
  def testout_str
62
51
  @testout.rewind
63
52
  @testout.read
64
53
  end
65
-
66
- #
67
- # default way to deduce the root directory that holds the tests
68
- #
69
- def testdir
70
- @testdir ||= begin
71
- tries = [@gem_root+'/test', @gem_root+'/spec']
72
- found = tries.detect{ |path| File.directory?(path) }
73
- fail("Couldn't find test dir for gem at (#{tries*', '})") unless found
74
- found
75
- end
76
- end
77
54
  end
78
55
  end
@@ -4,10 +4,16 @@ unless Object.const_defined?('NanDoc')
4
4
  require File.expand_path('../../nandoc.rb', __FILE__)
5
5
  end
6
6
 
7
+
8
+ # @todo get this right
9
+ unless NanDoc.const_defined?('SpecDoc') # TO_HERE_HACK
10
+
7
11
  me = File.dirname(__FILE__)+'/spec-doc'
8
- require me + '/support-modules.rb'
12
+ require me + '/agent-instance-methods.rb'
13
+ require me + '/code-snippet.rb'
14
+ require me + '/parse-trace.rb'
15
+ require me + '/recordings.rb'
9
16
  require me + '/test-case-agent.rb'
10
- require me + '/test-framework-dispatcher.rb'
11
17
 
12
18
  module NanDoc
13
19
  module SpecDoc
@@ -20,27 +26,65 @@ module NanDoc
20
26
  def include_to mod
21
27
  if Object.const_defined?('MiniTest') &&
22
28
  mod.ancestors.include?(::MiniTest::Spec)
23
- require File.dirname(__FILE__)+'/spec-doc/mini-test.rb'
24
- ::NanDoc::SpecDoc::MiniTest::SpecInstanceMethods.include_to mod
29
+ require 'nandoc/extlib/minitest.rb'
30
+ SpecInstanceMethods.include_to mod
25
31
  else
26
- fail("don't know how to enhance test module: #{mod}")
32
+ GenericInstanceMethods.include_to mod
27
33
  end
28
34
  end
35
+
36
+ #
37
+ # no reason not to use the conventional callback
38
+ # in cases where we are not passing parameters to the enhancement
39
+ #
40
+ alias_method :included, :include_to
29
41
  end
30
42
 
31
- def initialize gem_root
32
- @sexp_cache = Hash.new{|h,k| h[k] = {}}
33
- @test_framework_dispatcher = TestFrameworkDispatcher.new(gem_root)
43
+ #
44
+ # Experimental nandoc hook to give random ass objects a hook to some
45
+ # kind of SpecDoc agent thing that can a) not necessarily be a test case
46
+ # but b) still write recordings somehow. let's see what happens. hook.
47
+ #
48
+ module GenericInstanceMethods
49
+ class << self
50
+ def include_to mod
51
+ mod.send(:include, self)
52
+ end
53
+ end
54
+ def nandoc
55
+ @nandoc_agent ||= begin
56
+ require File.dirname(__FILE__)+'/spec-doc/generic-agent'
57
+ GenericAgent.new(self)
58
+ end
59
+ end
34
60
  end
35
61
 
36
62
  #
37
- # only run any test method at most once, just to keep recordings clean
63
+ # These are the methods that will be available to nandoc-enhanced tests.
64
+ # For now it is recommended to leave this as just the one method nandoc(),
65
+ # which will return the TestCaseAgent.
38
66
  #
39
- def get_sexp testfile, testname
40
- sexp = @sexp_cache[testfile][testname] ||= begin
41
- @test_framework_dispatcher.get_sexp testfile, testname
67
+ module SpecInstanceMethods
68
+ class << self
69
+ def include_to mod
70
+ #
71
+ # This used to be MiniTest::Spec-specific, now it's not, but here
72
+ # for reference:
73
+ #
74
+ # unless mod.ancestors.include?(::MiniTest::Spec)
75
+ # fail(
76
+ # "Sorry, for now SpecDoc can only extend MiniTest::Spec "<<
77
+ # " tests. Couldn't extend #{mod}."
78
+ # )
79
+ # end
80
+ mod.send(:include, self)
81
+ end
82
+ end
83
+ def nandoc
84
+ @nandoc_agent ||= TestCaseAgent.new(self)
42
85
  end
43
- sexp
44
86
  end
45
87
  end
46
88
  end
89
+
90
+ end # TO_HERE_HACK
File without changes
@@ -35,6 +35,12 @@ module NanDoc
35
35
  end
36
36
  end
37
37
  end
38
+ def match_assert str, name=nil
39
+ match(str) or begin
40
+ use_name = name || "/#{source}/"
41
+ fail("#{use_name} failed to match #{str.inspect}")
42
+ end
43
+ end
38
44
  def names *list
39
45
  if list.any?
40
46
  @names = list
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__)+'/regexp-enhance.rb'
2
+
3
+ module NanDoc
4
+ class Regexp < ::Regexp
5
+ def initialize re, *names
6
+ super(re)
7
+ RegexpEnhance.to(self) do |me|
8
+ me.names(*names) if names.any?
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module NanDoc
2
+ module SecretParent
3
+ #
4
+ # @dependencies: none
5
+ # @api private
6
+ # set parent attribute without it showing up in inspect() dumps
7
+ #
8
+ def parent= mixed
9
+ fail("no clear_parent() available yet.") unless mixed
10
+ @has_parent = !! mixed
11
+ class << self; self end.send(:define_method, :parent){mixed}
12
+ mixed # maybe chain assignmnet of 1 parent to several cx at once
13
+ end
14
+ def parent?
15
+ instance_variable_defined?('@has_parent') && @has_parent # no warnings
16
+ end
17
+ def parent
18
+ nil
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module NanDoc
2
+ module SharedAttrReader
3
+ #
4
+ # @api private
5
+ # @dependencies none
6
+ #
7
+ # this is a specialized form of delegator pattern: let one object
8
+ # use the responses from another object for a set of accessors
9
+ #
10
+ def shared_attr_reader *list
11
+ fail('no inehiritance yet') if method_defined?(:shared=)
12
+ sm = Module.new
13
+ name = self.to_s+'::SharedAttrReaders'
14
+ sing = class << sm; self end
15
+ sing.send(:define_method, :name){name}
16
+ sing.send(:alias_method, :inspect, :name)
17
+ list.each do |attrib|
18
+ sm.send(:define_method, attrib){ shared.send(attrib) }
19
+ end
20
+ fail('no') if method_defined?(:shared)
21
+ define_method(:shared){ self }
22
+ define_method(:shared=) do |source|
23
+ sing = class << self; self end
24
+ sing.send(:define_method, :shared){ source }
25
+ sing.send(:include, sm) # wow cool that this works w/o having
26
+ # to Module#undef_method
27
+ source
28
+ end
29
+ nil
30
+ end
31
+ end
32
+ end
@@ -11,7 +11,7 @@ module NanDoc
11
11
  end
12
12
  def site_merge opts, args
13
13
  existing_site_path = args.first
14
- task_abort("it's not exist: #{path}") unless
14
+ command_abort("it's not exist: #{path}") unless
15
15
  File.exist?(existing_site_path)
16
16
  # nanoc writes to stdout so we do too, but here we want to write
17
17
  # to stderr these notices, and write the diff to stdout
@@ -23,7 +23,7 @@ module NanDoc
23
23
  end
24
24
  path
25
25
  else
26
- task_abort <<-D.gsub(/^ */,'')
26
+ command_abort <<-D.gsub(/^ */,'')
27
27
  site path not found: #{args.first.inspect}
28
28
  usage: #{usage}
29
29
  #{invite_to_more_command_help}
@@ -37,14 +37,14 @@ module NanDoc
37
37
  path
38
38
  else
39
39
  persistent_set('last_site_path',false)
40
- task_abort <<-D.gsub(/^ */,'')
40
+ command_abort <<-D.gsub(/^ */,'')
41
41
  previous site path is stale (#{path.inspect}) and no site provided
42
42
  usage: #{usage}
43
43
  #{invite_to_more_command_help}
44
44
  D
45
45
  end
46
46
  else
47
- task_abort(
47
+ command_abort(
48
48
  'no site path provided and no site path in persistent data file '<<
49
49
  "(#{NanDoc.dotfile_path})\n"<<
50
50
  <<-D.gsub(/^ */,'')
@@ -61,7 +61,7 @@ module NanDoc
61
61
  #
62
62
  def parse_config_for_site_path path
63
63
  config_path = config_path_for_site_path( path )
64
- task_abort("config file for app not found: #{config_path}") unless
64
+ command_abort("config file for app not found: #{config_path}") unless
65
65
  File.exist?(config_path)
66
66
  YAML.load_file config_path
67
67
  end
@@ -72,7 +72,7 @@ module NanDoc
72
72
  end
73
73
  attr_reader :rule_list
74
74
  def when(re_or_symbol, opts=nil, &block)
75
- if re_or_symbol.kind_of?(Regexp) && Hash===opts && ! block_given?
75
+ if re_or_symbol.kind_of?(::Regexp) && Hash===opts && ! block_given?
76
76
  add_regex_rule(re_or_symbol, opts)
77
77
  elsif re_or_symbol.kind_of?(Symbol) && opts.nil? && block_given?
78
78
  define_state(re_or_symbol, &block)