rdoc 6.17.0 → 8.1.0

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +193 -0
  3. data/LEGAL.rdoc +6 -0
  4. data/LICENSE.rdoc +4 -0
  5. data/README.md +132 -8
  6. data/RI.md +75 -75
  7. data/doc/markup_reference/markdown.md +659 -0
  8. data/doc/markup_reference/rdoc.rdoc +1169 -0
  9. data/exe/rdoc +2 -2
  10. data/lib/rdoc/code_object/alias.rb +70 -74
  11. data/lib/rdoc/code_object/any_method.rb +308 -293
  12. data/lib/rdoc/code_object/attr.rb +150 -142
  13. data/lib/rdoc/code_object/class_module.rb +802 -715
  14. data/lib/rdoc/code_object/constant.rb +181 -144
  15. data/lib/rdoc/code_object/context/section.rb +140 -130
  16. data/lib/rdoc/code_object/context.rb +925 -941
  17. data/lib/rdoc/code_object/extend.rb +7 -5
  18. data/lib/rdoc/code_object/include.rb +7 -5
  19. data/lib/rdoc/code_object/method_attr.rb +328 -315
  20. data/lib/rdoc/code_object/mixin.rb +97 -92
  21. data/lib/rdoc/code_object/normal_class.rb +77 -78
  22. data/lib/rdoc/code_object/normal_module.rb +61 -59
  23. data/lib/rdoc/code_object/require.rb +23 -39
  24. data/lib/rdoc/code_object/single_class.rb +21 -19
  25. data/lib/rdoc/code_object/top_level.rb +215 -202
  26. data/lib/rdoc/code_object.rb +305 -305
  27. data/lib/rdoc/comment.rb +274 -337
  28. data/lib/rdoc/cross_reference.rb +195 -206
  29. data/lib/rdoc/encoding.rb +105 -103
  30. data/lib/rdoc/erb_partial.rb +13 -11
  31. data/lib/rdoc/erbio.rb +29 -27
  32. data/lib/rdoc/generator/aliki.rb +196 -30
  33. data/lib/rdoc/generator/darkfish.rb +647 -629
  34. data/lib/rdoc/generator/json_index.rb +233 -229
  35. data/lib/rdoc/generator/markup.rb +165 -122
  36. data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
  37. data/lib/rdoc/generator/pot/po.rb +52 -51
  38. data/lib/rdoc/generator/pot/po_entry.rb +138 -132
  39. data/lib/rdoc/generator/pot.rb +85 -81
  40. data/lib/rdoc/generator/ri.rb +23 -19
  41. data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
  42. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
  43. data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
  44. data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
  45. data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
  46. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
  47. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
  48. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
  49. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
  50. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
  51. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
  52. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
  53. data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
  54. data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
  55. data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
  56. data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
  57. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  58. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
  59. data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
  60. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  61. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  62. data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
  63. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
  64. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
  65. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
  66. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
  67. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
  68. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
  69. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
  70. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
  71. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
  72. data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
  73. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
  74. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
  75. data/lib/rdoc/generator.rb +48 -46
  76. data/lib/rdoc/i18n/locale.rb +99 -95
  77. data/lib/rdoc/i18n/text.rb +109 -105
  78. data/lib/rdoc/i18n.rb +7 -5
  79. data/lib/rdoc/markdown/byte_runtime.rb +80 -0
  80. data/lib/rdoc/markdown.kpeg +52 -33
  81. data/lib/rdoc/markdown.rb +365 -177
  82. data/lib/rdoc/markup/blank_line.rb +25 -23
  83. data/lib/rdoc/markup/block_quote.rb +12 -8
  84. data/lib/rdoc/markup/document.rb +127 -123
  85. data/lib/rdoc/markup/element.rb +21 -0
  86. data/lib/rdoc/markup/formatter.rb +220 -203
  87. data/lib/rdoc/markup/hard_break.rb +30 -27
  88. data/lib/rdoc/markup/heading.rb +163 -77
  89. data/lib/rdoc/markup/include.rb +33 -29
  90. data/lib/rdoc/markup/indented_paragraph.rb +37 -33
  91. data/lib/rdoc/markup/inline_parser.rb +316 -0
  92. data/lib/rdoc/markup/list.rb +80 -88
  93. data/lib/rdoc/markup/list_item.rb +73 -85
  94. data/lib/rdoc/markup/paragraph.rb +23 -19
  95. data/lib/rdoc/markup/parser.rb +501 -497
  96. data/lib/rdoc/markup/pre_process.rb +284 -305
  97. data/lib/rdoc/markup/raw.rb +52 -55
  98. data/lib/rdoc/markup/rule.rb +16 -12
  99. data/lib/rdoc/markup/table.rb +48 -40
  100. data/lib/rdoc/markup/to_ansi.rb +143 -92
  101. data/lib/rdoc/markup/to_bs.rb +86 -102
  102. data/lib/rdoc/markup/to_html.rb +608 -506
  103. data/lib/rdoc/markup/to_html_crossref.rb +219 -210
  104. data/lib/rdoc/markup/to_html_snippet.rb +210 -205
  105. data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
  106. data/lib/rdoc/markup/to_label.rb +64 -51
  107. data/lib/rdoc/markup/to_markdown.rb +212 -184
  108. data/lib/rdoc/markup/to_rdoc.rb +341 -277
  109. data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
  110. data/lib/rdoc/markup/to_test.rb +62 -50
  111. data/lib/rdoc/markup/to_tt_only.rb +83 -92
  112. data/lib/rdoc/markup/verbatim.rb +62 -58
  113. data/lib/rdoc/markup.rb +196 -215
  114. data/lib/rdoc/options.rb +1063 -1076
  115. data/lib/rdoc/parser/c.rb +1039 -1036
  116. data/lib/rdoc/parser/changelog.rb +320 -287
  117. data/lib/rdoc/parser/markdown.rb +17 -13
  118. data/lib/rdoc/parser/rbs.rb +279 -0
  119. data/lib/rdoc/parser/rd.rb +17 -13
  120. data/lib/rdoc/parser/ruby.rb +1231 -2222
  121. data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
  122. data/lib/rdoc/parser/simple.rb +31 -27
  123. data/lib/rdoc/parser/text.rb +12 -8
  124. data/lib/rdoc/parser.rb +230 -221
  125. data/lib/rdoc/rbs_helper.rb +186 -0
  126. data/lib/rdoc/rd/inline.rb +57 -53
  127. data/lib/rdoc/rd.rb +90 -88
  128. data/lib/rdoc/rdoc.rb +547 -366
  129. data/lib/rdoc/ri/driver.rb +1141 -1130
  130. data/lib/rdoc/ri/formatter.rb +7 -3
  131. data/lib/rdoc/ri/paths.rb +140 -136
  132. data/lib/rdoc/ri/servlet.rb +456 -0
  133. data/lib/rdoc/ri/store.rb +4 -2
  134. data/lib/rdoc/ri/task.rb +55 -51
  135. data/lib/rdoc/ri.rb +14 -11
  136. data/lib/rdoc/rubygems_hook.rb +194 -192
  137. data/lib/rdoc/server.rb +462 -0
  138. data/lib/rdoc/stats/normal.rb +46 -42
  139. data/lib/rdoc/stats/quiet.rb +39 -35
  140. data/lib/rdoc/stats/verbose.rb +35 -31
  141. data/lib/rdoc/stats.rb +363 -338
  142. data/lib/rdoc/store.rb +919 -725
  143. data/lib/rdoc/task.rb +260 -255
  144. data/lib/rdoc/text.rb +164 -240
  145. data/lib/rdoc/token_stream.rb +88 -106
  146. data/lib/rdoc/tom_doc.rb +203 -201
  147. data/lib/rdoc/version.rb +1 -1
  148. data/lib/rdoc.rb +35 -7
  149. data/lib/rubygems_plugin.rb +2 -11
  150. data/rdoc-logo.svg +43 -0
  151. data/rdoc.gemspec +9 -7
  152. metadata +46 -32
  153. data/CONTRIBUTING.rdoc +0 -219
  154. data/ExampleMarkdown.md +0 -39
  155. data/ExampleRDoc.rdoc +0 -210
  156. data/lib/rdoc/code_object/anon_class.rb +0 -10
  157. data/lib/rdoc/code_object/ghost_method.rb +0 -6
  158. data/lib/rdoc/code_object/meta_method.rb +0 -6
  159. data/lib/rdoc/markdown/literals.kpeg +0 -21
  160. data/lib/rdoc/markdown/literals.rb +0 -454
  161. data/lib/rdoc/markup/attr_changer.rb +0 -22
  162. data/lib/rdoc/markup/attr_span.rb +0 -35
  163. data/lib/rdoc/markup/attribute_manager.rb +0 -405
  164. data/lib/rdoc/markup/attributes.rb +0 -70
  165. data/lib/rdoc/markup/regexp_handling.rb +0 -40
  166. data/lib/rdoc/parser/prism_ruby.rb +0 -1100
  167. data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
  168. data/lib/rdoc/parser/ruby_tools.rb +0 -163
  169. data/lib/rdoc/servlet.rb +0 -452
