rdoc 3.9.5 → 3.10.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (183) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +6 -3
  3. data/History.txt +63 -13
  4. data/LICENSE.rdoc +57 -0
  5. data/Manifest.txt +60 -6
  6. data/Rakefile +24 -12
  7. data/TODO.rdoc +30 -0
  8. data/bin/rdoc +0 -2
  9. data/lib/rdoc.rb +55 -2
  10. data/lib/rdoc/alias.rb +0 -2
  11. data/lib/rdoc/anon_class.rb +0 -2
  12. data/lib/rdoc/any_method.rb +0 -3
  13. data/lib/rdoc/attr.rb +0 -2
  14. data/lib/rdoc/class_module.rb +40 -7
  15. data/lib/rdoc/code_object.rb +1 -3
  16. data/lib/rdoc/code_objects.rb +3 -21
  17. data/lib/rdoc/comment.rb +225 -0
  18. data/lib/rdoc/constant.rb +0 -2
  19. data/lib/rdoc/context.rb +37 -120
  20. data/lib/rdoc/context/section.rb +114 -0
  21. data/lib/rdoc/cross_reference.rb +16 -7
  22. data/lib/rdoc/encoding.rb +0 -2
  23. data/lib/rdoc/gauntlet.rb +1 -1
  24. data/lib/rdoc/generator.rb +7 -2
  25. data/lib/rdoc/generator/darkfish.rb +126 -20
  26. data/lib/rdoc/generator/json_index.rb +240 -0
  27. data/lib/rdoc/generator/markup.rb +17 -54
  28. data/lib/rdoc/generator/ri.rb +0 -3
  29. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  30. data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
  31. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
  32. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  33. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
  34. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
  35. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  36. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
  37. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
  41. data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
  42. data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
  43. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  44. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  45. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  46. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  47. data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
  48. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
  49. data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
  50. data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
  51. data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
  52. data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
  53. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
  54. data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
  55. data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
  56. data/lib/rdoc/ghost_method.rb +0 -2
  57. data/lib/rdoc/include.rb +0 -2
  58. data/lib/rdoc/markup.rb +204 -43
  59. data/lib/rdoc/markup/attr_changer.rb +25 -0
  60. data/lib/rdoc/markup/attr_span.rb +29 -0
  61. data/lib/rdoc/markup/attribute.rb +51 -0
  62. data/lib/rdoc/markup/document.rb +22 -1
  63. data/lib/rdoc/markup/formatter.rb +4 -11
  64. data/lib/rdoc/markup/formatter_test_case.rb +1 -2
  65. data/lib/rdoc/markup/heading.rb +44 -0
  66. data/lib/rdoc/markup/include.rb +42 -0
  67. data/lib/rdoc/markup/inline.rb +1 -144
  68. data/lib/rdoc/markup/list.rb +2 -1
  69. data/lib/rdoc/markup/parser.rb +6 -16
  70. data/lib/rdoc/markup/pre_process.rb +64 -10
  71. data/lib/rdoc/markup/raw.rb +1 -1
  72. data/lib/rdoc/markup/special.rb +40 -0
  73. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
  74. data/lib/rdoc/markup/to_ansi.rb +0 -2
  75. data/lib/rdoc/markup/to_bs.rb +0 -2
  76. data/lib/rdoc/markup/to_html.rb +102 -34
  77. data/lib/rdoc/markup/to_html_crossref.rb +36 -5
  78. data/lib/rdoc/markup/to_html_snippet.rb +270 -0
  79. data/lib/rdoc/markup/to_label.rb +55 -0
  80. data/lib/rdoc/markup/to_rdoc.rb +0 -3
  81. data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
  82. data/lib/rdoc/markup/to_test.rb +0 -3
  83. data/lib/rdoc/markup/to_tt_only.rb +0 -3
  84. data/lib/rdoc/markup/verbatim.rb +18 -0
  85. data/lib/rdoc/meta_method.rb +0 -2
  86. data/lib/rdoc/method_attr.rb +17 -1
  87. data/lib/rdoc/normal_class.rb +0 -2
  88. data/lib/rdoc/normal_module.rb +0 -2
  89. data/lib/rdoc/options.rb +18 -3
  90. data/lib/rdoc/parser.rb +74 -42
  91. data/lib/rdoc/parser/c.rb +79 -118
  92. data/lib/rdoc/parser/rd.rb +22 -0
  93. data/lib/rdoc/parser/ruby.rb +86 -54
  94. data/lib/rdoc/parser/simple.rb +21 -9
  95. data/lib/rdoc/parser/text.rb +11 -0
  96. data/lib/rdoc/rd.rb +95 -0
  97. data/lib/rdoc/rd/block_parser.ry +638 -0
  98. data/lib/rdoc/rd/inline.rb +71 -0
  99. data/lib/rdoc/rd/inline_parser.ry +575 -0
  100. data/lib/rdoc/rdoc.rb +8 -23
  101. data/lib/rdoc/require.rb +0 -2
  102. data/lib/rdoc/ri.rb +4 -2
  103. data/lib/rdoc/ri/driver.rb +2 -6
  104. data/lib/rdoc/ri/store.rb +0 -1
  105. data/lib/rdoc/ruby_lex.rb +43 -20
  106. data/lib/rdoc/ruby_token.rb +44 -2
  107. data/lib/rdoc/single_class.rb +0 -2
  108. data/lib/rdoc/stats.rb +0 -5
  109. data/lib/rdoc/task.rb +2 -6
  110. data/lib/rdoc/test_case.rb +59 -0
  111. data/lib/rdoc/text.rb +42 -30
  112. data/lib/rdoc/token_stream.rb +45 -0
  113. data/lib/rdoc/tom_doc.rb +232 -0
  114. data/lib/rdoc/top_level.rb +36 -4
  115. data/test/test_attribute_manager.rb +26 -29
  116. data/test/test_rdoc_any_method.rb +2 -26
  117. data/test/test_rdoc_attr.rb +4 -4
  118. data/test/test_rdoc_class_module.rb +95 -12
  119. data/test/test_rdoc_code_object.rb +10 -3
  120. data/test/test_rdoc_comment.rb +504 -0
  121. data/test/test_rdoc_context.rb +60 -11
  122. data/test/test_rdoc_context_section.rb +16 -17
  123. data/test/test_rdoc_cross_reference.rb +17 -2
  124. data/test/test_rdoc_encoding.rb +4 -7
  125. data/test/test_rdoc_generator_darkfish.rb +12 -11
  126. data/test/test_rdoc_generator_json_index.rb +255 -0
  127. data/test/test_rdoc_generator_markup.rb +56 -0
  128. data/test/test_rdoc_generator_ri.rb +8 -11
  129. data/test/test_rdoc_markup.rb +9 -5
  130. data/test/test_rdoc_markup_attribute_manager.rb +5 -8
  131. data/test/test_rdoc_markup_document.rb +34 -6
  132. data/test/test_rdoc_markup_formatter.rb +11 -13
  133. data/test/test_rdoc_markup_heading.rb +20 -0
  134. data/test/test_rdoc_markup_include.rb +19 -0
  135. data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
  136. data/test/test_rdoc_markup_paragraph.rb +2 -5
  137. data/test/test_rdoc_markup_parser.rb +87 -7
  138. data/test/test_rdoc_markup_pre_process.rb +60 -9
  139. data/test/test_rdoc_markup_raw.rb +4 -6
  140. data/test/test_rdoc_markup_to_ansi.rb +1 -4
  141. data/test/test_rdoc_markup_to_bs.rb +1 -4
  142. data/test/test_rdoc_markup_to_html.rb +170 -31
  143. data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
  144. data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
  145. data/test/test_rdoc_markup_to_label.rb +50 -0
  146. data/test/test_rdoc_markup_to_rdoc.rb +1 -4
  147. data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
  148. data/test/test_rdoc_markup_to_tt_only.rb +1 -4
  149. data/test/test_rdoc_markup_verbatim.rb +16 -0
  150. data/test/test_rdoc_method_attr.rb +16 -1
  151. data/test/test_rdoc_options.rb +17 -7
  152. data/test/test_rdoc_parser.rb +75 -6
  153. data/test/test_rdoc_parser_c.rb +56 -104
  154. data/test/test_rdoc_parser_rd.rb +52 -0
  155. data/test/test_rdoc_parser_ruby.rb +264 -323
  156. data/test/test_rdoc_parser_simple.rb +33 -17
  157. data/test/test_rdoc_rd.rb +30 -0
  158. data/test/test_rdoc_rd_block_parser.rb +527 -0
  159. data/test/test_rdoc_rd_inline.rb +63 -0
  160. data/test/test_rdoc_rd_inline_parser.rb +173 -0
  161. data/test/test_rdoc_rdoc.rb +7 -9
  162. data/test/test_rdoc_ri_driver.rb +10 -15
  163. data/test/test_rdoc_ri_paths.rb +6 -6
  164. data/test/test_rdoc_ri_store.rb +6 -13
  165. data/test/test_rdoc_ruby_lex.rb +53 -5
  166. data/test/test_rdoc_rubygems_hook.rb +2 -1
  167. data/test/test_rdoc_stats.rb +83 -103
  168. data/test/test_rdoc_task.rb +5 -4
  169. data/test/test_rdoc_text.rb +156 -11
  170. data/test/test_rdoc_token_stream.rb +42 -0
  171. data/test/test_rdoc_tom_doc.rb +458 -0
  172. data/test/test_rdoc_top_level.rb +49 -2
  173. data/test/xref_test_case.rb +4 -8
  174. metadata +217 -111
  175. metadata.gz.sig +0 -0
  176. checksums.yaml +0 -7
  177. checksums.yaml.gz.sig +0 -0
  178. data/CVE-2013-0256.rdoc +0 -49
  179. data/LICENSE.txt +0 -57
  180. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
  181. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  182. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  183. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+
