rdoc 2.0.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.
- data/History.txt +13 -0
- data/Manifest.txt +61 -0
- data/README.txt +34 -0
- data/Rakefile +10 -0
- data/bin/rdoc +22 -0
- data/bin/ri +6 -0
- data/lib/rdoc.rb +277 -0
- data/lib/rdoc/code_objects.rb +776 -0
- data/lib/rdoc/diagram.rb +338 -0
- data/lib/rdoc/dot.rb +249 -0
- data/lib/rdoc/generator.rb +1048 -0
- data/lib/rdoc/generator/chm.rb +113 -0
- data/lib/rdoc/generator/chm/chm.rb +98 -0
- data/lib/rdoc/generator/html.rb +370 -0
- data/lib/rdoc/generator/html/hefss.rb +414 -0
- data/lib/rdoc/generator/html/html.rb +704 -0
- data/lib/rdoc/generator/html/kilmer.rb +418 -0
- data/lib/rdoc/generator/html/one_page_html.rb +121 -0
- data/lib/rdoc/generator/ri.rb +229 -0
- data/lib/rdoc/generator/xml.rb +120 -0
- data/lib/rdoc/generator/xml/rdf.rb +113 -0
- data/lib/rdoc/generator/xml/xml.rb +111 -0
- data/lib/rdoc/markup.rb +473 -0
- data/lib/rdoc/markup/attribute_manager.rb +274 -0
- data/lib/rdoc/markup/formatter.rb +14 -0
- data/lib/rdoc/markup/fragments.rb +337 -0
- data/lib/rdoc/markup/inline.rb +101 -0
- data/lib/rdoc/markup/lines.rb +152 -0
- data/lib/rdoc/markup/preprocess.rb +71 -0
- data/lib/rdoc/markup/to_flow.rb +185 -0
- data/lib/rdoc/markup/to_html.rb +353 -0
- data/lib/rdoc/markup/to_html_crossref.rb +86 -0
- data/lib/rdoc/markup/to_latex.rb +328 -0
- data/lib/rdoc/markup/to_test.rb +50 -0
- data/lib/rdoc/options.rb +616 -0
- data/lib/rdoc/parsers/parse_c.rb +775 -0
- data/lib/rdoc/parsers/parse_f95.rb +1841 -0
- data/lib/rdoc/parsers/parse_rb.rb +2584 -0
- data/lib/rdoc/parsers/parse_simple.rb +40 -0
- data/lib/rdoc/parsers/parserfactory.rb +99 -0
- data/lib/rdoc/rdoc.rb +277 -0
- data/lib/rdoc/ri.rb +4 -0
- data/lib/rdoc/ri/cache.rb +188 -0
- data/lib/rdoc/ri/descriptions.rb +150 -0
- data/lib/rdoc/ri/display.rb +274 -0
- data/lib/rdoc/ri/driver.rb +452 -0
- data/lib/rdoc/ri/formatter.rb +616 -0
- data/lib/rdoc/ri/paths.rb +102 -0
- data/lib/rdoc/ri/reader.rb +106 -0
- data/lib/rdoc/ri/util.rb +81 -0
- data/lib/rdoc/ri/writer.rb +68 -0
- data/lib/rdoc/stats.rb +25 -0
- data/lib/rdoc/template.rb +64 -0
- data/lib/rdoc/tokenstream.rb +33 -0
- data/test/test_rdoc_c_parser.rb +261 -0
- data/test/test_rdoc_markup.rb +613 -0
- data/test/test_rdoc_markup_attribute_manager.rb +224 -0
- data/test/test_rdoc_ri_attribute_formatter.rb +42 -0
- data/test/test_rdoc_ri_default_display.rb +295 -0
- data/test/test_rdoc_ri_formatter.rb +318 -0
- data/test/test_rdoc_ri_overstrike_formatter.rb +69 -0
- metadata +134 -0
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'rdoc/generator'
|
2
|
+
require 'rdoc/markup/to_flow'
|
3
|
+
|
4
|
+
require 'rdoc/ri/cache'
|
5
|
+
require 'rdoc/ri/reader'
|
6
|
+
require 'rdoc/ri/writer'
|
7
|
+
require 'rdoc/ri/descriptions'
|
8
|
+
|
9
|
+
class RDoc::Generator::RI
|
10
|
+
|
11
|
+
##
|
12
|
+
# Generator may need to return specific subclasses depending on the
|
13
|
+
# options they are passed. Because of this we create them using a factory
|
14
|
+
|
15
|
+
def self.for(options)
|
16
|
+
new(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
protected :new
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Set up a new RDoc::Generator::RI.
|
25
|
+
|
26
|
+
def initialize(options) #:not-new:
|
27
|
+
@options = options
|
28
|
+
@ri_writer = RDoc::RI::Writer.new "."
|
29
|
+
@markup = RDoc::Markup.new
|
30
|
+
@to_flow = RDoc::Markup::ToFlow.new
|
31
|
+
|
32
|
+
@generated = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Build the initial indices and output objects based on an array of
|
37
|
+
# TopLevel objects containing the extracted information.
|
38
|
+
|
39
|
+
def generate(toplevels)
|
40
|
+
RDoc::TopLevel.all_classes_and_modules.each do |cls|
|
41
|
+
process_class cls
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_class(from_class)
|
46
|
+
generate_class_info(from_class)
|
47
|
+
|
48
|
+
# now recure into this classes constituent classess
|
49
|
+
from_class.each_classmodule do |mod|
|
50
|
+
process_class(mod)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_class_info(cls)
|
55
|
+
if cls === RDoc::NormalModule
|
56
|
+
cls_desc = RDoc::RI::ModuleDescription.new
|
57
|
+
else
|
58
|
+
cls_desc = RDoc::RI::ClassDescription.new
|
59
|
+
cls_desc.superclass = cls.superclass
|
60
|
+
end
|
61
|
+
|
62
|
+
cls_desc.name = cls.name
|
63
|
+
cls_desc.full_name = cls.full_name
|
64
|
+
cls_desc.comment = markup(cls.comment)
|
65
|
+
|
66
|
+
cls_desc.attributes = cls.attributes.sort.map do |a|
|
67
|
+
RDoc::RI::Attribute.new(a.name, a.rw, markup(a.comment))
|
68
|
+
end
|
69
|
+
|
70
|
+
cls_desc.constants = cls.constants.map do |c|
|
71
|
+
RDoc::RI::Constant.new(c.name, c.value, markup(c.comment))
|
72
|
+
end
|
73
|
+
|
74
|
+
cls_desc.includes = cls.includes.map do |i|
|
75
|
+
RDoc::RI::IncludedModule.new(i.name)
|
76
|
+
end
|
77
|
+
|
78
|
+
class_methods, instance_methods = method_list(cls)
|
79
|
+
|
80
|
+
cls_desc.class_methods = class_methods.map do |m|
|
81
|
+
RDoc::RI::MethodSummary.new(m.name)
|
82
|
+
end
|
83
|
+
|
84
|
+
cls_desc.instance_methods = instance_methods.map do |m|
|
85
|
+
RDoc::RI::MethodSummary.new(m.name)
|
86
|
+
end
|
87
|
+
|
88
|
+
update_or_replace(cls_desc)
|
89
|
+
|
90
|
+
class_methods.each do |m|
|
91
|
+
generate_method_info(cls_desc, m)
|
92
|
+
end
|
93
|
+
|
94
|
+
instance_methods.each do |m|
|
95
|
+
generate_method_info(cls_desc, m)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def generate_method_info(cls_desc, method)
|
100
|
+
meth_desc = RDoc::RI::MethodDescription.new
|
101
|
+
meth_desc.name = method.name
|
102
|
+
meth_desc.full_name = cls_desc.full_name
|
103
|
+
if method.singleton
|
104
|
+
meth_desc.full_name += "::"
|
105
|
+
else
|
106
|
+
meth_desc.full_name += "#"
|
107
|
+
end
|
108
|
+
meth_desc.full_name << method.name
|
109
|
+
|
110
|
+
meth_desc.comment = markup(method.comment)
|
111
|
+
meth_desc.params = params_of(method)
|
112
|
+
meth_desc.visibility = method.visibility.to_s
|
113
|
+
meth_desc.is_singleton = method.singleton
|
114
|
+
meth_desc.block_params = method.block_params
|
115
|
+
|
116
|
+
meth_desc.aliases = method.aliases.map do |a|
|
117
|
+
RDoc::RI::AliasName.new(a.name)
|
118
|
+
end
|
119
|
+
|
120
|
+
@ri_writer.add_method(cls_desc, meth_desc)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
##
|
126
|
+
# Returns a list of class and instance methods that we'll be documenting
|
127
|
+
|
128
|
+
def method_list(cls)
|
129
|
+
list = cls.method_list
|
130
|
+
unless @options.show_all
|
131
|
+
list = list.find_all do |m|
|
132
|
+
m.visibility == :public || m.visibility == :protected || m.force_documentation
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
c = []
|
137
|
+
i = []
|
138
|
+
list.sort.each do |m|
|
139
|
+
if m.singleton
|
140
|
+
c << m
|
141
|
+
else
|
142
|
+
i << m
|
143
|
+
end
|
144
|
+
end
|
145
|
+
return c,i
|
146
|
+
end
|
147
|
+
|
148
|
+
def params_of(method)
|
149
|
+
if method.call_seq
|
150
|
+
method.call_seq
|
151
|
+
else
|
152
|
+
params = method.params || ""
|
153
|
+
|
154
|
+
p = params.gsub(/\s*\#.*/, '')
|
155
|
+
p = p.tr("\n", " ").squeeze(" ")
|
156
|
+
p = "(" + p + ")" unless p[0] == ?(
|
157
|
+
|
158
|
+
if (block = method.block_params)
|
159
|
+
block.gsub!(/\s*\#.*/, '')
|
160
|
+
block = block.tr("\n", " ").squeeze(" ")
|
161
|
+
if block[0] == ?(
|
162
|
+
block.sub!(/^\(/, '').sub!(/\)/, '')
|
163
|
+
end
|
164
|
+
p << " {|#{block.strip}| ...}"
|
165
|
+
end
|
166
|
+
p
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def markup(comment)
|
171
|
+
return nil if !comment || comment.empty?
|
172
|
+
|
173
|
+
# Convert leading comment markers to spaces, but only
|
174
|
+
# if all non-blank lines have them
|
175
|
+
|
176
|
+
if comment =~ /^(?>\s*)[^\#]/
|
177
|
+
content = comment
|
178
|
+
else
|
179
|
+
content = comment.gsub(/^\s*(#+)/) { $1.tr('#',' ') }
|
180
|
+
end
|
181
|
+
@markup.convert(content, @to_flow)
|
182
|
+
end
|
183
|
+
|
184
|
+
##
|
185
|
+
# By default we replace existing classes with the same name. If the
|
186
|
+
# --merge option was given, we instead merge this definition into an
|
187
|
+
# existing class. We add our methods, aliases, etc to that class, but do
|
188
|
+
# not change the class's description.
|
189
|
+
|
190
|
+
def update_or_replace(cls_desc)
|
191
|
+
old_cls = nil
|
192
|
+
|
193
|
+
if @options.merge
|
194
|
+
rdr = RDoc::RI::Reader.new RDoc::RI::Cache.new(@options.op_dir)
|
195
|
+
|
196
|
+
namespace = rdr.top_level_namespace
|
197
|
+
namespace = rdr.lookup_namespace_in(cls_desc.name, namespace)
|
198
|
+
if namespace.empty?
|
199
|
+
$stderr.puts "You asked me to merge this source into existing "
|
200
|
+
$stderr.puts "documentation. This file references a class or "
|
201
|
+
$stderr.puts "module called #{cls_desc.name} which I don't"
|
202
|
+
$stderr.puts "have existing documentation for."
|
203
|
+
$stderr.puts
|
204
|
+
$stderr.puts "Perhaps you need to generate its documentation first"
|
205
|
+
exit 1
|
206
|
+
else
|
207
|
+
old_cls = namespace[0]
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
prev_cls = @generated[cls_desc.full_name]
|
212
|
+
|
213
|
+
if old_cls and not prev_cls then
|
214
|
+
old_desc = rdr.get_class old_cls
|
215
|
+
cls_desc.merge_in old_desc
|
216
|
+
end
|
217
|
+
|
218
|
+
if prev_cls then
|
219
|
+
cls_desc.merge_in prev_cls
|
220
|
+
end
|
221
|
+
|
222
|
+
@generated[cls_desc.full_name] = cls_desc
|
223
|
+
|
224
|
+
@ri_writer.remove_class cls_desc
|
225
|
+
@ri_writer.add_class cls_desc
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'rdoc/generator/html'
|
2
|
+
|
3
|
+
##
|
4
|
+
# Generate XML output as one big file
|
5
|
+
|
6
|
+
class RDoc::Generator::XML < RDoc::Generator::HTML
|
7
|
+
|
8
|
+
##
|
9
|
+
# Standard generator factory
|
10
|
+
|
11
|
+
def self.for(options)
|
12
|
+
new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Build the initial indices and output objects
|
21
|
+
# based on an array of TopLevel objects containing
|
22
|
+
# the extracted information.
|
23
|
+
|
24
|
+
def generate(info)
|
25
|
+
@info = info
|
26
|
+
@files = []
|
27
|
+
@classes = []
|
28
|
+
@hyperlinks = {}
|
29
|
+
|
30
|
+
build_indices
|
31
|
+
generate_xml
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Generate:
|
36
|
+
#
|
37
|
+
# * a list of HtmlFile objects for each TopLevel object.
|
38
|
+
# * a list of HtmlClass objects for each first level
|
39
|
+
# class or module in the TopLevel objects
|
40
|
+
# * a complete list of all hyperlinkable terms (file,
|
41
|
+
# class, module, and method names)
|
42
|
+
|
43
|
+
def build_indices
|
44
|
+
@info.each do |toplevel|
|
45
|
+
@files << RDoc::Generator::HtmlFile.new(toplevel, @options, RDoc::Generator::FILE_DIR)
|
46
|
+
end
|
47
|
+
|
48
|
+
RDoc::TopLevel.all_classes_and_modules.each do |cls|
|
49
|
+
build_class_list(cls, @files[0], RDoc::Generator::CLASS_DIR)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_class_list(from, html_file, class_dir)
|
54
|
+
@classes << RDoc::Generator::HtmlClass.new(from, html_file, class_dir, @options)
|
55
|
+
from.each_classmodule do |mod|
|
56
|
+
build_class_list(mod, html_file, class_dir)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Generate all the HTML. For the one-file case, we generate
|
62
|
+
# all the information in to one big hash
|
63
|
+
|
64
|
+
def generate_xml
|
65
|
+
values = {
|
66
|
+
'charset' => @options.charset,
|
67
|
+
'files' => gen_into(@files),
|
68
|
+
'classes' => gen_into(@classes)
|
69
|
+
}
|
70
|
+
|
71
|
+
# this method is defined in the template file
|
72
|
+
write_extra_pages if defined? write_extra_pages
|
73
|
+
|
74
|
+
template = RDoc::TemplatePage.new @template::ONE_PAGE
|
75
|
+
|
76
|
+
if @options.op_name
|
77
|
+
opfile = File.open(@options.op_name, "w")
|
78
|
+
else
|
79
|
+
opfile = $stdout
|
80
|
+
end
|
81
|
+
template.write_html_on(opfile, values)
|
82
|
+
end
|
83
|
+
|
84
|
+
def gen_into(list)
|
85
|
+
res = []
|
86
|
+
list.each do |item|
|
87
|
+
res << item.value_hash
|
88
|
+
end
|
89
|
+
res
|
90
|
+
end
|
91
|
+
|
92
|
+
def gen_file_index
|
93
|
+
gen_an_index(@files, 'Files')
|
94
|
+
end
|
95
|
+
|
96
|
+
def gen_class_index
|
97
|
+
gen_an_index(@classes, 'Classes')
|
98
|
+
end
|
99
|
+
|
100
|
+
def gen_method_index
|
101
|
+
gen_an_index(RDoc::Generator::HtmlMethod.all_methods, 'Methods')
|
102
|
+
end
|
103
|
+
|
104
|
+
def gen_an_index(collection, title)
|
105
|
+
res = []
|
106
|
+
collection.sort.each do |f|
|
107
|
+
if f.document_self
|
108
|
+
res << { "href" => f.path, "name" => f.index_name }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
return {
|
113
|
+
"entries" => res,
|
114
|
+
'list_title' => title,
|
115
|
+
'index_url' => main_url,
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rdoc/generator/xml'
|
2
|
+
|
3
|
+
module RDoc::Generator::XML::RDF
|
4
|
+
|
5
|
+
CONTENTS_RDF = <<-EOF
|
6
|
+
<% if defined? classes and classes["description"] then %>
|
7
|
+
<description rd:parseType="Literal">
|
8
|
+
<%= classes["description"] %>
|
9
|
+
</description>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<% if defined? files and files["requires"] then %>
|
13
|
+
<% files["requires"].each do |requires| %>
|
14
|
+
<rd:required-file rd:name="<%= requires["name"] %>" />
|
15
|
+
<% end # files["requires"] %>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<% if defined? classes and classes["includes"] then %>
|
19
|
+
<IncludedModuleList>
|
20
|
+
<% classes["includes"].each do |includes| %>
|
21
|
+
<included-module rd:name="<%= includes["name"] %>" />
|
22
|
+
<% end # includes["includes"] %>
|
23
|
+
</IncludedModuleList>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<% if defined? classes and classes["sections"] then %>
|
27
|
+
<% classes["sections"].each do |sections| %>
|
28
|
+
<% if sections["attributes"] then %>
|
29
|
+
<% sections["attributes"].each do |attributes| %>
|
30
|
+
<contents>
|
31
|
+
<Attribute rd:name="<%= attributes["name"] %>">
|
32
|
+
<% if attributes["rw"] then %>
|
33
|
+
<attribute-rw><%= attributes["rw"] %></attribute-rw>
|
34
|
+
<% end %>
|
35
|
+
<description rdf:parseType="Literal"><%= attributes["a_desc"] %></description>
|
36
|
+
</Attribute>
|
37
|
+
</contents>
|
38
|
+
<% end # sections["attributes"] %>
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<% if sections["method_list"] then %>
|
42
|
+
<% sections["method_list"].each do |method_list| %>
|
43
|
+
<% if method_list["methods"] then %>
|
44
|
+
<% method_list["methods"].each do |methods| %>
|
45
|
+
<contents>
|
46
|
+
<Method rd:name="<%= methods["name"] %>" rd:visibility="<%= methods["type"] %>"
|
47
|
+
rd:category="<%= methods["category"] %>" rd:id="<%= methods["aref"] %>">
|
48
|
+
<parameters><%= methods["params"] %></parameters>
|
49
|
+
<% if methods["m_desc"] then %>
|
50
|
+
<description rdf:parseType="Literal">
|
51
|
+
<%= methods["m_desc"] %>
|
52
|
+
</description>
|
53
|
+
<% end %>
|
54
|
+
<% if methods["sourcecode"] then %>
|
55
|
+
<source-code-listing rdf:parseType="Literal">
|
56
|
+
<%= methods["sourcecode"] %>
|
57
|
+
</source-code-listing>
|
58
|
+
<% end %>
|
59
|
+
</Method>
|
60
|
+
</contents>
|
61
|
+
<% end # method_list["methods"] %>
|
62
|
+
<% end %>
|
63
|
+
<% end # sections["method_list"] %>
|
64
|
+
<% end %>
|
65
|
+
<!-- end method list -->
|
66
|
+
<% end # classes["sections"] %>
|
67
|
+
<% end %>
|
68
|
+
EOF
|
69
|
+
|
70
|
+
########################################################################
|
71
|
+
|
72
|
+
ONE_PAGE = %{<?xml version="1.0" encoding="utf-8"?>
|
73
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
74
|
+
xmlns="http://pragprog.com/rdoc/rdoc.rdf#"
|
75
|
+
xmlns:rd="http://pragprog.com/rdoc/rdoc.rdf#">
|
76
|
+
|
77
|
+
<!-- RDoc -->
|
78
|
+
<% values["files"].each do |files| %>
|
79
|
+
<rd:File rd:name="<%= files["short_name"] %>" rd:id="<%= files["href"] %>">
|
80
|
+
<path><%= files["full_path"] %></path>
|
81
|
+
<dtm-modified><%= files["dtm_modified"] %></dtm-modified>
|
82
|
+
} + CONTENTS_RDF + %{
|
83
|
+
</rd:File>
|
84
|
+
<% end # values["files"] %>
|
85
|
+
<% values["classes"].each do |classes| %>
|
86
|
+
<<%= values["classmod"] %> rd:name="<%= classes["full_name"] %>" rd:id="<%= classes["full_name"] %>">
|
87
|
+
<classmod-info>
|
88
|
+
<% if classes["infiles"] then %>
|
89
|
+
<InFiles>
|
90
|
+
<% classes["infiles"].each do |infiles| %>
|
91
|
+
<infile>
|
92
|
+
<File rd:name="<%= infiles["full_path"] %>"
|
93
|
+
<% if infiles["full_path_url"] then %>
|
94
|
+
rdf:about="<%= infiles["full_path_url"] %>"
|
95
|
+
<% end %>
|
96
|
+
/>
|
97
|
+
</infile>
|
98
|
+
<% end # classes["infiles"] %>
|
99
|
+
</InFiles>
|
100
|
+
<% end %>
|
101
|
+
<% if classes["parent"] then %>
|
102
|
+
<superclass><%= href classes["par_url"], classes["parent"] %></superclass>
|
103
|
+
<% end %>
|
104
|
+
</classmod-info>
|
105
|
+
} + CONTENTS_RDF + %{
|
106
|
+
</<%= classes["classmod"] %>>
|
107
|
+
<% end # values["classes"] %>
|
108
|
+
<!-- /RDoc -->
|
109
|
+
</rdf:RDF>
|
110
|
+
}
|
111
|
+
|
112
|
+
end
|
113
|
+
|