@@ -1,130 +1,112 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ##
4
- # A TokenStream is a list of tokens, gathered during the parse of some entity
5
- # (say a method). Entities populate these streams by being registered with the
6
- # lexer. Any class can collect tokens by including TokenStream. From the
7
- # outside, you use such an object by calling the start_collecting_tokens
8
- # method, followed by calls to add_token and pop_token.
9
-
10
- module RDoc::TokenStream
11
-
3
+ module RDoc
12
4
  ##
13
- # Converts +token_stream+ to HTML wrapping various tokens with
14
- # <tt><span></tt> elements. Some tokens types are wrapped in spans
15
- # with the given class names. Other token types are not wrapped in spans.
16
-
17
- def self.to_html(token_stream)
18
- starting_title = false
19
-
20
- token_stream.map do |t|
21
- next unless t
22
-
23
- style = case t[:kind]
24
- when :on_const then 'ruby-constant'
25
- when :on_kw then 'ruby-keyword'
26
- when :on_ivar then 'ruby-ivar'
27
- when :on_cvar then 'ruby-identifier'
28
- when :on_gvar then 'ruby-identifier'
29
- when '=' != t[:text] && :on_op
30
- then 'ruby-operator'
31
- when :on_tlambda then 'ruby-operator'
32
- when :on_ident then 'ruby-identifier'
33
- when :on_label then 'ruby-value'
34
- when :on_backref, :on_dstring
35
- then 'ruby-node'
36
- when :on_comment then 'ruby-comment'
37
- when :on_embdoc then 'ruby-comment'
38
- when :on_regexp then 'ruby-regexp'
39
- when :on_tstring then 'ruby-string'
40
- when :on_int, :on_float,
41
- :on_rational, :on_imaginary,
42
- :on_heredoc,
43
- :on_symbol, :on_CHAR then 'ruby-value'
44
- when :on_heredoc_beg, :on_heredoc_end
45
- then 'ruby-identifier'
46
- end
47
-
48
- comment_with_nl = false
49
- if :on_comment == t[:kind] or :on_embdoc == t[:kind] or :on_heredoc_end == t[:kind]
50
- comment_with_nl = true if "\n" == t[:text][-1]
51
- text = t[:text].rstrip
52
- else
53
- text = t[:text]
54
- end
5
+ # A TokenStream is a list of tokens, gathered during the parse of some entity
6
+ # (say a method). Entities populate these streams by being registered with the
7
+ # lexer. Any class can collect tokens by including TokenStream. From the
8
+ # outside, you use such an object by calling the start_collecting_tokens
9
+ # method, followed by calls to add_token and pop_token.
10
+
11
+ module TokenStream
12
+
13
+ ##
14
+ # Converts +token_stream+ to HTML wrapping various tokens with
15
+ # <tt><span></tt> elements. Some tokens types are wrapped in spans
16
+ # with the given class names. Other token types are not wrapped in spans.
17
+
18
+ def self.to_html(token_stream)
19
+ token_stream.map do |t|
20
+ next unless t
21
+
22
+ style = case t[:kind]
23
+ when :operator then 'ruby-operator'
24
+ when :keyword then 'ruby-keyword'
25
+ when :constant then 'ruby-constant'
26
+ when :ivar then 'ruby-ivar'
27
+ when :comment then 'ruby-comment'
28
+ when :value then 'ruby-value'
29
+ when :string then 'ruby-string'
30
+ when :symbol then 'ruby-value'
31
+ when :x_string then 'ruby-string'
32
+ when :regexp then 'ruby-regexp'
33
+ when :identifier then 'ruby-identifier'
34
+ end
55
35
 
