rdoc 4.1.2 → 4.2.0

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +3 -1
  3. data/History.rdoc +70 -3
  4. data/LEGAL.rdoc +11 -0
  5. data/Manifest.txt +6 -2
  6. data/Rakefile +8 -1
  7. data/lib/rdoc.rb +3 -1
  8. data/lib/rdoc/context.rb +2 -0
  9. data/lib/rdoc/encoding.rb +3 -1
  10. data/lib/rdoc/generator.rb +1 -0
  11. data/lib/rdoc/generator/darkfish.rb +3 -2
  12. data/lib/rdoc/generator/json_index.rb +44 -0
  13. data/lib/rdoc/generator/pot.rb +97 -0
  14. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  15. data/lib/rdoc/generator/template/darkfish/_head.rhtml +9 -12
  16. data/lib/rdoc/generator/template/darkfish/{fonts.css → css/fonts.css} +0 -0
  17. data/lib/rdoc/generator/template/darkfish/{rdoc.css → css/rdoc.css} +11 -1
  18. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +32 -11
  19. data/lib/rdoc/markdown.kpeg +6 -1
  20. data/lib/rdoc/markdown.rb +174 -2
  21. data/lib/rdoc/markup.rb +2 -2
  22. data/lib/rdoc/markup/attribute_manager.rb +1 -1
  23. data/lib/rdoc/markup/to_html.rb +5 -4
  24. data/lib/rdoc/markup/to_label.rb +1 -1
  25. data/lib/rdoc/method_attr.rb +11 -3
  26. data/lib/rdoc/options.rb +55 -3
  27. data/lib/rdoc/parser.rb +1 -1
  28. data/lib/rdoc/parser/c.rb +5 -6
  29. data/lib/rdoc/parser/changelog.rb +7 -3
  30. data/lib/rdoc/parser/ruby.rb +8 -12
  31. data/lib/rdoc/rd/block_parser.rb +1 -1
  32. data/lib/rdoc/rd/inline_parser.rb +1 -1
  33. data/lib/rdoc/rdoc.rb +5 -3
  34. data/lib/rdoc/ruby_lex.rb +3 -3
  35. data/lib/rdoc/ruby_token.rb +7 -7
  36. data/lib/rdoc/single_class.rb +4 -0
  37. data/lib/rdoc/stats.rb +4 -0
  38. data/lib/rdoc/stats/normal.rb +22 -11
  39. data/lib/rdoc/task.rb +1 -1
  40. data/lib/rdoc/test_case.rb +1 -1
  41. data/lib/rdoc/text.rb +9 -0
  42. data/lib/rdoc/token_stream.rb +1 -1
  43. data/test/test_rdoc_context.rb +2 -0
  44. data/test/test_rdoc_encoding.rb +23 -0
  45. data/test/test_rdoc_generator_darkfish.rb +2 -2
  46. data/test/test_rdoc_generator_json_index.rb +55 -0
  47. data/test/test_rdoc_generator_markup.rb +1 -1
  48. data/test/test_rdoc_generator_pot.rb +91 -0
  49. data/test/test_rdoc_generator_pot_po.rb +51 -0
  50. data/test/test_rdoc_generator_pot_po_entry.rb +139 -0
  51. data/test/test_rdoc_i18n_locale.rb +73 -0
  52. data/test/test_rdoc_i18n_text.rb +123 -0
  53. data/test/test_rdoc_markup_attribute_manager.rb +6 -0
  54. data/test/test_rdoc_markup_heading.rb +4 -4
  55. data/test/test_rdoc_markup_pre_process.rb +1 -1
  56. data/test/test_rdoc_markup_to_html.rb +46 -26
  57. data/test/test_rdoc_markup_to_html_snippet.rb +8 -7
  58. data/test/test_rdoc_markup_to_label.rb +4 -4
  59. data/test/test_rdoc_method_attr.rb +31 -1
  60. data/test/test_rdoc_normal_class.rb +4 -4
  61. data/test/test_rdoc_options.rb +19 -0
  62. data/test/test_rdoc_parser.rb +16 -1
  63. data/test/test_rdoc_parser_c.rb +31 -1
  64. data/test/test_rdoc_parser_changelog.rb +1 -1
  65. data/test/test_rdoc_parser_markdown.rb +1 -1
  66. data/test/test_rdoc_parser_rd.rb +1 -1
  67. data/test/test_rdoc_parser_ruby.rb +22 -25
  68. data/test/test_rdoc_parser_simple.rb +1 -1
  69. data/test/test_rdoc_rd_block_parser.rb +3 -1
  70. data/test/test_rdoc_rdoc.rb +24 -3
  71. data/test/test_rdoc_ruby_lex.rb +11 -0
  72. data/test/test_rdoc_rubygems_hook.rb +0 -3
  73. data/test/test_rdoc_single_class.rb +13 -5
  74. data/test/test_rdoc_stats.rb +55 -0
  75. data/test/test_rdoc_task.rb +1 -0
  76. metadata +18 -7