4
+ require 'fileutils'
5
+ require 'pp'
6
+ require 'tempfile'
7
+ require 'tmpdir'
8
+ require 'stringio'
9
+
10
+ require 'rdoc'
11
+
12
+ ##
13
+ # RDoc::TestCase is an abstract TestCase to provide common setup and teardown
14
+ # across all RDoc tests. The test case uses minitest, so all the assertions
15
+ # of minitest may be used.
16
+ #
17
+ # The testcase provides the following:
18
+ #
19
+ # * A reset code-object tree
20
+ # * A reset markup preprocessor (RDoc::Markup::PreProcess)
21
+ # * The <code>@RM</code> alias of RDoc::Markup (for less typing)
22
+ # * <code>@pwd</code> containing the current working directory
23
+ # * FileUtils, pp, Tempfile, Dir.tmpdir and StringIO
24
+
25
+ class RDoc::TestCase < MiniTest::Unit::TestCase
26
+
27
+ ##
28
+ # Abstract test-case setup
29
+
30
+ def setup
31
+ super
32
+
33
+ @top_level = nil
34
+
35
+ @RM = RDoc::Markup
36
+
37
+ RDoc::RDoc.reset
38
+ RDoc::Markup::PreProcess.reset
39
+
40
+ @pwd = Dir.pwd
41
+ end
42
+
43
+ ##
44
+ # Creates an RDoc::Comment with +text+ which was defined on +top_level+.
45
+ # By default the comment has the 'rdoc' format.
46
+
47
+ def comment text, top_level = @top_level
48
+ RDoc::Comment.new text, top_level
49
+ end
50
+
51
+ end
52
+
53
+ # This hack allows autoload to work when Dir.pwd is changed for Ruby 1.8 since
54
+ # -I paths are not expanded.
55
+ $LOAD_PATH.each do |load_path|
56
+ break if load_path[0] == ?/
57
+ load_path.replace File.expand_path load_path
58
+ end if RUBY_VERSION < '1.9'
59
+
@@ -5,11 +5,33 @@
5
5
 