56
- if :on_ident == t[:kind] && starting_title
57
- starting_title = false
58
- style = 'ruby-identifier ruby-title'
59
- end
36
+ text = t[:text]
60
37
 
61
- if :on_kw == t[:kind] and 'def' == t[:text]
62
- starting_title = true
63
- end
38
+ text = CGI.escapeHTML text
64
39
 
65
- text = CGI.escapeHTML text
40
+ if style
41
+ end_with_newline = text.end_with?("\n")
42
+ text = text.chomp if end_with_newline
43
+ "<span class=\"#{style}\">#{text}</span>#{"\n" if end_with_newline}"
44
+ else
45
+ text
46
+ end
47
+ end.join
48
+ end
66
49
 
67
- if style then
68
- "<span class=\"#{style}\">#{text}</span>#{"\n" if comment_with_nl}"
69
- else
70
- text
71
- end
72
- end.join
73
- end
50
+ ##
51
+ # Adds +tokens+ to the collected tokens
74
52
 
75
- ##
76
- # Adds +tokens+ to the collected tokens
53
+ def add_tokens(tokens)
54
+ token_stream.concat(tokens)
55
+ end
77
56
 
78
- def add_tokens(tokens)
79
- @token_stream.concat(tokens)
80
- end
57
+ ##
58
+ # Adds one +token+ to the collected tokens
81
59
 
