iownbey-rdoc 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/History.txt +13 -0
  2. data/Manifest.txt +61 -0
  3. data/README.txt +34 -0
  4. data/bin/rdoc +22 -0
  5. data/bin/ri +6 -0
  6. data/lib/rdoc.rb +277 -0
  7. data/lib/rdoc/code_objects.rb +776 -0
  8. data/lib/rdoc/diagram.rb +338 -0
  9. data/lib/rdoc/dot.rb +249 -0
  10. data/lib/rdoc/generator.rb +1050 -0
  11. data/lib/rdoc/generator/chm.rb +113 -0
  12. data/lib/rdoc/generator/chm/chm.rb +98 -0
  13. data/lib/rdoc/generator/html.rb +370 -0
  14. data/lib/rdoc/generator/html/hefss.rb +414 -0
  15. data/lib/rdoc/generator/html/html.rb +704 -0
  16. data/lib/rdoc/generator/html/kilmer.rb +418 -0
  17. data/lib/rdoc/generator/html/one_page_html.rb +121 -0
  18. data/lib/rdoc/generator/ri.rb +229 -0
  19. data/lib/rdoc/generator/texinfo.rb +84 -0
  20. data/lib/rdoc/generator/texinfo/class.texinfo.erb +44 -0
  21. data/lib/rdoc/generator/texinfo/file.texinfo.erb +6 -0
  22. data/lib/rdoc/generator/texinfo/method.texinfo.erb +6 -0
  23. data/lib/rdoc/generator/texinfo/texinfo.erb +28 -0
  24. data/lib/rdoc/generator/xml.rb +120 -0
  25. data/lib/rdoc/generator/xml/rdf.rb +113 -0
  26. data/lib/rdoc/generator/xml/xml.rb +111 -0
  27. data/lib/rdoc/markup.rb +473 -0
  28. data/lib/rdoc/markup/attribute_manager.rb +274 -0
  29. data/lib/rdoc/markup/formatter.rb +14 -0
  30. data/lib/rdoc/markup/fragments.rb +337 -0
  31. data/lib/rdoc/markup/inline.rb +101 -0
  32. data/lib/rdoc/markup/lines.rb +152 -0
  33. data/lib/rdoc/markup/preprocess.rb +71 -0
  34. data/lib/rdoc/markup/to_flow.rb +185 -0
  35. data/lib/rdoc/markup/to_html.rb +354 -0
  36. data/lib/rdoc/markup/to_html_crossref.rb +86 -0
  37. data/lib/rdoc/markup/to_latex.rb +328 -0
  38. data/lib/rdoc/markup/to_test.rb +50 -0
  39. data/lib/rdoc/markup/to_texinfo.rb +69 -0
  40. data/lib/rdoc/options.rb +621 -0
  41. data/lib/rdoc/parsers/parse_c.rb +775 -0
  42. data/lib/rdoc/parsers/parse_f95.rb +1841 -0
  43. data/lib/rdoc/parsers/parse_rb.rb +2584 -0
  44. data/lib/rdoc/parsers/parse_simple.rb +40 -0
  45. data/lib/rdoc/parsers/parserfactory.rb +99 -0
  46. data/lib/rdoc/rdoc.rb +277 -0
  47. data/lib/rdoc/ri.rb +4 -0
  48. data/lib/rdoc/ri/cache.rb +188 -0
  49. data/lib/rdoc/ri/descriptions.rb +150 -0
  50. data/lib/rdoc/ri/display.rb +274 -0
  51. data/lib/rdoc/ri/driver.rb +452 -0
  52. data/lib/rdoc/ri/formatter.rb +616 -0
  53. data/lib/rdoc/ri/paths.rb +102 -0
  54. data/lib/rdoc/ri/reader.rb +106 -0
  55. data/lib/rdoc/ri/util.rb +81 -0
  56. data/lib/rdoc/ri/writer.rb +68 -0
  57. data/lib/rdoc/stats.rb +25 -0
  58. data/lib/rdoc/template.rb +64 -0
  59. data/lib/rdoc/tokenstream.rb +33 -0
  60. data/test/test_rdoc_c_parser.rb +261 -0
  61. data/test/test_rdoc_info_formatting.rb +179 -0
  62. data/test/test_rdoc_info_sections.rb +93 -0
  63. data/test/test_rdoc_markup.rb +613 -0
  64. data/test/test_rdoc_markup_attribute_manager.rb +224 -0
  65. data/test/test_rdoc_ri_attribute_formatter.rb +42 -0
  66. data/test/test_rdoc_ri_default_display.rb +295 -0
  67. data/test/test_rdoc_ri_formatter.rb +318 -0
  68. data/test/test_rdoc_ri_overstrike_formatter.rb +69 -0
  69. metadata +142 -0