6
6
  require 'strscan'
7
7
 
8
+ ##
9
+ # For RDoc::Text#snippet
10
+
11
+ begin
12
+ gem 'json'
13
+ rescue Gem::LoadError
14
+ end
15
+
16
+ require 'json'
17
+
8
18
  ##
9
19
  # Methods for manipulating comment text
10
20
 
11
21
  module RDoc::Text
12
22
 
23
+ ##
24
+ # Maps markup formats to classes that can parse them. If the format is
25
+ # unknown, "rdoc" format is used.
26
+
27
+ MARKUP_FORMAT = {
28
+ 'rdoc' => RDoc::Markup,
29
+ 'rd' => RDoc::RD,
30
+ 'tomdoc' => RDoc::TomDoc,
31
+ }
32
+
33
+ MARKUP_FORMAT.default = RDoc::Markup
34
+
13
35
  ##
14
36
  # Maps an encoding to a Hash of characters properly transcoded for that
15
37
  # encoding.
@@ -80,9 +102,7 @@ module RDoc::Text
80
102
  # Requires the including class to implement #formatter
81
103
 
82
104
  def markup text
83
- document = parse text
84
-
85
- document.accept formatter
105
+ parse(text).accept formatter
86
106
  end
87
107
 
88
108
  ##
@@ -91,9 +111,10 @@ module RDoc::Text
91
111
  def normalize_comment text