82
- ##
83
- # Adds one +token+ to the collected tokens
60
+ def add_token(token)
61
+ token_stream.push(token)
62
+ end
84
63
 
85
- def add_token(token)
86
- @token_stream.push(token)
87
- end
64
+ ##
65
+ # Starts collecting tokens
66
+ #
67
+ # The optional +loader+ is called once on first access and its result is reused.
88
68
 
89
- ##
90
- # Starts collecting tokens
91
- #
69
+ def collect_tokens(language, loader: nil)
70
+ @token_stream = []
71
+ @token_stream_loader = loader
72
+ @token_stream_language = language
73
+ end
92
74
 
93
- def collect_tokens(language)
94
- @token_stream = []
95
- @token_stream_language = language
96
- end
75
+ alias start_collecting_tokens collect_tokens
97
76
 
98
- alias start_collecting_tokens collect_tokens
77
+ ##
78
+ # Remove the last token from the collected tokens
99
79
 
100
- ##
101
- # Remove the last token from the collected tokens
80
+ def pop_token
81
+ token_stream.pop
82
+ end
102
83
 
103
- def pop_token
104
- @token_stream.pop
105
- end
84
+ ##
85
+ # Current token stream
106
86
 
107
- ##
108
- # Current token stream
87
+ def token_stream
88
+ if @token_stream_loader
89
+ @token_stream = @token_stream_loader.call
90
+ @token_stream_loader = nil
91
+ end
92
+ @token_stream
93
+ end
109
94
 
110
- def token_stream
111
- @token_stream
112
- end
95
+ ##
96
+ # Returns a string representation of the token stream
113
97
 
114
- ##
115
- # Returns a string representation of the token stream
98
+ def tokens_to_s
99
+ (token_stream or return '').compact.map { |token| token[:text] }.join ''
100
+ end
116
101
 
117
- def tokens_to_s
118
- (token_stream or return '').compact.map { |token| token[:text] }.join ''
119
- end
102
+ ##
103
+ # Returns the source language of the token stream as a string
104
+ #
105
+ # Returns 'c' or 'ruby'
120
106
 
121
- ##
122
- # Returns the source language of the token stream as a string
123
- #
124
- # Returns 'c' or 'ruby'
107
+ def source_language
108
+ @token_stream_language == :c ? 'c' : 'ruby'
109
+ end
125
110
 
126
- def source_language
127
- @token_stream_language == :c ? 'c' : 'ruby'
128
111
  end
129
-
130
112
  end
data/lib/rdoc/tom_doc.rb CHANGED
@@ -1,257 +1,259 @@
1
1
  # frozen_string_literal: true
2
2
  # :markup: tomdoc
3
3
 