@@ -136,6 +136,61 @@ class TestRDocGeneratorJsonIndex < RDoc::TestCase
136
136
  assert_equal expected, index
137
137
  end
138
138
 
139
+ def test_generate_gzipped
140
+ require 'zlib'
141
+ @g.generate
142
+ @g.generate_gzipped
143
+
144
+ assert_file 'js/searcher.js'
145
+ assert_file 'js/searcher.js.gz'
146
+ assert_file 'js/navigation.js'
147
+ assert_file 'js/navigation.js.gz'
148
+ assert_file 'js/search_index.js'
149
+ assert_file 'js/search_index.js.gz'
150
+
151
+ gzip = File.open 'js/search_index.js.gz'
152
+ json = Zlib::GzipReader.new(gzip).read
153
+
154
+ json =~ /\Avar search_data = /
155
+
156
+ assignment = $&
157
+ index = $'
158
+
159
+ refute_empty assignment
160
+
161
+ index = JSON.parse index
162
+
163
+ info = [
164
+ @klass.search_record[2..-1],
165
+ @nest_klass.search_record[2..-1],
166
+ @meth.search_record[2..-1],
167
+ @nest_meth.search_record[2..-1],
168
+ @page.search_record[2..-1],
169
+ ]
170
+
171
+ expected = {
172
+ 'index' => {
173
+ 'searchIndex' => [
174
+ 'c',
175
+ 'd',
176
+ 'meth()',
177
+ 'meth()',
178
+ 'page',
179
+ ],
180
+ 'longSearchIndex' => [
181
+ 'c',
182
+ 'c::d',
183
+ 'c#meth()',
184
+ 'c::d#meth()',
185
+ '',
186
+ ],
187
+ 'info' => info,
188
+ },
189
+ }
190
+
191
+ assert_equal expected, index
192
+ end
193
+
139
194
  def test_generate_utf_8
140
195
  skip "Encoding not implemented" unless Object.const_defined? :Encoding
141
196
 
@@ -38,7 +38,7 @@ class TestRDocGeneratorMarkup < RDoc::TestCase
38
38
  @comment = '= Hello'
39
39
 
40
40
  links = '<span><a href="#label-Hello">&para;</a> ' +
41
- '<a href="#documentation">&uarr;</a></span>'
41
+ '<a href="#top">&uarr;</a></span>'
42
42
 
43
43
  assert_equal "\n<h1 id=\"label-Hello\">Hello#{links}</h1>\n", description
44
44
  end
