rdoc-babel 0.9.1

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.
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Script for the main frame.
3
+ * An adaptation of (darkfish.js by Michael Granger)
4
+ */
5
+
6
+ function setupShowSource() {
7
+ //$('.method-detail').click(showSource);
8
+ $('.method-heading').click(toggleSource);
9
+ };
10
+
11
+ function toggleSource(e) {
12
+ //TODO not when clicking a link
13
+ $(e.target).parents('.method-detail').find('.method-source-code').slideToggle();
14
+ };
15
+
16
+ function setupShowConstantValue() {
17
+ $('#constant-list .const-display').click(toggleValue);
18
+ };
19
+
20
+ function toggleValue(e) {
21
+ //TODO not when clicking a link
22
+ $(this).next().toggle();
23
+ };
24
+
25
+ function setupShowAllFiles() {
26
+ var allFiles = $('#all-files');
27
+ if (allFiles.length == 0) return;
28
+ var skipBodyClick = false;
29
+ $('#show-all-files').click(function(e) {
30
+ e.preventDefault();
31
+ skipBodyClick = true;
32
+ if (allFiles.css('display') == 'block')
33
+ allFiles.css('display', 'none');
34
+ else
35
+ allFiles.css('display', 'block');
36
+ });
37
+ $('body').click(function() {
38
+ if (skipBodyClick)
39
+ skipBodyClick = false;
40
+ else if (allFiles.css('display') == 'block')
41
+ allFiles.css('display', 'none');
42
+ });
43
+ }
44
+
45
+ function setupResizing() {
46
+
47
+ var doc = $('#documentation');
48
+ var delta = $('body').outerHeight() - doc.height();
49
+
50
+ // callback on resize event
51
+ $(window).resize(function() {
52
+ frameResized(doc, delta);
53
+ });
54
+
55
+ // initial resize
56
+ frameResized(doc, delta);
57
+ }
58
+
59
+ function frameResized(doc, delta) {
60
+ var frameHeight = $(window).height();
61
+ if ($.browser.mozilla) frameHeight--;
62
+ newHeight = frameHeight - delta;
63
+ //console.debug('frameHeight: %s', frameHeight);
64
+ //console.debug('delta: %s', delta);
65
+ //console.debug('newHeight: %s', newHeight);
66
+ if (newHeight > 50)
67
+ doc.height(newHeight);
68
+ }
69
+
70
+ function highlightUrlHash() {
71
+ //console.debug('window.location.href: %s', window.location.href);
72
+ var h = window.location.hash;
73
+ if (h && h != '') {
74
+ highlightElement(h);
75
+ }
76
+ };
77
+
78
+ function highlightTarget(e) {
79
+ var href = $(e.target).attr('href');
80
+ //console.debug('Highlighting link href=%s', href);
81
+ var match =/(#.*)/.exec(href);
82
+ if (match && match[1].length > 1) {
83
+ highlightElement(match[1]);
84
+ }
85
+ };
86
+
87
+ function highlightElement(id) {
88
+ //console.debug('Highlighting %s.', id);
89
+ $('.highlighted').removeClass('highlighted');
90
+ var e = $(id);
91
+ if (e.length > 0) {
92
+ e.addClass('highlighted');
93
+ //console.debug('added class "highlighted" to %s.', id);
94
+ }
95
+ else {
96
+ //console.debug('not found: %s', id);
97
+ }
98
+ };
99
+
100
+ $(document).ready( function() {
101
+ setupShowSource();
102
+ setupShowConstantValue();
103
+ setupShowAllFiles();
104
+ //setupResizing(); interferes with hyperlinking
105
+ highlightUrlHash();
106
+ $('a[href*="#"]').click(highlightTarget);
107
+ });
data/lib/rdoc_babel.rb ADDED
@@ -0,0 +1,3 @@
1
+ module RDocBabel
2
+ VERSION = '0.9.1'
3
+ end
@@ -0,0 +1,2 @@
1
+
2
+ This is HISTORY.
@@ -0,0 +1,2 @@
1
+
2
+ This is README.
@@ -0,0 +1,42 @@
1
+
2
+ module Kernel
3
+ def met; end
4
+ end
5
+
6
+ class Object
7
+ def mut; end
8
+ end
9
+
10
+ module Mod1
11
+ # doc
12
+ def met; end
13
+ def nod; end
14
+ def mot; end
15
+ end
16
+
17
+ module Mod2
18
+ include Mod1
19
+ # doc
20
+ def met; end
21
+ end
22
+
23
+ module Mod3
24
+ include Mod2
25
+ def met; end
26
+ def nod; end
27
+ def mot; end # rdoc bug
28
+ end
29
+
30
+ module Mod4
31
+ # doc
32
+ def met; end
33
+ end
34
+
35
+ class Klass
36
+ include Mod1
37
+ include Mod4
38
+ def met; end
39
+ def mut; end
40
+ alias ali met
41
+ alias ald nod
42
+ end
@@ -0,0 +1,2 @@
1
+
2
+ # This file contains a comment.
@@ -0,0 +1,8 @@
1
+
2
+ module Mod1
3
+ def met; end
4
+ end
5
+
6
+ module Mod2
7
+ Mod3 = Mod1
8
+ end
@@ -0,0 +1,15 @@
1
+
2
+ #--
3
+ # This file will be displayed by default if designated
4
+ # as --main, even though the file itself has no comment.
5
+
6
+ module RDocBabel
7
+
8
+ module NotDocumented
9
+ end
10
+
11
+ # This module should be the first displayed.
12
+ module Documented
13
+ end
14
+
15
+ end
@@ -0,0 +1,2 @@
1
+
2
+ puts "Hello"
@@ -0,0 +1,3 @@
1
+
2
+ module RDocBabel
3
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module RDocBabel
3
+ end
4
+
5
+ module RDocBabelNoContent
6
+ end
7
+
8
+ module RDocBabelWithContent
9
+ CONST = 'const'
10
+ end
@@ -0,0 +1,251 @@
1
+ require 'rubygems'
2
+ require 'rdoc/generator/babel'
3
+ require 'minitest/autorun'
4
+ require 'tmpdir'
5
+ require 'nokogiri'
6
+
7
+ class TestRDocGeneratorBabel < MiniTest::Unit::TestCase
8
+
9
+ def setup
10
+
11
+ @srcdir = File.expand_path(File.join(File.dirname(__FILE__), 'data'))
12
+
13
+ @tmpdir = Dir.mktmpdir('rdoc_babel_')
14
+ @delete = true
15
+ @dirnum = 0
16
+
17
+ @main = 'README.rdoc'
18
+ @title = 'Babel Test'
19
+ @charset = 'utf-8'
20
+
21
+ end
22
+
23
+ def teardown
24
+ FileUtils.remove_entry_secure @tmpdir if @delete
25
+ end
26
+
27
+ def test_index
28
+
29
+ make_doc %w(--title Hi --charset iso-8859-1 main_file.rb)
30
+ doc = html_doc('index.html')
31
+
32
+ assert_equal 'Hi', doc.at_css('title').content
33
+ assert_equal 'iso-8859-1', doc.encoding
34
+
35
+ end
36
+
37
+ def test_first_page
38
+
39
+ # - The file designated by the +main_page+ option,
40
+ # if there is a +TopLevel+ with that name.
41
+
42
+ make_doc %w(--main main_file.rb README.rdoc main_file.rb)
43
+ assert_main 'files/main_file_rb.html'
44
+
45
+ make_doc %w(--main does_not_exist.rdoc README.rdoc main_file.rb)
46
+ assert_main 'files/README_rdoc.html'
47
+
48
+ # - The first simple file that contains a comment
49
+ # (in the order given on the command line).
50
+
51
+ make_doc %w(README.rdoc HISTORY.rdoc main_file.rb)
52
+ assert_main 'files/README_rdoc.html'
53
+
54
+ # - The first class or module that contains a comment.
55
+
56
+ make_doc %w(main_file.rb)
57
+ assert_main 'classes/RDocBabel/Documented.html'
58
+
59
+ # - The first file that contains a comment
60
+ # (in the order given on the command line).
61
+
62
+ make_doc %w(not_commented.rb commented.rb)
63
+ assert_main 'files/commented_rb.html'
64
+
65
+ # - The first class or module that has any kind of content.
66
+
67
+ make_doc %w(not_commented.rb)
68
+ assert_main 'classes/RDocBabelWithContent.html'
69
+
70
+ # - The first class or module.
71
+
72
+ make_doc %w(no_content.rb)
73
+ assert_main 'classes/RDocBabel.html'
74
+
75
+ # - The first file.
76
+
77
+ make_doc %w(no_class_nor_module.rb)
78
+ assert_main 'files/no_class_nor_module_rb.html'
79
+
80
+ end
81
+
82
+ def test_indexes
83
+
84
+ make_doc %w(README.rdoc context_alias.rb)
85
+ doc = html_doc('indexes.html')
86
+
87
+ files = doc.at_css('#file-index')
88
+ assert files, 'file index not found'
89
+
90
+ refs = files.css('a')
91
+ assert_equal 1, refs.length
92
+ assert_equal 'README.rdoc', refs.first.content
93
+ assert_equal 'files/README_rdoc.html', refs.first['href']
94
+
95
+ classes = doc.at_css('#class-index')
96
+ assert classes, 'class index not found'
97
+
98
+ refs = classes.css('a')
99
+ assert_equal 3, refs.length
100
+ assert_equal "Mod2::Mod3 \342\206\222 Mod1", refs.last.content
101
+ assert_equal 'classes/Mod1.html', refs.last['href']
102
+
103
+ methods = doc.at_css('#method-index')
104
+ assert methods, 'method index not found'
105
+
106
+ refs = methods.css('a')
107
+ assert_equal 1, refs.length
108
+ assert_equal 'met (Mod1)', refs.first.content
109
+ assert_equal 'classes/Mod1.html#method-i-met', refs.first['href']
110
+
111
+ end
112
+
113
+ def test_description
114
+
115
+ #@delete = false
116
+ make_doc %w(ancestors.rb)
117
+
118
+ doc = html_doc('classes/Klass.html')
119
+
120
+ ali = doc.at_css('#method-i-ali')
121
+ assert ali, 'Klass#ali not found'
122
+ assert ali['class'].include?('method-alias'), 'Klass#ali CSS class missing'
123
+ assert ali.content.include?('Alias for'), 'Klass#ali alias text missing'
124
+
125
+ met = doc.at_css('#method-i-met')
126
+ assert met, 'Klass#met not found'
127
+ assert met.content.include?('See'), 'Klass#met "see" missing'
128
+ assert met.content.include?('aliased'), 'Klass#met "aliased" missing'
129
+
130
+ mut = doc.at_css('#method-i-mut')
131
+ assert mut, 'Klass#mut not found'
132
+ refute mut.content.include?('See'), 'Klass#mut "see" for Object'
133
+
134
+ doc = html_doc('classes/Mod1.html')
135
+
136
+ met = doc.at_css('#method-i-met')
137
+ assert met, 'Mod1#met not found'
138
+ refute met.content.include?('See'), 'Mod1#met "see" for Kernel'
139
+
140
+ end
141
+
142
+ def test_see_standard_ancestors
143
+
144
+ make_doc %w(--see-standard-ancestors ancestors.rb)
145
+
146
+ doc = html_doc('classes/Klass.html')
147
+
148
+ mut = doc.at_css('#method-i-mut')
149
+ assert mut, 'Klass#mut not found'
150
+ assert mut.content.include?('See'), 'Klass#mut "see" for Object'
151
+
152
+ doc = html_doc('classes/Mod1.html')
153
+
154
+ met = doc.at_css('#method-i-met')
155
+ assert met, 'Mod1#met not found'
156
+ assert met.content.include?('See'), 'Mod1#met "see" for Kernel'
157
+
158
+ end
159
+
160
+ def test_decorated_call_seq
161
+
162
+ check_call_seq 'try_convert', <<-CALL, <<-HTML.strip
163
+ IO.try_convert(obj) -> io or nil
164
+ CALL
165
+ IO.<span class="c">try_convert</span>(obj) &rarr; io or nil
166
+ HTML
167
+
168
+ check_call_seq '<<', <<-CALL, <<-HTML.strip
169
+ ios << obj -> ios
170
+ CALL
171
+ ios <span class=\"c\">&lt;&lt;</span> obj &rarr; ios
172
+ HTML
173
+
174
+ check_call_seq 'pos', <<-CALL, <<-HTML.strip.gsub("\n", '')
175
+ ios.pos -> integer
176
+ ios.tell -> integer
177
+ CALL
178
+ ios.<span class=\"c\">pos</span> &rarr; integer<br/>
179
+ ios.tell &rarr; integer
180
+ HTML
181
+
182
+ check_call_seq 'readpartial', <<-CALL, <<-HTML.strip.gsub("\n", '')
183
+ ios.readpartial(maxlen) -> string
184
+ ios.readpartial(maxlen, outbuf) -> outbuf
185
+ CALL
186
+ ios.<span class=\"c\">readpartial</span>(maxlen) &rarr; string<br/>
187
+ ios.<span class=\"c\">readpartial</span>(maxlen, outbuf) &rarr; outbuf
188
+ HTML
189
+
190
+ check_call_seq '[]', <<-CALL, <<-HTML.strip.gsub("\n", '')
191
+ array[index] - obj or nil
192
+ array[start, length] - an_array or nil
193
+ array[range] - an_array or nil
194
+ array.slice(index) - obj or nil
195
+ array.slice(start, length) - an_array or nil
196
+ array.slice(range) - an_array or nil
197
+ CALL
198
+ array<span class=\"c\">[</span>index<span class=\"c\">]</span> - obj or nil<br/>
199
+ array<span class=\"c\">[</span>start, length<span class=\"c\">]</span> - an_array or nil<br/>
200
+ array<span class=\"c\">[</span>range<span class=\"c\">]</span> - an_array or nil<br/>
201
+ array.slice(index) - obj or nil<br/>
202
+ array.slice(start, length) - an_array or nil<br/>
203
+ array.slice(range) - an_array or nil
204
+ HTML
205
+
206
+ end
207
+
208
+ private
209
+
210
+ def make_doc(args)
211
+ Dir.chdir(@srcdir) do
212
+ @dirnum += 1
213
+ @docdir = File.join(@tmpdir, "doc_#@dirnum")
214
+ args = [
215
+ '--quiet',
216
+ '--op', @docdir,
217
+ '--format', 'babel',
218
+ ] + args
219
+ @rdoc = RDoc::RDoc.new
220
+ @rdoc.document args
221
+ end
222
+
223
+ end
224
+
225
+ def check_call_seq(name, call_seq, html)
226
+ m = RDoc::AnyMethod.new(nil, name)
227
+ m.call_seq = call_seq
228
+ assert_equal html, babel_gen.decorated_call_seq(m, 'c')
229
+ end
230
+
231
+ def babel_gen
232
+ @babel_gen ||= begin
233
+ options = Struct.new(:babel_options, :line_numbers, :template).new
234
+ options.template = 'babel'
235
+ options.babel_options = {}
236
+ RDoc::Generator::Babel.new(options)
237
+ end
238
+ end
239
+
240
+ def assert_main(expected_file)
241
+ doc = html_doc('index.html')
242
+ main_frame = doc.at_css 'frame[name = "mainFrame"]'
243
+ assert_equal expected_file, main_frame['src'], "assert_main ##@dirnum"
244
+ end
245
+
246
+ def html_doc(file)
247
+ file = File.join(@docdir, file)
248
+ File.open(file, 'rb') { |f| Nokogiri.HTML f }
249
+ end
250
+
251
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdoc-babel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 57
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 1
10
+ version: 0.9.1
11
+ platform: ruby
12
+ authors:
13
+ - Thierry Lambert
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-17 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ version: "3.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: minitest
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 1
44
+ segments:
45
+ - 1
46
+ - 7
47
+ version: "1.7"
48
+ type: :development
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: nokogiri
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 7
59
+ segments:
60
+ - 1
61
+ - 4
62
+ version: "1.4"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: hoe
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 23
74
+ segments:
75
+ - 2
76
+ - 10
77
+ version: "2.10"
78
+ type: :development
79
+ version_requirements: *id004
80
+ description: |-
81
+ Babel is an RDoc formatter producing HTML documentation.
82
+ The default template is +ruby-lang+.
83
+
84
+ - Look and feel inspired from ruby-lang.org[http://www.ruby-lang.org/].
85
+ - Dual-frame output, with indexes on the left.
86
+ - Search boxes for classes and methods.
87
+ - Links to undocumented classes/methods are grayed.
88
+ - Highlights target methods, attributes and constants.
89
+ - Adds links to ancestor methods/attributes.
90
+ - Borrows some ideas (and one icon) from Darkfish.
91
+ - Tested on Firefox 3.5 & 5, Chrome 9 & 12, Safari 4 & 5.
92
+ email:
93
+ - thyresias@gmail.com
94
+ executables: []
95
+
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - Manifest.txt
100
+ - README.rdoc
101
+ - HISTORY.rdoc
102
+ files:
103
+ - .autotest
104
+ - HISTORY.rdoc
105
+ - Manifest.txt
106
+ - Rakefile
107
+ - README.rdoc
108
+ - lib/rdoc/discover.rb
109
+ - lib/rdoc/generator/babel.rb
110
+ - lib/rdoc/generator/ruby-lang/class-page.html.erb
111
+ - lib/rdoc/generator/ruby-lang/file-page.html.erb
112
+ - lib/rdoc/generator/ruby-lang/images/zoom.png
113
+ - lib/rdoc/generator/ruby-lang/index.html.erb
114
+ - lib/rdoc/generator/ruby-lang/indexes.html.erb
115
+ - lib/rdoc/generator/ruby-lang/rdoc.css
116
+ - lib/rdoc/generator/ruby-lang/scripts/indexFrame.js
117
+ - lib/rdoc/generator/ruby-lang/scripts/jquery.js
118
+ - lib/rdoc/generator/ruby-lang/scripts/jquery.quicksearch.js
119
+ - lib/rdoc/generator/ruby-lang/scripts/mainFrame.js
120
+ - lib/rdoc_babel.rb
121
+ - test/data/ancestors.rb
122
+ - test/data/commented.rb
123
+ - test/data/context_alias.rb
124
+ - test/data/HISTORY.rdoc
125
+ - test/data/main_file.rb
126
+ - test/data/not_commented.rb
127
+ - test/data/no_class_nor_module.rb
128
+ - test/data/no_content.rb
129
+ - test/data/README.rdoc
130
+ - test/test_rdoc_generator_babel.rb
131
+ - .gemtest
132
+ homepage: http://github.com/thyresias/babel
133
+ licenses: []
134
+
135
+ post_install_message:
136
+ rdoc_options:
137
+ - --main
138
+ - README.rdoc
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project: rdoc-babel
162
+ rubygems_version: 1.8.5
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: An RDoc formatter producing HTML documentation.
166
+ test_files:
167
+ - test/test_rdoc_generator_babel.rb