4
- # A parser for TomDoc based on TomDoc 1.0.0-rc1 (02adef9b5a)
5
- #
6
- # The TomDoc specification can be found at http://tomdoc.org.
7
- #
8
- # To choose TomDoc as your only default format see RDoc::Options@Saved+Options
9
- # for instructions on setting up a <code>.rdoc_options</code> file to store
10
- # your project default.
11
- #
12
- # There are a few differences between this parser and the specification. A
13
- # best-effort was made to follow the specification as closely as possible but
14
- # some choices to deviate were made.
15
- #
16
- # A future version of RDoc will warn when a MUST or MUST NOT is violated and
17
- # may warn when a SHOULD or SHOULD NOT is violated. RDoc will always try
18
- # to emit documentation even if given invalid TomDoc.
19
- #
20
- # Here are some implementation choices this parser currently makes:
21
- #
22
- # This parser allows rdoc-style inline markup but you should not depended on
23
- # it.
24
- #
25
- # This parser allows a space between the comment and the method body.
26
- #
27
- # This parser does not require the default value to be described for an
28
- # optional argument.
29
- #
30
- # This parser does not examine the order of sections. An Examples section may
31
- # precede the Arguments section.
32
- #
33
- # This class is documented in TomDoc format. Since this is a subclass of the
34
- # RDoc markup parser there isn't much to see here, unfortunately.
35
-
36
- class RDoc::TomDoc < RDoc::Markup::Parser
37
-
38
- # Internal: Token accessor
39
-
40
- attr_reader :tokens
41
-
42
- # Internal: Adds a post-processor which sets the RDoc section based on the
43
- # comment's status.
4
+ module RDoc
5
+ # A parser for TomDoc based on TomDoc 1.0.0-rc1 (02adef9b5a)
44
6
  #