92
112
  return text if text.empty?
93
113
 
94
- text = strip_hashes text
95
- text = expand_tabs text
96
- text = flush_left text
114
+ text = strip_stars text
115
+ text = strip_hashes text
116
+ text = expand_tabs text
117
+ text = flush_left text
97
118
  text = strip_newlines text
98
119
  text
99
120
  end
@@ -101,35 +122,24 @@ module RDoc::Text
101
122
  ##
102
123
  # Normalizes +text+ then builds a RDoc::Markup::Document from it
103
124
 
104
- def parse text
125
+ def parse text, format = 'rdoc'
105
126
  return text if RDoc::Markup::Document === text
127
+ return text.parse if RDoc::Comment === text
106
128
 
107
- text = normalize_comment text
129
+ text = normalize_comment text # TODO remove, should not be necessary
108
130
 
109
131
  return RDoc::Markup::Document.new if text =~ /\A\n*\z/
110
132
 
111
- RDoc::Markup::Parser.parse text
112
- rescue RDoc::Markup::Parser::Error => e
113
- $stderr.puts <<-EOF
114
- While parsing markup, RDoc encountered a #{e.class}:
115
-
116
- #{e}
117
- \tfrom #{e.backtrace.join "\n\tfrom "}
118
-
119
- ---8<---
120
- #{text}
121
- ---8<---
122
-
123
- RDoc #{RDoc::VERSION}
124
-
125
- Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_RELEASE_DATE}
133
+ MARKUP_FORMAT[format].parse text
134
+ end
126
135
 
127
- Please file a bug report with the above information at:
136
+ ##
137
+ # The first +limit+ characters of +text+ as HTML
128
138
 
129
- https://github.com/rdoc/rdoc/issues
139
+ def snippet text, limit = 100
140
+ document = parse text
130
141
 
131
- EOF
132
- raise
142
+ RDoc::Markup::ToHtmlSnippet.new(limit).convert document
133
143
  end
134
144
 
135
145
  ##
@@ -155,6 +165,8 @@ https://github.com/rdoc/rdoc/issues
155
165
  # Strips /* */ style comments
156
166
 
157
167
  def strip_stars text
168
+ return text unless text =~ %r%/\*.*\*/%m
169
+
158
170
  encoding = text.encoding if Object.const_defined? :Encoding
159
171
 