@@ -0,0 +1,91 @@
1
+ require 'rdoc/test_case'
2
+
3
+ class TestRDocGeneratorPOT < RDoc::TestCase
4
+
5
+ def setup
6
+ super
7
+
8
+ @options = RDoc::Options.new
9
+ @tmpdir = File.join Dir.tmpdir, "test_rdoc_generator_pot_#{$$}"
10
+ FileUtils.mkdir_p @tmpdir
11
+
12
+ @generator = RDoc::Generator::POT.new @store, @options
13
+
14
+ @top_level = @store.add_file 'file.rb'
15
+ @klass = @top_level.add_class RDoc::NormalClass, 'Object'
16
+ @klass.add_comment 'This is a class', @top_level
17
+ @klass.add_section 'This is a section', comment('This is a section comment')
18
+
19
+ @const = RDoc::Constant.new "CONSTANT", "29", "This is a constant"
20
+
21
+ @meth = RDoc::AnyMethod.new nil, 'method'
22
+ @meth.record_location @top_level
23
+ @meth.comment = 'This is a method'
24
+
25
+ @attr = RDoc::Attr.new nil, 'attr', 'RW', ''
26
+ @attr.record_location @top_level
27
+ @attr.comment = 'This is an attribute'
28
+
29
+ @klass.add_constant @const
30
+ @klass.add_method @meth
31
+ @klass.add_attribute @attr
32
+
33
+ Dir.chdir @tmpdir
34
+ end
35
+
36
+ def teardown
37
+ super
38
+
39
+ Dir.chdir @pwd
40
+ FileUtils.rm_rf @tmpdir
41
+ end
42
+
43
+ def test_generate
44
+ @generator.generate
45
+
46
+ assert_equal <<-POT, File.read(File.join(@tmpdir, 'rdoc.pot'))
47
+ # SOME DESCRIPTIVE TITLE.
48
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
49
+ # This file is distributed under the same license as the PACKAGE package.
50
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
51
+ #, fuzzy
52
+ msgid ""
53
+ msgstr ""
54
+ "Project-Id-Version: PACKAGE VERSEION\\n"
55
+ "Report-Msgid-Bugs-To:\\n"
56
+ "PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE\\n"
57
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
58
+ "Language-Team: LANGUAGE <LL@li.org>\\n"
59
+ "Language:\\n"
60
+ "MIME-Version: 1.0\\n"
61
+ "Content-Type: text/plain; charset=CHARSET\\n"
62
+ "Content-Transfer-Encoding: 8bit\\n"
63
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n"
64
+
65
+ #. Object
66
+ msgid "This is a class"
67
+ msgstr ""
68
+
69
+ #. Object::CONSTANT
70
+ msgid "This is a constant"
71
+ msgstr ""
72
+
73
+ #. Object#method
74
+ msgid "This is a method"
75
+ msgstr ""
76
+
77
+ #. Object: section title
78
+ msgid "This is a section"
79
+ msgstr ""
80
+
81
+ #. Object: This is a section
82
+ msgid "This is a section comment"
83
+ msgstr ""
84
+
85
+ #. Object#attr
86
+ msgid "This is an attribute"
87
+ msgstr ""
88
+ POT
89
+ end
90
+
91
+ end
@@ -0,0 +1,51 @@
1
+ require 'rdoc/test_case'
2
+
3
+ class TestRDocGeneratorPOTPO < RDoc::TestCase
4
+
5
+ def setup
6
+ super
7
+ @po = RDoc::Generator::POT::PO.new
8
+ end
9
+
10
+ def test_empty
11
+ assert_equal header, @po.to_s
12
+ end
13
+
14
+ def test_have_entry
15
+ @po.add(entry("Hello", {}))
16
+ assert_equal <<-PO, @po.to_s
17
+ #{header}
18
+ msgid "Hello"
19
+ msgstr ""
20
+ PO
21
+ end
22
+
23
+ private
24
+
25
+ def entry(msgid, options)
26
+ RDoc::Generator::POT::POEntry.new(msgid, options)
27
+ end
28
+
29
+ def header
30
+ <<-'HEADER'
31
+ # SOME DESCRIPTIVE TITLE.
32
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
33
+ # This file is distributed under the same license as the PACKAGE package.
34
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
35
+ #, fuzzy
36
+ msgid ""
37
+ msgstr ""
38
+ "Project-Id-Version: PACKAGE VERSEION\n"
39
+ "Report-Msgid-Bugs-To:\n"
40
+ "PO-Revision-Date: YEAR-MO_DA HO:MI+ZONE\n"
41
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
42
+ "Language-Team: LANGUAGE <LL@li.org>\n"
43
+ "Language:\n"
44
+ "MIME-Version: 1.0\n"
45
+ "Content-Type: text/plain; charset=CHARSET\n"
46
+ "Content-Transfer-Encoding: 8bit\n"
47
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
48
+ HEADER
49
+ end
50
+
51
+ end
@@ -0,0 +1,139 @@
1
+ require 'rdoc/test_case'
2
+
3
+ class TestRDocGeneratorPOTPOEntry < RDoc::TestCase
4
+
5
+ def test_msgid_normal
6
+ assert_equal <<-'ENTRY', entry("Hello", {}).to_s
7
+ msgid "Hello"
8
+ msgstr ""
9
+ ENTRY
10
+ end
11
+
12
+ def test_msgid_multiple_lines
13
+ assert_equal <<-'ENTRY', entry("Hello\nWorld", {}).to_s
14
+ msgid ""
15
+ "Hello\n"
16
+ "World"
17
+ msgstr ""
18
+ ENTRY
19
+ end
20
+
21
+ def test_msgid_tab
22
+ assert_equal <<-'ENTRY', entry("Hello\tWorld", {}).to_s
23
+ msgid "Hello\tWorld"
24
+ msgstr ""
25
+ ENTRY
26
+ end
27
+
28
+ def test_msgid_back_slash
29
+ assert_equal <<-'ENTRY', entry("Hello \\ World", {}).to_s
30
+ msgid "Hello \\ World"
31
+ msgstr ""
32
+ ENTRY
33
+ end
34
+
35
+ def test_msgid_double_quote
36
+ assert_equal <<-'ENTRY', entry("Hello \"World\"!", {}).to_s
37
+ msgid "Hello \"World\"!"
38
+ msgstr ""
39
+ ENTRY
40
+ end
41
+
42
+ def test_translator_comment_normal
43
+ options = {:translator_comment => "Greeting"}
44
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
45
+ # Greeting
46
+ msgid "Hello"
47
+ msgstr ""
48
+ ENTRY
49
+ end
50
+
51
+ def test_translator_comment_multiple_lines
52
+ options = {:translator_comment => "Greeting\nfor morning"}
53
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
54
+ # Greeting
55
+ # for morning
56
+ msgid "Hello"
57
+ msgstr ""
58
+ ENTRY
59
+ end
60
+
61
+ def test_extracted_comment_normal
62
+ options = {:extracted_comment => "Object"}
63
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
64
+ #. Object
65
+ msgid "Hello"
66
+ msgstr ""
67
+ ENTRY
68
+ end
69
+
70
+ def test_extracted_comment_multiple_lines
71
+ options = {:extracted_comment => "Object\nMorning#greeting"}
72
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
73
+ #. Object
74
+ #. Morning#greeting
75
+ msgid "Hello"
76
+ msgstr ""
77
+ ENTRY
78
+ end
79
+
80
+ def test_references_normal
81
+ options = {:references => [["lib/rdoc.rb", 29]]}
82
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
83
+ #: lib/rdoc.rb:29
84
+ msgid "Hello"
85
+ msgstr ""
86
+ ENTRY
87
+ end
88
+
89
+ def test_references_multiple
90
+ options = {:references => [["lib/rdoc.rb", 29], ["lib/rdoc/i18n.rb", 9]]}
91
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
92
+ #: lib/rdoc.rb:29
93
+ #: lib/rdoc/i18n.rb:9
94
+ msgid "Hello"
95
+ msgstr ""
96
+ ENTRY
97
+ end
98
+
99
+ def test_flags_normal
100
+ options = {:flags => ["fuzzy"]}
101
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
102
+ #, fuzzy
103
+ msgid "Hello"
104
+ msgstr ""
105
+ ENTRY
106
+ end
107
+
108
+ def test_flags_multiple
109
+ options = {:flags => ["fuzzy", "ruby-format"]}
110
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
111
+ #, fuzzy,ruby-format
112
+ msgid "Hello"
113
+ msgstr ""
114
+ ENTRY
115
+ end
116
+
117
+ def test_full
118
+ options = {
119
+ :translator_comment => "Greeting",
120
+ :extracted_comment => "Morning#greeting",
121
+ :references => [["lib/rdoc.rb", 29]],
122
+ :flags => ["fuzzy"],
123
+ }
124
+ assert_equal <<-'ENTRY', entry("Hello", options).to_s
125
+ # Greeting
126
+ #. Morning#greeting
127
+ #: lib/rdoc.rb:29
128
+ #, fuzzy
129
+ msgid "Hello"
130
+ msgstr ""
131
+ ENTRY
132
+ end
133
+
134
+ private
135
+ def entry(msgid, options)
136
+ RDoc::Generator::POT::POEntry.new(msgid, options)
137
+ end
138
+
139
+ end
@@ -0,0 +1,73 @@
1
+ require 'rdoc/test_case'
2
+
3
+ class TestRDocI18nLocale < RDoc::TestCase
4
+
5
+ def setup
6
+ super
7
+ @locale = locale('fr')
8
+
9
+ @tmpdir = File.join Dir.tmpdir, "test_rdoc_i18n_locale_#{$$}"
10
+ FileUtils.mkdir_p @tmpdir
11
+
12
+ @locale_dir = @tmpdir
13
+ end
14
+
15
+ def teardown
16
+ FileUtils.rm_rf @tmpdir
17
+ super
18
+ end
19
+
20
+ def test_name
21
+ assert_equal 'fr', locale('fr').name
22
+ end
23
+
24
+ def test_load_nonexistent_po
25
+ File.stub(:exist?, false) do
26
+ refute @locale.load('nonexsitent-locale')
27
+ end
28
+ end
29
+
30
+ def test_load_existent_po
31
+ begin
32
+ require 'gettext/po_parser'
33
+ rescue LoadError
34
+ skip 'gettext gem is not found'
35
+ end
36
+
37
+ fr_locale_dir = File.join @locale_dir, 'fr'
38
+ FileUtils.mkdir_p fr_locale_dir
39
+ File.open File.join(fr_locale_dir, 'rdoc.po'), 'w' do |po|
40
+ po.puts <<-PO
41
+ msgid ""
42
+ msgstr ""
43
+ "Language: fr\n"
44
+ "MIME-Version: 1.0\n"
45
+ "Content-Type: text/plain; charset=UTF-8\n"
46
+ "Content-Transfer-Encoding: 8bit\n"
47
+
48
+ msgid "Hello"
49
+ msgstr "Bonjour"
50
+ PO
51
+ end
52
+
53
+ assert @locale.load(@locale_dir)
54
+ assert_equal 'Bonjour', @locale.translate('Hello')
55
+ end
56
+
57
+ def test_translate_existent_message
58
+ messages = @locale.instance_variable_get(:@messages)
59
+ messages['Hello'] = 'Bonjour'
60
+ assert_equal 'Bonjour', @locale.translate('Hello')
61
+ end
62
+
63
+ def test_translate_nonexistent_message
64
+ assert_equal 'Hello', @locale.translate('Hello')
65
+ end
66
+
67
+ private
68
+
69
+ def locale(name)
70
+ RDoc::I18n::Locale.new(name)
71
+ end
72
+
73
+ end
@@ -0,0 +1,123 @@
1
+ require 'rdoc/test_case'
2
+
3
+ class TestRDocI18nText < RDoc::TestCase
4
+
5
+ def test_multiple_paragraphs
6
+ paragraph1 = <<-PARAGRAPH.strip
7
+ RDoc produces HTML and command-line documentation for Ruby projects. RDoc
8
+ includes the +rdoc+ and +ri+ tools for generating and displaying documentation
9
+ from the command-line.
10
+ PARAGRAPH
11
+
12
+ paragraph2 = <<-PARAGRAPH.strip
13
+ This command generates documentation for all the Ruby and C source
14
+ files in and below the current directory. These will be stored in a
15
+ documentation tree starting in the subdirectory +doc+.
16
+ PARAGRAPH
17
+
18
+ raw = <<-RAW
19
+ #{paragraph1}
20
+
21
+ #{paragraph2}
22
+ RAW
23
+
24
+ expected = [
25
+ {
26
+ :type => :paragraph,
27
+ :paragraph => paragraph1,
28
+ :line_no => 1,
29
+ },
30
+ {
31
+ :type => :paragraph,
32
+ :paragraph => paragraph2,
33
+ :line_no => 5,
34
+ },
35
+ ]
36
+ assert_equal expected, extract_messages(raw)
37
+ end
38
+
39
+ def test_translate_multiple_paragraphs
40
+ paragraph1 = <<-PARAGRAPH.strip
41
+ Paragraph 1.
42
+ PARAGRAPH
43
+ paragraph2 = <<-PARAGRAPH.strip
44
+ Paragraph 2.
45
+ PARAGRAPH
46
+
47
+ raw = <<-RAW
48
+ #{paragraph1}
49
+
50
+ #{paragraph2}
51
+ RAW
52
+
53
+ expected = <<-TRANSLATED
54
+ Paragraphe 1.
55
+
56
+ Paragraphe 2.
57
+ TRANSLATED
58
+ assert_equal expected, translate(raw)
59
+ end
60
+
61
+ def test_translate_not_transalted_message
62
+ nonexistent_paragraph = <<-PARAGRAPH.strip
63
+ Nonexistent paragraph.
64
+ PARAGRAPH
65
+
66
+ raw = <<-RAW
67
+ #{nonexistent_paragraph}
68
+ RAW
69
+
70
+ expected = <<-TRANSLATED
71
+ #{nonexistent_paragraph}
72
+ TRANSLATED
73
+ assert_equal expected, translate(raw)
74
+ end
75
+
76
+ def test_translate_keep_empty_lines
77
+ raw = <<-RAW
78
+ Paragraph 1.
79
+
80
+
81
+
82
+
83
+ Paragraph 2.
84
+ RAW
85
+
86
+ expected = <<-TRANSLATED
87
+ Paragraphe 1.
88
+
89
+
90
+
91
+
92
+ Paragraphe 2.
93
+ TRANSLATED
94
+ assert_equal expected, translate(raw)
95
+ end
96
+
97
+ private
98
+
99
+ def extract_messages(raw)
100
+ text = RDoc::I18n::Text.new(raw)
101
+ messages = []
102
+ text.extract_messages do |message|
103
+ messages << message
104
+ end
105
+ messages
106
+ end
107
+
108
+ def locale
109
+ locale = RDoc::I18n::Locale.new('fr')
110
+ messages = locale.instance_variable_get(:@messages)
111
+ messages['markdown'] = 'markdown (markdown in fr)'
112
+ messages['Hello'] = 'Bonjour (Hello in fr)'
113
+ messages['Paragraph 1.'] = 'Paragraphe 1.'
114
+ messages['Paragraph 2.'] = 'Paragraphe 2.'
115
+ locale
116
+ end
117
+
118
+ def translate(raw)
119
+ text = RDoc::I18n::Text.new(raw)
120
+ text.translate(locale)
121
+ end
122
+
123
+ end