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,22 @@
1
+ ##
2
+ # Parse a RD format file. The parsed RDoc::Markup::Document is attached as a
3
+ # file comment.
4
+
5
+ class RDoc::Parser::RD < RDoc::Parser
6
+
7
+ include RDoc::Parser::Text
8
+
9
+ parse_files_matching(/\.rd(?:\.[^.]+)?$/)
10
+
11
+ ##
12
+ # Creates an rd-format TopLevel for the given file.
13
+
14
+ def scan
15
+ comment = RDoc::Comment.new @content, @top_level
16
+ comment.format = 'rd'
17
+
18
+ @top_level.comment = comment
19
+ end
20
+
21
+ end
22
+
@@ -7,15 +7,6 @@
7
7
  # by Keiju ISHITSUKA (Nippon Rational Inc.)
8
8
  #
9
9
 
10
- require 'rdoc/ruby_token'
11
- require 'rdoc/ruby_lex'
12
-
13
- require 'rdoc/code_objects'
14
- require 'rdoc/token_stream'
15
- require 'rdoc/markup/pre_process'
16
- require 'rdoc/parser'
17
- require 'rdoc/parser/ruby_tools'
18
-
19
10
  $TOKEN_DEBUG ||= nil
20
11
 
21
12
  ##
@@ -173,6 +164,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
173
164
  @scanner = RDoc::RubyLex.new content, @options
174
165
  @scanner.exception_on_syntax_error = false
175
166
  @prev_seek = nil
167
+ @markup = @options.markup
176
168
 
177
169
  @encoding = nil
178
170
  @encoding = @options.encoding if Object.const_defined? :Encoding
@@ -213,7 +205,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
213
205
 
214
206
  unget_tk tk
215
207
 
216
- comment
208
+ new_comment comment
217
209
  end
218
210
 
219
211
  ##
@@ -225,22 +217,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
225
217
  abort msg
226
218
  end
227
219
 