160
172
  text = text.gsub %r%Document-method:\s+[\w:.#=!?]+%, ''
@@ -202,10 +214,10 @@ https://github.com/rdoc/rdoc/issues
202
214
 
203
215
  until s.eos? do
204
216
  case
205
- when s.scan(/<tt>.*?<\/tt>/) then # skip contents of tt
217
+ when s.scan(/<(tt|code)>.*?<\/\1>/) then # skip contents of tt
206
218
  html << s.matched.gsub('\\\\', '\\')
207
- when s.scan(/<tt>.*?/) then
208
- warn 'mismatched <tt> tag' # TODO signal file/line
219
+ when s.scan(/<(tt|code)>.*?/) then
220
+ warn "mismatched <#{s[1]}> tag" # TODO signal file/line
209
221
  html << s.matched
210
222
  when s.scan(/<[^>]+\/?s*>/) then # skip HTML tags
211
223
  html << s.matched
@@ -7,6 +7,51 @@
7
7
 
8
8
  module RDoc::TokenStream
9
9
 
10
+ ##
11
+ # Converts +token_stream+ to HTML wrapping various tokens with
12
+ # <tt><span></tt> elements. The following tokens types are wrapped in spans
13
+ # with the given class names:
14
+ #
15
+ # TkCONSTANT :: 'ruby-constant'
16
+ # TkKW :: 'ruby-keyword'
17
+ # TkIVAR :: 'ruby-ivar'
18
+ # TkOp :: 'ruby-operator'
19
+ # TkId :: 'ruby-identifier'
20
+ # TkNode :: 'ruby-node'
21
+ # TkCOMMENT :: 'ruby-comment'
22
+ # TkREGEXP :: 'ruby-regexp'
23
+ # TkSTRING :: 'ruby-string'
24
+ # TkVal :: 'ruby-value'
25
+ #
26
+ # Other token types are not wrapped in spans.
27
+
28
+ def self.to_html token_stream
29
+ token_stream.map do |t|
30
+ next unless t
31
+
32
+ style = case t
33
+ when RDoc::RubyToken::TkCONSTANT then 'ruby-constant'
34
+ when RDoc::RubyToken::TkKW then 'ruby-keyword'
35
+ when RDoc::RubyToken::TkIVAR then 'ruby-ivar'
36
+ when RDoc::RubyToken::TkOp then 'ruby-operator'
37
+ when RDoc::RubyToken::TkId then 'ruby-identifier'
38
+ when RDoc::RubyToken::TkNode then 'ruby-node'
39
+ when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
40
+ when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
41
+ when RDoc::RubyToken::TkSTRING then 'ruby-string'
42
+ when RDoc::RubyToken::TkVal then 'ruby-value'
43
+ end
44
+
45
+ text = CGI.escapeHTML t.text
46
+
47
+ if style then
48
+ "<span class=\"#{style}\">#{text}</span>"
49
+ else
50
+ text
51
+ end
52
+ end.join
53
+ end
54
+
10
55
  ##
11
56
  # Adds +tokens+ to the collected tokens
12
57
 
@@ -0,0 +1,232 @@
1
+ # :markup: tomdoc
2
+
3
+ # A parser for TomDoc based on TomDoc 1.0.0-rc1 (02adef9b5a)
4
+ #
5
+ # The TomDoc specification can be found at:
6
+ #
7
+ # http://tomdoc.org
8
+ #
9
+ # The latest version of the TomDoc specification can be found at:
10
+ #
11
+ # https://github.com/mojombo/tomdoc/blob/master/tomdoc.md
12
+ #
13
+ # There are a few differences between this parser and the specification. A
14
+ # best-effort was made to follow the specification as closely as possible but
15
+ # some choices to deviate were made.
16
+ #
17
+ # A future version of RDoc will warn when a MUST or MUST NOT is violated and
18
+ # may warn when a SHOULD or SHOULD NOT is violated. RDoc will always try
19
+ # to emit documentation even if given invalid TomDoc.
20
+ #
21
+ # Here are some implementation choices this parser currently makes:
22
+ #
23
+ # This parser allows rdoc-style inline markup but you should not depended on
24
+ # it.
25
+ #
26
+ # This parser allows a space between the comment and the method body.
27
+ #
28
+ # This parser does not require the default value to be described for an
29
+ # optional argument.
30
+ #
31
+ # This parser does not examine the order of sections. An Examples section may
32
+ # precede the Arguments section.
33
+ #
34
+ # This class is documented in TomDoc format. Since this is a subclass of the
35
+ # RDoc markup parser there isn't much to see here, unfortunately.
36
+
37
+ class RDoc::TomDoc < RDoc::Markup::Parser
38
+
39
+ # Internal: Token accessor
40
+
41
+ attr_reader :tokens
42
+
43
+ # Internal: Adds a post-processor which sets the RDoc section based on the
44
+ # comment's status.
45
+ #
46
+ # Returns nothing.
47
+
48
+ def self.add_post_processor # :nodoc:
49
+ RDoc::Markup::PreProcess.post_process do |comment, code_object|
50
+ next unless code_object and
51
+ RDoc::Comment === comment and comment.format == 'tomdoc'
52
+
53
+ comment.text.gsub!(/(\A\s*# )(Public|Internal|Deprecated):\s+/) do
54
+ section = code_object.add_section $2
55
+ code_object.temporary_section = section
56
+
57
+ $1
58
+ end
59
+ end
60
+ end
61
+
62
+ add_post_processor
63
+
64
+ # Public: Parses TomDoc from text
65
+ #
66
+ # text - A String containing TomDoc-format text.
67
+ #
68
+ # Examples
69
+ #
70
+ # RDoc::TomDoc.parse <<-TOMDOC
71
+ # This method does some things
72
+ #
73
+ # Returns nothing.
74
+ # TOMDOC
75
+ # # => #<RDoc::Markup::Document:0xXXX @parts=[...], @file=nil>
76
+ #
77
+ # Returns an RDoc::Markup::Document representing the TomDoc format.
78
+
79
+ def self.parse text
80
+ parser = new
81
+
82
+ parser.tokenize text
83
+ doc = RDoc::Markup::Document.new
84
+ parser.parse doc
85
+ doc
86
+ end
87
+
88
+ # Internal: Extracts the Signature section's method signature
89
+ #
90
+ # comment - An RDoc::Comment that will be parsed and have the signature
91
+ # extracted
92
+ #
93
+ # Returns a String containing the signature and nil if not
94
+
95
+ def self.signature comment
96
+ return unless comment.tomdoc?
97
+
98
+ document = comment.parse
99
+
100
+ signature = nil
101
+ found_heading = false
102
+ found_signature = false
103
+
104
+ document.parts.delete_if do |part|
105
+ next false if found_signature
106
+
107
+ found_heading ||=
108
+ RDoc::Markup::Heading === part && part.text == 'Signature'
109
+
110
+ next false unless found_heading
111
+
112
+ next true if RDoc::Markup::BlankLine === part
113
+
114
+ if RDoc::Markup::Verbatim === part then
115
+ signature = part
116
+ found_signature = true
117
+ end
118
+ end
119
+
120
+ signature and signature.text
121
+ end
122
+
123
+ # Public: Creates a new TomDoc parser. See also RDoc::Markup::parse
124
+
125
+ def initialize
126
+ super
127
+
128
+ @section = nil
129
+ end
130
+
131
+ # Internal: Builds a heading from the token stream
132
+ #
133
+ # level - The level of heading to create
134
+ #
135
+ # Returns an RDoc::Markup::Heading
136
+
137
+ def build_heading level
138
+ heading = super
139
+
140
+ @section = heading.text
141
+
142
+ heading
143
+ end
144
+
145
+ # Internal: Builds a verbatim from the token stream. A verbatim in the
146
+ # Examples section will be marked as in ruby format.
147
+ #
148
+ # margin - The indentation from the margin for lines that belong to this
149
+ # verbatim section.
150
+ #
151
+ # Returns an RDoc::Markup::Verbatim
152
+
153
+ def build_verbatim margin
154
+ verbatim = super
155
+
156
+ verbatim.format = :ruby if @section == 'Examples'
157
+
158
+ verbatim
159
+ end
160
+
161
+ # Internal: Builds a paragraph from the token stream
162
+ #
163
+ # margin - Unused
164
+ #
165
+ # Returns an RDoc::Markup::Paragraph.
166
+
167
+ def build_paragraph margin
168
+ p :paragraph_start => margin if @debug
169
+
170
+ paragraph = RDoc::Markup::Paragraph.new
171
+
172
+ until @tokens.empty? do
173
+ type, data, = get
174
+
175
+ if type == :TEXT then
176
+ paragraph << data
177
+ skip :NEWLINE
178
+ else
179
+ unget
180
+ break
181
+ end
182
+ end
183
+
184
+ p :paragraph_end => margin if @debug
185
+
186
+ paragraph
187
+ end
188
+
189
+ # Internal: Turns text into an Array of tokens
190
+ #
191
+ # text - A String containing TomDoc-format text.
192
+ #
193
+ # Returns self.
194
+
195
+ def tokenize text
196
+ text.sub!(/\A(Public|Internal|Deprecated):\s+/, '')
197
+
198
+ s = StringScanner.new text
199
+
200
+ @line = 0
201
+ @line_pos = 0
202
+
203
+ until s.eos? do
204
+ pos = s.pos
205
+
206
+ # leading spaces will be reflected by the column of the next token
207
+ # the only thing we loose are trailing spaces at the end of the file
208
+ next if s.scan(/ +/)
209
+
210
+ @tokens << case
211
+ when s.scan(/\r?\n/) then
212
+ token = [:NEWLINE, s.matched, *token_pos(pos)]
213
+ @line_pos = s.pos
214
+ @line += 1
215
+ token
216
+ when s.scan(/(Examples|Signature)$/) then
217
+ @tokens << [:HEADER, 3, *token_pos(pos)]
218
+
219
+ [:TEXT, s[1], *token_pos(pos)]
220
+ when s.scan(/([:\w]\w*)[ ]+- /) then
221
+ [:NOTE, s[1], *token_pos(pos)]
222
+ else
223
+ s.scan(/.*/)
224
+ [:TEXT, s.matched.sub(/\r$/, ''), *token_pos(pos)]
225
+ end
226
+ end
227
+
228
+ self
229
+ end
230
+
231
+ end
232
+