45
- # Returns nothing.
46
-
47
- def self.add_post_processor # :nodoc:
48
- RDoc::Markup::PreProcess.post_process do |comment, code_object|
49
- next unless code_object and
50
- RDoc::Comment === comment and comment.format == 'tomdoc'
51
-
52
- comment.text.gsub!(/\A(\s*# |)(Public|Internal|Deprecated):\s+/) do
53
- section = code_object.add_section $2
54
- code_object.temporary_section = section
55
-
56
- $1
57
- end
58
- end
59
- end
60
-
61
- add_post_processor
62
-
63
- # Public: Parses TomDoc from text
7
+ # The TomDoc specification can be found at http://tomdoc.org.
64
8
  #
65
- # text - A String containing TomDoc-format text.
9
+ # To choose TomDoc as your only default format see RDoc::Options@Saved+Options
10
+ # for instructions on setting up a <code>.rdoc_options</code> file to store
11
+ # your project default.
66
12
  #
67
- # Examples
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.
68
16
  #
69
- # RDoc::TomDoc.parse <<-TOMDOC
70
- # This method does some things
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.
71
20
  #
72
- # Returns nothing.
73
- # TOMDOC
74
- # # => #<RDoc::Markup::Document:0xXXX @parts=[...], @file=nil>
21
+ # Here are some implementation choices this parser currently makes:
75
22
  #
76
- # Returns an RDoc::Markup::Document representing the TomDoc format.
77
-
78
- def self.parse(text)
79
- parser = new
80
-
81
- parser.tokenize text
82
- doc = RDoc::Markup::Document.new
83
- parser.parse doc
84
- doc
85
- end
86
-
87
- # Internal: Extracts the Signature section's method signature
23
+ # This parser allows rdoc-style inline markup but you should not depended on
24
+ # it.
88
25
  #
89
- # comment - An RDoc::Comment that will be parsed and have the signature
90
- # extracted
26
+ # This parser allows a space between the comment and the method body.
91
27
  #
92
- # Returns a String containing the signature and nil if not
93
-
94
- def self.signature(comment)
95
- return unless comment.tomdoc?
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.
96
36
 
97
- document = comment.parse
37
+ class TomDoc < Markup::Parser
98
38
 
99
- signature = nil
100
- found_heading = false
101
- found_signature = false
39
+ # Internal: Token accessor
102
40
 
103
- document.parts.delete_if do |part|
104
- next false if found_signature
41
+ attr_reader :tokens
105
42
 
106
- found_heading ||=
107
- RDoc::Markup::Heading === part && part.text == 'Signature'
43
+ # Internal: Adds a post-processor which sets the RDoc section based on the
44
+ # comment's status.
45
+ #
46
+ # Returns nothing.
108
47
 
109
- next false unless found_heading
48
+ def self.add_post_processor # :nodoc:
49
+ Markup::PreProcess.post_process do |comment, code_object|
50
+ next unless code_object and
51
+ Comment === comment and comment.format == 'tomdoc'
110
52
 
111
- next true if RDoc::Markup::BlankLine === part
53
+ comment.text.gsub!(/\A(\s*# |)(Public|Internal|Deprecated):\s+/) do
54
+ section = code_object.add_section $2
55
+ code_object.temporary_section = section
112
56
 
113
- if RDoc::Markup::Verbatim === part then
114
- signature = part
115
- found_signature = true
57
+ $1
58
+ end
116
59
  end
117
60
  end
118
61
 
119
- signature and signature.text
120
- end
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 = Markup::Document.new
84
+ parser.parse doc
85
+ doc
86
+ end
121
87
 
122
- # Public: Creates a new TomDoc parser. See also RDoc::Markup::parse
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
123
94
 
124
- def initialize
125
- super
95
+ def self.signature(comment)
96
+ return unless comment.tomdoc?
126
97
 
127
- @section = nil
128
- @seen_returns = false
129
- end
98
+ document = comment.parse
130
99
 
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
100
+ signature = nil
101
+ found_heading = false
102
+ found_signature = false
136
103
 
137
- def build_heading(level)
138
- heading = super
104
+ document.parts.delete_if do |part|
105
+ next false if found_signature
139
106
 
140
- @section = heading.text
107
+ found_heading ||=
108
+ Markup::Heading === part && part.text == 'Signature'
141
109
 
142
- heading
143
- end
110
+ next false unless found_heading
144
111
 
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
112
+ next true if Markup::BlankLine === part
113
+
114
+ if Markup::Verbatim === part
115
+ signature = part
116
+ found_signature = true
117
+ end
118
+ end
152
119
 
153
- def build_verbatim(margin)
154
- verbatim = super
120
+ signature and signature.text
121
+ end
155
122
 
156
- verbatim.format = :ruby if @section == 'Examples'
123
+ # Public: Creates a new TomDoc parser. See also RDoc::Markup::parse
157
124
 
158
- verbatim
159
- end
125
+ def initialize
126
+ super
160
127
 
161
- # Internal: Builds a paragraph from the token stream
162
- #
163
- # margin - Unused
164
- #
165
- # Returns an RDoc::Markup::Paragraph.
128
+ @section = nil
129
+ @seen_returns = false
130
+ end
166
131
 
167
- def build_paragraph(margin)
168
- p :paragraph_start => margin if @debug
132
+ # Internal: Builds a heading from the token stream
133
+ #
134
+ # level - The level of heading to create
135
+ #
136
+ # Returns an RDoc::Markup::Heading
169
137
 
170
- paragraph = RDoc::Markup::Paragraph.new
138
+ def build_heading(level)
139
+ heading = super
171
140
 
172
- until @tokens.empty? do
173
- type, data, = get
141
+ @section = heading.text
174
142
 
175
- case type
176
- when :TEXT then
177
- @section = 'Returns' if data =~ /\A(Returns|Raises)/
143
+ heading
144
+ end
178
145
 
179
- paragraph << data
180
- when :NEWLINE then
181
- if :TEXT == peek_token[0] then
182
- # Lines beginning with 'Raises' in the Returns section should not be
183
- # treated as multiline text
184
- if 'Returns' == @section and
185
- peek_token[1].start_with?('Raises') then
186
- break
146
+ # Internal: Builds a verbatim from the token stream. A verbatim in the
147
+ # Examples section will be marked as in Ruby format.
148
+ #
149
+ # margin - The indentation from the margin for lines that belong to this
150
+ # verbatim section.
151
+ #
152
+ # Returns an RDoc::Markup::Verbatim
153
+
154
+ def build_verbatim(margin)
155
+ verbatim = super
156
+
157
+ verbatim.format = :ruby if @section == 'Examples'
158
+
159
+ verbatim
160
+ end
161
+
162
+ # Internal: Builds a paragraph from the token stream
163
+ #
164
+ # margin - Unused
165
+ #
166
+ # Returns an RDoc::Markup::Paragraph.
167
+
168
+ def build_paragraph(margin)
169
+ p :paragraph_start => margin if @debug
170
+
171
+ paragraph = Markup::Paragraph.new
172
+
173
+ until @tokens.empty? do
174
+ type, data, = get
175
+
176
+ case type
177
+ when :TEXT
178
+ @section = 'Returns' if data =~ /\A(Returns|Raises)/
179
+
180
+ paragraph << data
181
+ when :NEWLINE
182
+ if :TEXT == peek_token[0]
183
+ # Lines beginning with 'Raises' in the Returns section should not be
184
+ # treated as multiline text
185
+ if 'Returns' == @section and
186
+ peek_token[1].start_with?('Raises')
187
+ break
188
+ else
189
+ paragraph << ' '
190
+ end
187
191
  else
188
- paragraph << ' '
192
+ break
189
193
  end
190
194
  else
195
+ unget
191
196
  break
192
197
  end
193
- else
194
- unget
195
- break
196
198
  end
197
- end
198
199
 
199
- p :paragraph_end => margin if @debug
200
+ p :paragraph_end => margin if @debug
200
201
 
201
- paragraph
202
- end
202
+ paragraph
203
+ end
204
+
205
+ ##
206
+ # Detects a section change to "Returns" and adds a heading
203
207
 
204
- ##
205
- # Detects a section change to "Returns" and adds a heading
208
+ def parse_text(parent, indent) # :nodoc:
209
+ paragraph = build_paragraph indent
206
210
 
207
- def parse_text(parent, indent) # :nodoc:
208
- paragraph = build_paragraph indent
211
+ if false == @seen_returns and 'Returns' == @section
212
+ @seen_returns = true
213
+ parent << Markup::Heading.new(3, 'Returns')
214
+ parent << Markup::BlankLine.new
215
+ end
209
216
 
210
- if false == @seen_returns and 'Returns' == @section then
211
- @seen_returns = true
212
- parent << RDoc::Markup::Heading.new(3, 'Returns')
213
- parent << RDoc::Markup::BlankLine.new
217
+ parent << paragraph
214
218
  end
215
219
 
216
- parent << paragraph
217
- end
220
+ # Internal: Turns text into an Array of tokens
221
+ #
222
+ # text - A String containing TomDoc-format text.
223
+ #
224
+ # Returns self.
225
+
226
+ def tokenize(text)
227
+ text = text.sub(/\A(Public|Internal|Deprecated):\s+/, '')
228
+
229
+ setup_scanner text
230
+
231
+ until @s.eos? do
232
+ pos = @s.pos
233
+
234
+ # leading spaces will be reflected by the column of the next token
235
+ # the only thing we loose are trailing spaces at the end of the file
236
+ next if @s.scan(/ +/)
237
+
238
+ @tokens << case
239
+ when @s.scan(/\r?\n/)
240
+ token = [:NEWLINE, @s.matched, *pos]
241
+ @s.newline!
242
+ token
243
+ when @s.scan(/(Examples|Signature)$/)
244
+ @tokens << [:HEADER, 3, *pos]
245
+
246
+ [:TEXT, @s[1], *pos]
247
+ when @s.scan(/([:\w][\w\[\]]*)[ ]+- /)
248
+ [:NOTE, @s[1], *pos]
249
+ else
250
+ @s.scan(/.*/)
251
+ [:TEXT, @s.matched.sub(/\r$/, ''), *pos]
252
+ end
253
+ end
218
254
 
219
- # Internal: Turns text into an Array of tokens
220
- #
221
- # text - A String containing TomDoc-format text.
222
- #
223
- # Returns self.
224
-
225
- def tokenize(text)
226
- text = text.sub(/\A(Public|Internal|Deprecated):\s+/, '')
227
-
228
- setup_scanner text
229
-
230
- until @s.eos? do
231
- pos = @s.pos
232
-
233
- # leading spaces will be reflected by the column of the next token
234
- # the only thing we loose are trailing spaces at the end of the file
235
- next if @s.scan(/ +/)
236
-
237
- @tokens << case
238
- when @s.scan(/\r?\n/) then
239
- token = [:NEWLINE, @s.matched, *pos]
240
- @s.newline!
241
- token
242
- when @s.scan(/(Examples|Signature)$/) then
243
- @tokens << [:HEADER, 3, *pos]
244
-
245
- [:TEXT, @s[1], *pos]
246
- when @s.scan(/([:\w][\w\[\]]*)[ ]+- /) then
247
- [:NOTE, @s[1], *pos]
248
- else
249
- @s.scan(/.*/)
250
- [:TEXT, @s.matched.sub(/\r$/, ''), *pos]
251
- end
255
+ self
252
256
  end
253
257
 
254
- self
255
258
  end
256
-
257
259
  end