228
- ##
229
- # Look for a 'call-seq' in the comment, and override the normal parameter
230
- # stuff
231
- #--
232
- # TODO handle undent
233
-
234
- def extract_call_seq(comment, meth)
235
- if comment.sub!(/:?call-seq:(.*?)(^\s*#?\s*$|\z)/m, '') then
236
- seq = $1
237
- seq.gsub!(/^\s*\#\s*/, '')
238
- meth.call_seq = seq
239
- end
240
-
241
- meth
242
- end
243
-
244
220
  ##
245
221
  # Looks for a true or false token. Returns false if TkFALSE or TkNIL are
246
222
  # found.
@@ -412,8 +388,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
412
388
  'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
413
389
  false # handled elsewhere
414
390
  when 'section' then
415
- context.set_current_section param, comment
416
- comment.replace ''
391
+ context.set_current_section param, comment.dup
392
+ comment.text = ''
417
393
  break
418
394
  end
419
395
  end
@@ -432,6 +408,15 @@ class RDoc::Parser::Ruby < RDoc::Parser
432
408
  "#{prefix} #{message}"
433
409
  end
434
410
 
411
+ ##
412
+ # Creates a comment with the correct format
413
+
414
+ def new_comment comment
415
+ c = RDoc::Comment.new comment, @top_level
416
+ c.format = @markup
417
+ c
418
+ end
419
+
435
420
  ##
436
421
  # Creates an RDoc::Attr for the name following +tk+, setting the comment to
437
422
  # +comment+.
@@ -751,15 +736,18 @@ class RDoc::Parser::Ruby < RDoc::Parser
751
736
  # Generates an RDoc::Method or RDoc::Attr from +comment+ by looking for
752
737
  # :method: or :attr: directives in +comment+.
753
738
 
754
- def parse_comment(container, tk, comment)
739
+ def parse_comment container, tk, comment
740
+ return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
755
741
  column = tk.char_no
756
742
  offset = tk.seek
757
743
  line_no = tk.line_no
758
744
 
759
- singleton = !!comment.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
745
+ text = comment.text
746
+
747
+ singleton = !!text.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
760
748
 
761
749
  # REFACTOR
762
- if comment.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
750
+ if text.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
763
751
  name = $1 unless $1.empty?
764
752
 
765
753
  meth = RDoc::GhostMethod.new get_tkread, name
@@ -769,16 +757,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
769
757
  meth.line = line_no
770
758
 
771
759
  meth.start_collecting_tokens
772
- indent = TkSPACE.new nil, 1, 1
760
+ indent = TkSPACE.new 0, 1, 1
773
761
  indent.set_text " " * column
774
762
 
775
- position_comment = TkCOMMENT.new nil, line_no, 1
763
+ position_comment = TkCOMMENT.new 0, line_no, 1
776
764
  position_comment.set_text "# File #{@top_level.absolute_name}, line #{line_no}"
777
765
  meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
778
766
 
779
767
  meth.params = ''
780
768
 
781
- extract_call_seq comment, meth
769
+ comment.normalize
770
+ comment.extract_call_seq meth
782
771
 
783
772
  return unless meth.name
784
773
 
@@ -787,7 +776,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
787
776
  meth.comment = comment
788
777
 
789
778
  @stats.add_method meth
790
- elsif comment.sub!(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
779
+ elsif text.sub!(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
791
780
  rw = case $1
792
781
  when 'attr_reader' then 'R'
793
782
  when 'attr_writer' then 'W'
@@ -809,6 +798,43 @@ class RDoc::Parser::Ruby < RDoc::Parser
809
798
  true
810
799
  end
811
800
 
801
+ ##
802
+ # Creates an RDoc::Method on +container+ from +comment+ if there is a
803
+ # Signature section in the comment
804
+
805
+ def parse_comment_tomdoc container, tk, comment
806
+ return unless signature = RDoc::TomDoc.signature(comment)
807
+ offset = tk.seek
808
+ line_no = tk.line_no
809
+
810
+ name, = signature.split %r%[ \(]%, 2
811
+
812
+ meth = RDoc::GhostMethod.new get_tkread, name
813
+ meth.record_location @top_level
814
+ meth.offset = offset
815
+ meth.line = line_no
816
+
817
+ meth.start_collecting_tokens
818
+ indent = TkSPACE.new 0, 1, 1
819
+ indent.set_text " " * offset
820
+
821
+ position_comment = TkCOMMENT.new 0, line_no, 1
822
+ position_comment.set_text "# File #{@top_level.absolute_name}, line #{line_no}"
823
+ meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
824
+
825
+ meth.call_seq = signature
826
+
827
+ comment.normalize
828
+
829
+ return unless meth.name
830
+
831
+ container.add_method meth
832
+
833
+ meth.comment = comment
834
+
835
+ @stats.add_method meth
836
+ end
837
+
812
838
  ##
813
839
  # Parses an +include+ in +context+ with +comment+
814
840
 
@@ -867,7 +893,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
867
893
  tmp = RDoc::CodeObject.new
868
894
  read_documentation_modifiers tmp, RDoc::ATTR_MODIFIERS
869
895
 
870
- if comment.sub!(/^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
896
+ if comment.text.sub!(/^# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '') then
871
897
  rw = case $1
872
898
  when 'attr_reader' then 'R'
873
899
  when 'attr_writer' then 'W'
@@ -908,9 +934,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
908
934
 
909
935
  skip_tkspace false
910
936
 
911
- singleton = !!comment.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
937
+ singleton = !!comment.text.sub!(/(^# +:?)(singleton-)(method:)/, '\1\3')
912
938
 
913
- if comment.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
939
+ if comment.text.sub!(/^# +:?method: *(\S*).*?\n/i, '') then
914
940
  name = $1 unless $1.empty?
915
941
  end
916
942
 
@@ -939,10 +965,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
939
965
  remove_token_listener self
940
966
 
941
967
  meth.start_collecting_tokens
942
- indent = TkSPACE.new nil, 1, 1
968
+ indent = TkSPACE.new 0, 1, 1
943
969
  indent.set_text " " * column
944
970
 
945
- position_comment = TkCOMMENT.new nil, line_no, 1
971
+ position_comment = TkCOMMENT.new 0, line_no, 1
946
972
  position_comment.value = "# File #{@top_level.absolute_name}, line #{line_no}"
947
973
  meth.add_tokens [position_comment, NEWLINE_TOKEN, indent]
948
974
  meth.add_tokens @token_stream
@@ -950,7 +976,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
950
976
  token_listener meth do
951
977
  meth.params = ''
952
978
 
953
- extract_call_seq comment, meth
979
+ comment.normalize
980
+ comment.extract_call_seq meth
954
981
 
955
982
  container.add_method meth
956
983
 
@@ -1084,10 +1111,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
1084
1111
  meth.line = line_no
1085
1112
 
1086
1113
  meth.start_collecting_tokens
1087
- indent = TkSPACE.new nil, 1, 1
1114
+ indent = TkSPACE.new 0, 1, 1
1088
1115
  indent.set_text " " * column
1089
1116
 
1090
- token = TkCOMMENT.new nil, line_no, 1
1117
+ token = TkCOMMENT.new 0, line_no, 1
1091
1118
  token.set_text "# File #{@top_level.absolute_name}, line #{line_no}"
1092
1119
  meth.add_tokens [token, NEWLINE_TOKEN, indent]
1093
1120
  meth.add_tokens @token_stream
@@ -1118,7 +1145,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
1118
1145
  parse_statements container, single, meth
1119
1146
  end
1120
1147
 
1121
- extract_call_seq comment, meth
1148
+ comment.normalize
1149
+ comment.extract_call_seq meth
1122
1150
 
1123
1151
  meth.comment = comment
1124
1152
 
@@ -1253,7 +1281,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
1253
1281
  # The core of the ruby parser.
1254
1282
 
1255
1283
  def parse_statements(container, single = NORMAL, current_method = nil,
1256
- comment = '')
1284
+ comment = new_comment(''))
1285
+ raise 'no' unless RDoc::Comment === comment
1257
1286
  comment.force_encoding @encoding if @encoding
1258
1287
 
1259
1288
  nest = 1
@@ -1293,6 +1322,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
1293
1322
  end
1294
1323
  end
1295
1324
 
1325
+ comment = new_comment comment
1326
+
1296
1327
  unless comment.empty? then
1297
1328
  look_for_directives_in container, comment
1298
1329
 
@@ -1370,8 +1401,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
1370
1401
  when 'require', 'include' then
1371
1402
  # ignore
1372
1403
  else
1373
- if comment =~ /\A#\#$/ then
1374
- case comment
1404
+ if comment.text =~ /\A#\#$/ then
1405
+ case comment.text
1375
1406
  when /^# +:?attr(_reader|_writer|_accessor)?:/ then
1376
1407
  parse_meta_attr container, single, tk, comment
1377
1408
  else
@@ -1410,7 +1441,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
1410
1441
  end
1411
1442
 
1412
1443
  unless keep_comment then
1413
- comment = ''
1444
+ comment = new_comment ''
1414
1445
  comment.force_encoding @encoding if @encoding
1415
1446
  end
1416
1447
 
@@ -1497,8 +1528,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
1497
1528
 
1498
1529
  def parse_top_level_statements container
1499
1530
  comment = collect_first_comment
1531
+
1500
1532
  look_for_directives_in container, comment
1501
1533
 
1534
+ @markup = comment.format
1535
+
1502
1536
  # HACK move if to RDoc::Context#comment=
1503
1537
  container.comment = comment if container.document_self unless comment.empty?
1504
1538
 
@@ -1640,13 +1674,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
1640
1674
 
1641
1675
  ##
1642
1676
  # Removes private comments from +comment+
1677
+ #--
1678
+ # TODO remove
1643
1679
 
1644
- def remove_private_comments(comment)
1645
- empty = ''
1646
- empty.force_encoding comment.encoding if Object.const_defined? :Encoding
1647
-
1648
- comment.gsub!(/^#--.*?^#\+\+\n?/m, empty)
1649
- comment.sub!(/^#--.*/m, '')
1680
+ def remove_private_comments comment
1681
+ comment.remove_private
1650
1682
  end
1651
1683
 
1652
1684
  ##
@@ -4,6 +4,8 @@
4
4
 
5
5
  class RDoc::Parser::Simple < RDoc::Parser
6
6
 
7
+ include RDoc::Parser::Text
8
+
7
9
  parse_files_matching(//)
8
10
 
9
11
  attr_reader :content # :nodoc:
@@ -24,20 +26,14 @@ class RDoc::Parser::Simple < RDoc::Parser
24
26
 
25
27
  def scan
26
28
  comment = remove_coding_comment @content
27
- comment = remove_private_comments comment
29
+ comment = remove_private_comment comment
30
+
31
+ comment = RDoc::Comment.new comment, @top_level
28
32
 
29
33
  @top_level.comment = comment
30
- @top_level.parser = self.class
31
34
  @top_level
32
35
  end
33
36
 
34
- ##
35
- # Removes comments wrapped in <tt>--/++</tt>
36
-
37
- def remove_private_comments text
38
- text.gsub(/^--\n.*?^\+\+/m, '').sub(/^--\n.*/m, '')
39
- end
40
-
41
37
  ##
42
38
  # Removes the encoding magic comment from +text+
43
39
 
@@ -45,5 +41,21 @@ class RDoc::Parser::Simple < RDoc::Parser
45
41
  text.sub(/\A# .*coding[=:].*$/, '')
46
42
  end
47
43
 
44
+ ##
45
+ # Removes private comments.
46
+ #
47
+ # Unlike RDoc::Comment#remove_private this implementation only looks for two
48
+ # dashes at the beginning of the line. Three or more dashes are considered
49
+ # to be a rule and ignored.
50
+
51
+ def remove_private_comment comment
52
+ # Workaround for gsub encoding for Ruby 1.9.2 and earlier
53
+ empty = ''
54
+ empty.force_encoding comment.encoding if Object.const_defined? :Encoding
55
+
56
+ comment = comment.gsub(%r%^--\n.*?^\+\+\n?%m, empty)
57
+ comment.sub(%r%^--\n.*%m, empty)
58
+ end
59
+
48
60
  end
49
61
 
@@ -0,0 +1,11 @@
1
+ ##
2
+ # Indicates this parser is text and doesn't contain code constructs.
3
+ #
4
+ # Include this module in a RDoc::Parser subclass to make it show up as a file,
5
+ # not as part of a class or module.
6
+ #--
7
+ # This is not named File to avoid overriding ::File
8
+
9
+ module RDoc::Parser::Text
10
+ end
11
+
@@ -0,0 +1,95 @@
1
+ ##
2
+ # RDoc::RD implements the RD format from the rdtool gem.
3
+ #
4
+ # = LICENSE
5
+ #
6
+ # The grammar that produces RDoc::RD::BlockParser and RDoc::RD::InlineParser
7
+ # is included in RDoc under the Ruby License.
8
+ #
9
+ # You can find the original source for rdtool at
10
+ # https://github.com/uwabami/rdtool/
11
+ #
12
+ # You can use, re-distribute or change these files under Ruby's License or GPL.
13
+ #
14
+ # 1. You may make and give away verbatim copies of the source form of the
15
+ # software without restriction, provided that you duplicate all of the
16
+ # original copyright notices and associated disclaimers.
17
+ #
18
+ # 2. You may modify your copy of the software in any way, provided that
19
+ # you do at least ONE of the following:
20
+ #
21
+ # a. place your modifications in the Public Domain or otherwise
22
+ # make them Freely Available, such as by posting said
23
+ # modifications to Usenet or an equivalent medium, or by allowing
24
+ # the author to include your modifications in the software.
25
+ #
26
+ # b. use the modified software only within your corporation or
27
+ # organization.
28
+ #
29
+ # c. give non-standard binaries non-standard names, with
30
+ # instructions on where to get the original software distribution.
31
+ #
32
+ # d. make other distribution arrangements with the author.
33
+ #
34
+ # 3. You may distribute the software in object code or binary form,
35
+ # provided that you do at least ONE of the following:
36
+ #
37
+ # a. distribute the binaries and library files of the software,
38
+ # together with instructions (in the manual page or equivalent)
39
+ # on where to get the original distribution.
40
+ #
41
+ # b. accompany the distribution with the machine-readable source of
42
+ # the software.
43
+ #
44
+ # c. give non-standard binaries non-standard names, with
45
+ # instructions on where to get the original software distribution.
46
+ #
47
+ # d. make other distribution arrangements with the author.
48
+ #
49
+ # 4. You may modify and include the part of the software into any other
50
+ # software (possibly commercial). But some files in the distribution
51
+ # are not written by the author, so that they are not under these terms.
52
+ #
53
+ # For the list of those files and their copying conditions, see the
54
+ # file LEGAL.
55
+ #
56
+ # 5. The scripts and library files supplied as input to or produced as
57
+ # output from the software do not automatically fall under the
58
+ # copyright of the software, but belong to whomever generated them,
59
+ # and may be sold commercially, and may be aggregated with this
60
+ # software.
61
+ #
62
+ # 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
63
+ # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
64
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
65
+ # PURPOSE.
66
+
67
+ class RDoc::RD
68
+
69
+ ##
70
+ # Parses +rd+ source and returns an RDoc::Markup::Document. If the
71
+ # <tt>=begin</tt> or <tt>=end</tt> lines are missing they will be added.
72
+
73
+ def self.parse rd
74
+ rd = rd.lines.to_a
75
+
76
+ if rd.find { |i| /\S/ === i } and !rd.find{|i| /^=begin\b/ === i } then
77
+ rd.unshift("=begin\n").push("=end\n")
78
+ end
79
+
80
+ parser = RDoc::RD::BlockParser.new
81
+ document = parser.parse rd
82
+
83
+ # isn't this always true?
84
+ document.parts.shift if RDoc::Markup::BlankLine === document.parts.first
85
+ document.parts.pop if RDoc::Markup::BlankLine === document.parts.last
86
+
87
+ document
88
+ end
89
+
90
+ autoload :BlockParser, 'rdoc/rd/block_parser'
91
+ autoload :InlineParser, 'rdoc/rd/inline_parser'
92
+ autoload :Inline, 'rdoc/rd/inline'
93
+
94
+ end
95
+