@@ -0,0 +1,33 @@
1
+ module RDoc; end
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
+
12
+ def token_stream
13
+ @token_stream
14
+ end
15
+
16
+ def start_collecting_tokens
17
+ @token_stream = []
18
+ end
19
+
20
+ def add_token(tk)
21
+ @token_stream << tk
22
+ end
23
+
24
+ def add_tokens(tks)
25
+ tks.each {|tk| add_token(tk)}
26
+ end
27
+
28
+ def pop_token
29
+ @token_stream.pop
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,261 @@
1
+ require 'stringio'
2
+ require 'tempfile'
3
+ require 'test/unit'
4
+ require 'rdoc/parsers/parse_c'
5
+
6
+ class RDoc::C_Parser
7
+ attr_accessor :classes
8
+
9
+ public :do_classes, :do_constants
10
+ end
11
+
12
+ class TestRdocC_Parser < Test::Unit::TestCase
13
+
14
+ def setup
15
+ @tempfile = Tempfile.new self.class.name
16
+ filename = @tempfile.path
17
+
18
+ @top_level = RDoc::TopLevel.new filename
19
+ @fn = filename
20
+ @options = RDoc::Options.new Hash.new
21
+ @stats = RDoc::Stats.new
22
+
23
+ @progress = StringIO.new
24
+ end
25
+
26
+ def teardown
27
+ @tempfile.unlink
28
+ end
29
+
30
+ def test_do_classes_boot_class
31
+ content = <<-EOF
32
+ /* Document-class: Foo
33
+ * this is the Foo boot class
34
+ */
35
+ VALUE cFoo = boot_defclass("Foo", 0);
36
+ EOF
37
+
38
+ klass = util_get_class content, 'cFoo'
39
+ assert_equal " this is the Foo boot class\n ", klass.comment
40
+ end
41
+
42
+ def test_do_classes_class
43
+ content = <<-EOF
44
+ /* Document-class: Foo
45
+ * this is the Foo class
46
+ */
47
+ VALUE cFoo = rb_define_class("Foo", rb_cObject);
48
+ EOF
49
+
50
+ klass = util_get_class content, 'cFoo'
51
+ assert_equal " this is the Foo class\n ", klass.comment
52
+ end
53
+
54
+ def test_do_classes_class_under
55
+ content = <<-EOF
56
+ /* Document-class: Kernel::Foo
57
+ * this is the Foo class under Kernel
58
+ */
59
+ VALUE cFoo = rb_define_class_under(rb_mKernel, "Foo", rb_cObject);
60
+ EOF
61
+
62
+ klass = util_get_class content, 'cFoo'
63
+ assert_equal " this is the Foo class under Kernel\n ", klass.comment
64
+ end
65
+
66
+ def test_do_classes_module
67
+ content = <<-EOF
68
+ /* Document-module: Foo
69
+ * this is the Foo module
70
+ */
71
+ VALUE mFoo = rb_define_module("Foo");
72
+ EOF
73
+
74
+ klass = util_get_class content, 'mFoo'
75
+ assert_equal " this is the Foo module\n ", klass.comment
76
+ end
77
+
78
+ def test_do_classes_module_under
79
+ content = <<-EOF
80
+ /* Document-module: Kernel::Foo
81
+ * this is the Foo module under Kernel
82
+ */
83
+ VALUE mFoo = rb_define_module_under(rb_mKernel, "Foo");
84
+ EOF
85
+
86
+ klass = util_get_class content, 'mFoo'
87
+ assert_equal " this is the Foo module under Kernel\n ", klass.comment
88
+ end
89
+
90
+ def test_do_constants
91
+ content = <<-EOF
92
+ #include <ruby.h>
93
+
94
+ void Init_foo(){
95
+ VALUE cFoo = rb_define_class("Foo", rb_cObject);
96
+
97
+ /* 300: The highest possible score in bowling */
98
+ rb_define_const(cFoo, "PERFECT", INT2FIX(300));
99
+
100
+ /* Huzzah!: What you cheer when you roll a perfect game */
101
+ rb_define_const(cFoo, "CHEER", rb_str_new2("Huzzah!"));
102
+
103
+ /* TEST\:TEST: Checking to see if escaped semicolon works */
104
+ rb_define_const(cFoo, "TEST", rb_str_new2("TEST:TEST"));
105
+
106
+ /* \\: The file separator on MS Windows */
107
+ rb_define_const(cFoo, "MSEPARATOR", rb_str_new2("\\"));
108
+
109
+ /* /: The file separator on Unix */
110
+ rb_define_const(cFoo, "SEPARATOR", rb_str_new2("/"));
111
+
112
+ /* C:\\Program Files\\Stuff: A directory on MS Windows */
113
+ rb_define_const(cFoo, "STUFF", rb_str_new2("C:\\Program Files\\Stuff"));
114
+
115
+ /* Default definition */
116
+ rb_define_const(cFoo, "NOSEMI", INT2FIX(99));
117
+
118
+ rb_define_const(cFoo, "NOCOMMENT", rb_str_new2("No comment"));
119
+
120
+ /*
121
+ * Multiline comment goes here because this comment spans multiple lines.
122
+ * Multiline comment goes here because this comment spans multiple lines.
123
+ */
124
+ rb_define_const(cFoo, "MULTILINE", INT2FIX(1));
125
+
126
+ /*
127
+ * 1: Multiline comment goes here because this comment spans multiple lines.
128
+ * Multiline comment goes here because this comment spans multiple lines.
129
+ */
130
+ rb_define_const(cFoo, "MULTILINE_VALUE", INT2FIX(1));
131
+
132
+ /* Multiline comment goes here because this comment spans multiple lines.
133
+ * Multiline comment goes here because this comment spans multiple lines.
134
+ */
135
+ rb_define_const(cFoo, "MULTILINE_NOT_EMPTY", INT2FIX(1));
136
+
137
+ }
138
+ EOF
139
+
140
+ parser = util_parser content
141
+
142
+ parser.do_classes
143
+ parser.do_constants
144
+
145
+ klass = parser.classes['cFoo']
146
+ assert klass
147
+
148
+ constants = klass.constants
149
+ assert !klass.constants.empty?
150
+
151
+ constants = constants.map { |c| [c.name, c.value, c.comment] }
152
+
153
+ assert_equal ['PERFECT', '300',
154
+ "\n The highest possible score in bowling \n "],
155
+ constants.shift
156
+ assert_equal ['CHEER', 'Huzzah!',
157
+ "\n What you cheer when you roll a perfect game \n "],
158
+ constants.shift
159
+ assert_equal ['TEST', 'TEST:TEST',
160
+ "\n Checking to see if escaped semicolon works \n "],
161
+ constants.shift
162
+ assert_equal ['MSEPARATOR', '\\',
163
+ "\n The file separator on MS Windows \n "],
164
+ constants.shift
165
+ assert_equal ['SEPARATOR', '/',
166
+ "\n The file separator on Unix \n "],
167
+ constants.shift
168
+ assert_equal ['STUFF', 'C:\\Program Files\\Stuff',
169
+ "\n A directory on MS Windows \n "],
170
+ constants.shift
171
+ assert_equal ['NOSEMI', 'INT2FIX(99)',
172
+ "\n Default definition \n "],
173
+ constants.shift
174
+ assert_equal ['NOCOMMENT', 'rb_str_new2("No comment")', nil],
175
+ constants.shift
176
+
177
+ comment = <<-EOF.chomp
178
+
179
+
180
+ Multiline comment goes here because this comment spans multiple lines.
181
+ Multiline comment goes here because this comment spans multiple lines.
182
+
183
+
184
+ EOF
185
+ assert_equal ['MULTILINE', 'INT2FIX(1)', comment], constants.shift
186
+ assert_equal ['MULTILINE_VALUE', '1', comment], constants.shift
187
+
188
+ comment = <<-EOF.chomp
189
+
190
+ Multiline comment goes here because this comment spans multiple lines.
191
+ Multiline comment goes here because this comment spans multiple lines.
192
+
193
+
194
+ EOF
195
+ assert_equal ['MULTILINE_NOT_EMPTY', 'INT2FIX(1)', comment], constants.shift
196
+
197
+ assert constants.empty?, constants.inspect
198
+ end
199
+
200
+ def test_find_class_comment_init
201
+ content = <<-EOF
202
+ /*
203
+ * a comment for class Foo
204
+ */
205
+ void
206
+ Init_Foo(void) {
207
+ VALUE foo = rb_define_class("Foo", rb_cObject);
208
+ }
209
+ EOF
210
+
211
+ klass = util_get_class content, 'foo'
212
+
213
+ assert_equal " \n a comment for class Foo\n \n", klass.comment
214
+ end
215
+
216
+ def test_find_class_comment_define_class
217
+ content = <<-EOF
218
+ /*
219
+ * a comment for class Foo
220
+ */
221
+ VALUE foo = rb_define_class("Foo", rb_cObject);
222
+ EOF
223
+
224
+ klass = util_get_class content, 'foo'
225
+
226
+ assert_equal " \n a comment for class Foo\n ", klass.comment
227
+ end
228
+
229
+ def test_find_class_comment_define_class_Init_Foo
230
+ content = <<-EOF
231
+ /*
232
+ * a comment for class Foo on Init
233
+ */
234
+ void
235
+ Init_Foo(void) {
236
+ /*
237
+ * a comment for class Foo on rb_define_class
238
+ */
239
+ VALUE foo = rb_define_class("Foo", rb_cObject);
240
+ }
241
+ EOF
242
+
243
+ klass = util_get_class content, 'foo'
244
+
245
+ assert_equal " \n a comment for class Foo on Init\n \n", klass.comment
246
+ end
247
+
248
+ def util_get_class(content, name)
249
+ parser = util_parser content
250
+ parser.do_classes
251
+ parser.classes[name]
252
+ end
253
+
254
+ def util_parser(content)
255
+ parser = RDoc::C_Parser.new @top_level, @fn, content, @options, @stats
256
+ parser.progress = @progress
257
+ parser
258
+ end
259
+
260
+ end
261
+
@@ -0,0 +1,179 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/'
2
+ require 'fileutils'
3
+ require 'test/unit'
4
+ require 'rdoc/generator/texinfo'
5
+ require 'yaml'
6
+
7
+ # From chapter 18 of the Pickaxe 3rd ed. and the TexInfo manual.
8
+ class TestRdocInfoFormatting < Test::Unit::TestCase
9
+ OUTPUT_DIR = "/tmp/rdoc-#{$$}"
10
+
11
+ def setup
12
+ # supress stdout
13
+ $stdout = File.new('/dev/null','w')
14
+ $stderr = File.new('/dev/null','w')
15
+
16
+ RDoc::RDoc.new.document(['--fmt=texinfo',
17
+ File.expand_path(__FILE__),
18
+ "--op=#{OUTPUT_DIR}"])
19
+ @text = File.read(OUTPUT_DIR + '/rdoc.texinfo')
20
+ # File.open('rdoc.texinfo', 'w') { |f| f.puts @text }
21
+ end
22
+
23
+ def teardown
24
+ $stdout = STDOUT
25
+ $stderr = STDERR
26
+ FileUtils.rm_rf OUTPUT_DIR
27
+ end
28
+
29
+ # Make sure tags like *this* do not make HTML
30
+ def test_descriptions_are_not_html
31
+ assert_no_match Regexp.new("\<b\>this\<\/b\>"), @text, "We had some HTML; icky!"
32
+ end
33
+
34
+ # Ensure we get a reasonable amount
35
+ #
36
+ # of space in between paragraphs.
37
+ def test_paragraphs_are_spaced
38
+ assert_match(/amount\n\n\nof space/, @text)
39
+ end
40
+
41
+ # @ and {} should be at-sign-prefixed
42
+ def test_escaping
43
+ assert_match(/@@ and @\{@\} should be at-sign-prefixed/)
44
+ end
45
+
46
+ # This tests that *bold* and <b>bold me</b> become @strong{bolded}
47
+ def test_bold
48
+ # Seems like a limitation of the Info format: @strong{bold}
49
+ # becomes *bold* when read in Info or M-x info. highly lame!
50
+ assert_match(/@strong\{bold\}/)
51
+ assert_match(/@strong\{bold me\}/)
52
+ end
53
+
54
+ # Test that _italics_ and <em>italicize me</em> becomes @emph{italicized}
55
+ def test_italics
56
+ assert_match(/@emph\{italics\}/)
57
+ assert_match(/@emph\{italicize me\}/)
58
+ end
59
+
60
+ # And that typewriter +text+ and <tt>typewriter me</tt> becomes @code{typewriter}
61
+ def test_tt
62
+ assert_match(/@code\{text\}/)
63
+ assert_match(/@code\{typewriter me\}/)
64
+ end
65
+
66
+ # Check that
67
+ # anything indented is
68
+ # verbatim @verb{|foo bar baz|}
69
+ def test_literal_code
70
+ assert_match("@verb{| anything indented is
71
+ verbatim @@verb@{|foo bar baz|@}
72
+ |}")
73
+ end
74
+
75
+ # = Huge heading should be a @majorheading
76
+ # == There is also @chapheading
77
+ # === Everything deeper becomes a regular @heading
78
+ # ====== Regardless of its nesting level
79
+ def test_headings
80
+ assert_match(/@majorheading\{Huge heading should be a @@majorheading\}/)
81
+ assert_match(/@chapheading\{There is also @@chapheading\}/)
82
+ assert_match(/@heading\{Everything deeper becomes a regular @@heading\}/)
83
+ assert_match(/@heading\{Regardless of its nesting level\}/)
84
+ end
85
+
86
+ # * list item
87
+ # * list item2
88
+ #
89
+ # with a paragraph in between
90
+ #
91
+ # - hyphen lists
92
+ # - are also allowed
93
+ # and items may flow over lines
94
+ def test_bullet_lists
95
+ assert_match("@itemize @bullet
96
+ @item
97
+ list item
98
+ @item
99
+ list item2
100
+ @end itemize")
101
+ assert_match("@itemize @bullet
102
+ @item
103
+ hyphen lists
104
+ @item
105
+ are also allowed and items may flow over lines
106
+ @end itemize")
107
+ end
108
+
109
+ # 2. numbered lists
110
+ # 8. are made by
111
+ # 9. a digit followed by a period
112
+ def test_numbered_lists
113
+ end
114
+
115
+ # a. alpha lists
116
+ # b. should be parsed too
117
+ def test_alpha_lists
118
+ end
119
+
120
+ # [cat] small domestic animal
121
+ # [+cat+] command to copy standard input
122
+ # to standard output
123
+ def test_labelled_lists
124
+ end
125
+
126
+ # * First item.
127
+ # * Inner item.
128
+ # * Second inner item.
129
+ # * Second outer item.
130
+ def test_nested_lists
131
+ assert_match("@itemize @bullet
132
+ @item
133
+ First item.
134
+ @itemize @bullet
135
+ @item
136
+ Inner item.
137
+ @item
138
+ Second inner item.
139
+ @end itemize
140
+ @item
141
+ Second outer item.
142
+ @end itemize")
143
+ end
144
+
145
+ def test_internal_hyperlinks
146
+ # be sure to test multi-word hyperlinks as well.
147
+ end
148
+
149
+ def test_hyperlink_targets
150
+ end
151
+
152
+ def test_web_links
153
+ # An example of the two-argument form: The official
154
+ # @uref{ftp://ftp.gnu.org/gnu, GNU ftp site} holds programs and texts.
155
+
156
+ # produces:
157
+ # The official GNU ftp site (ftp://ftp.gnu.org/gnu)
158
+ # holds programs and texts.
159
+ # and the HTML output is this:
160
+ # The official <a href="ftp://ftp.gnu.org/gnu">GNU ftp site</a>
161
+ # holds programs and texts.
162
+ end
163
+
164
+ # three or more hyphens
165
+ # ----
166
+ # should produce a horizontal rule
167
+ def test_horizontal_rule
168
+ # gah; not sure texinfo supports horizontal rules
169
+ end
170
+
171
+ private
172
+
173
+ # We don't want the whole string inspected if we pass our own
174
+ # message in.
175
+ def assert_match(regex, string = @text,
176
+ message = "Didn't find #{regex.inspect} in #{string}.")
177
+ assert string[regex] #, message
178
+ end
179
+ end