rdoc-f95 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +79 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +147 -0
- data/Rakefile +28 -0
- data/bin/rdoc-f95 +70 -0
- data/lib/rdoc-f95.rb +306 -0
- data/lib/rdoc-f95/code_objects.rb +776 -0
- data/lib/rdoc-f95/diagram.rb +342 -0
- data/lib/rdoc-f95/dot.rb +249 -0
- data/lib/rdoc-f95/generator.rb +1088 -0
- data/lib/rdoc-f95/generator/chm.rb +113 -0
- data/lib/rdoc-f95/generator/chm/chm.rb +98 -0
- data/lib/rdoc-f95/generator/html.rb +370 -0
- data/lib/rdoc-f95/generator/html/hefss.rb +414 -0
- data/lib/rdoc-f95/generator/html/html.rb +708 -0
- data/lib/rdoc-f95/generator/html/kilmer.rb +418 -0
- data/lib/rdoc-f95/generator/html/one_page_html.rb +121 -0
- data/lib/rdoc-f95/generator/ri.rb +229 -0
- data/lib/rdoc-f95/generator/xhtml.rb +106 -0
- data/lib/rdoc-f95/generator/xhtml/ctop.xsl +1318 -0
- data/lib/rdoc-f95/generator/xhtml/mathml.xsl +42 -0
- data/lib/rdoc-f95/generator/xhtml/pmathml.xsl +612 -0
- data/lib/rdoc-f95/generator/xhtml/pmathmlcss.xsl +872 -0
- data/lib/rdoc-f95/generator/xhtml/xhtml.rb +732 -0
- data/lib/rdoc-f95/generator/xml.rb +120 -0
- data/lib/rdoc-f95/generator/xml/rdf.rb +113 -0
- data/lib/rdoc-f95/generator/xml/xml.rb +111 -0
- data/lib/rdoc-f95/install.rb +166 -0
- data/lib/rdoc-f95/markup.rb +506 -0
- data/lib/rdoc-f95/markup/formatter.rb +14 -0
- data/lib/rdoc-f95/markup/fragments.rb +337 -0
- data/lib/rdoc-f95/markup/inline.rb +361 -0
- data/lib/rdoc-f95/markup/install.rb +57 -0
- data/lib/rdoc-f95/markup/lines.rb +152 -0
- data/lib/rdoc-f95/markup/mathml_wrapper.rb +91 -0
- data/lib/rdoc-f95/markup/preprocess.rb +71 -0
- data/lib/rdoc-f95/markup/sample/rdoc2latex.rb +16 -0
- data/lib/rdoc-f95/markup/sample/sample.rb +42 -0
- data/lib/rdoc-f95/markup/to_flow.rb +185 -0
- data/lib/rdoc-f95/markup/to_html.rb +357 -0
- data/lib/rdoc-f95/markup/to_html_crossref.rb +123 -0
- data/lib/rdoc-f95/markup/to_latex.rb +328 -0
- data/lib/rdoc-f95/markup/to_test.rb +50 -0
- data/lib/rdoc-f95/markup/to_xhtml_texparser.rb +234 -0
- data/lib/rdoc-f95/options.rb +745 -0
- data/lib/rdoc-f95/parsers/parse_c.rb +775 -0
- data/lib/rdoc-f95/parsers/parse_f95.rb +2499 -0
- data/lib/rdoc-f95/parsers/parse_rb.rb +2587 -0
- data/lib/rdoc-f95/parsers/parse_simple.rb +39 -0
- data/lib/rdoc-f95/parsers/parserfactory.rb +99 -0
- data/lib/rdoc-f95/ri.rb +2 -0
- data/lib/rdoc-f95/ri/cache.rb +188 -0
- data/lib/rdoc-f95/ri/descriptions.rb +147 -0
- data/lib/rdoc-f95/ri/display.rb +244 -0
- data/lib/rdoc-f95/ri/driver.rb +435 -0
- data/lib/rdoc-f95/ri/formatter.rb +603 -0
- data/lib/rdoc-f95/ri/paths.rb +105 -0
- data/lib/rdoc-f95/ri/reader.rb +106 -0
- data/lib/rdoc-f95/ri/util.rb +81 -0
- data/lib/rdoc-f95/ri/writer.rb +64 -0
- data/lib/rdoc-f95/stats.rb +23 -0
- data/lib/rdoc-f95/template.rb +64 -0
- data/lib/rdoc-f95/tokenstream.rb +33 -0
- data/lib/rdoc-f95/usage.rb +210 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_rdoc-f95.rb +11 -0
- metadata +156 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
lib/rdoc-f95.rb
|
7
|
+
script/console
|
8
|
+
script/destroy
|
9
|
+
script/generate
|
10
|
+
test/test_helper.rb
|
11
|
+
test/test_rdoc-f95.rb
|
12
|
+
bin/rdoc-f95
|
13
|
+
lib/rdoc-f95/code_objects.rb
|
14
|
+
lib/rdoc-f95/diagram.rb
|
15
|
+
lib/rdoc-f95/dot.rb
|
16
|
+
lib/rdoc-f95/generator
|
17
|
+
lib/rdoc-f95/generator/chm.rb
|
18
|
+
lib/rdoc-f95/generator/html.rb
|
19
|
+
lib/rdoc-f95/generator/ri.rb
|
20
|
+
lib/rdoc-f95/generator/xhtml.rb
|
21
|
+
lib/rdoc-f95/generator/xml.rb
|
22
|
+
lib/rdoc-f95/generator/chm
|
23
|
+
lib/rdoc-f95/generator/chm/chm.rb
|
24
|
+
lib/rdoc-f95/generator/html
|
25
|
+
lib/rdoc-f95/generator/html/hefss.rb
|
26
|
+
lib/rdoc-f95/generator/html/html.rb
|
27
|
+
lib/rdoc-f95/generator/html/kilmer.rb
|
28
|
+
lib/rdoc-f95/generator/html/one_page_html.rb
|
29
|
+
lib/rdoc-f95/generator/xhtml
|
30
|
+
lib/rdoc-f95/generator/xhtml/ctop.xsl
|
31
|
+
lib/rdoc-f95/generator/xhtml/mathml.xsl
|
32
|
+
lib/rdoc-f95/generator/xhtml/pmathml.xsl
|
33
|
+
lib/rdoc-f95/generator/xhtml/pmathmlcss.xsl
|
34
|
+
lib/rdoc-f95/generator/xhtml/xhtml.rb
|
35
|
+
lib/rdoc-f95/generator/xml
|
36
|
+
lib/rdoc-f95/generator/xml/rdf.rb
|
37
|
+
lib/rdoc-f95/generator/xml/xml.rb
|
38
|
+
lib/rdoc-f95/generator.rb
|
39
|
+
lib/rdoc-f95/install.rb
|
40
|
+
lib/rdoc-f95/markup
|
41
|
+
lib/rdoc-f95/markup/formatter.rb
|
42
|
+
lib/rdoc-f95/markup/fragments.rb
|
43
|
+
lib/rdoc-f95/markup/inline.rb
|
44
|
+
lib/rdoc-f95/markup/install.rb
|
45
|
+
lib/rdoc-f95/markup/lines.rb
|
46
|
+
lib/rdoc-f95/markup/mathml_wrapper.rb
|
47
|
+
lib/rdoc-f95/markup/preprocess.rb
|
48
|
+
lib/rdoc-f95/markup/to_flow.rb
|
49
|
+
lib/rdoc-f95/markup/to_html.rb
|
50
|
+
lib/rdoc-f95/markup/to_html_crossref.rb
|
51
|
+
lib/rdoc-f95/markup/to_latex.rb
|
52
|
+
lib/rdoc-f95/markup/to_test.rb
|
53
|
+
lib/rdoc-f95/markup/to_xhtml_texparser.rb
|
54
|
+
lib/rdoc-f95/markup/sample
|
55
|
+
lib/rdoc-f95/markup/sample/rdoc2latex.rb
|
56
|
+
lib/rdoc-f95/markup/sample/sample.rb
|
57
|
+
lib/rdoc-f95/markup.rb
|
58
|
+
lib/rdoc-f95/options.rb
|
59
|
+
lib/rdoc-f95/parsers
|
60
|
+
lib/rdoc-f95/parsers/parse_c.rb
|
61
|
+
lib/rdoc-f95/parsers/parse_f95.rb
|
62
|
+
lib/rdoc-f95/parsers/parse_rb.rb
|
63
|
+
lib/rdoc-f95/parsers/parse_simple.rb
|
64
|
+
lib/rdoc-f95/parsers/parserfactory.rb
|
65
|
+
lib/rdoc-f95/ri
|
66
|
+
lib/rdoc-f95/ri/cache.rb
|
67
|
+
lib/rdoc-f95/ri/descriptions.rb
|
68
|
+
lib/rdoc-f95/ri/display.rb
|
69
|
+
lib/rdoc-f95/ri/driver.rb
|
70
|
+
lib/rdoc-f95/ri/formatter.rb
|
71
|
+
lib/rdoc-f95/ri/paths.rb
|
72
|
+
lib/rdoc-f95/ri/reader.rb
|
73
|
+
lib/rdoc-f95/ri/util.rb
|
74
|
+
lib/rdoc-f95/ri/writer.rb
|
75
|
+
lib/rdoc-f95/ri.rb
|
76
|
+
lib/rdoc-f95/stats.rb
|
77
|
+
lib/rdoc-f95/template.rb
|
78
|
+
lib/rdoc-f95/tokenstream.rb
|
79
|
+
lib/rdoc-f95/usage.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
= rdoc-f95: Enhanced version of RDoc Fortran 90/95 parser
|
2
|
+
|
3
|
+
* Project Page: http://rubyforge.org/projects/rdoc/
|
4
|
+
* Documentation: http://rdoc-f95.rubyforge.org/
|
5
|
+
|
6
|
+
== INSTALLATION
|
7
|
+
|
8
|
+
% sudo gem install rdoc-f95
|
9
|
+
|
10
|
+
== USAGE
|
11
|
+
|
12
|
+
Set the environment variable *PATH* to include
|
13
|
+
the directory where the execution program is installed,
|
14
|
+
and *RUBYLIB* to include the directory
|
15
|
+
where the libraries are installed.
|
16
|
+
|
17
|
+
Move to a directory where your Fortran 90/95 files exist,
|
18
|
+
and execute the following command. HTML documents will be generated in
|
19
|
+
*doc* directory.
|
20
|
+
|
21
|
+
% rdoc-f95 -U --ignore-case --inline-source
|
22
|
+
|
23
|
+
Files ending <tt>.f90</tt>, <tt>.F90</tt>, <tt>.f95</tt>, <tt>.F95</tt>
|
24
|
+
are parsed as Fortran 90/95 programs.
|
25
|
+
All Fortran 90/95 programs in subdirectories are parsed recursively.
|
26
|
+
|
27
|
+
Just as in the original RDoc, files ending with <tt>.rb</tt> and <tt>.rbw</tt>
|
28
|
+
are parsed as Ruby programs and files ending with <tt>.c</tt>, <tt>.cc</tt>,
|
29
|
+
<tt>.cpp</tt>, <tt>.CC</tt>, <tt>.cxx</tt> are parsed as C programs.
|
30
|
+
|
31
|
+
With the option <tt>--op</tt>,
|
32
|
+
the directory where HTML documents are generated can be changed.
|
33
|
+
<tt>--title</tt> option sets title of HTML documents.
|
34
|
+
When <tt>--all</tt> option is used,
|
35
|
+
private subroutines, functions etc. in
|
36
|
+
Fortran 90/95 programs are shown in HTML documents (for developers).
|
37
|
+
If files or directories are specified as arguments (for example,
|
38
|
+
"<tt>src/*.f90</tt>" or "<tt>test/</tt>"), the particular files
|
39
|
+
are parsed.
|
40
|
+
In the following example, files with suffix "<tt>.f90</tt>" in a
|
41
|
+
directory "<tt>src/</tt>" and files in a directory "<tt>test/</tt>"
|
42
|
+
are parsed.
|
43
|
+
|
44
|
+
% rdoc-f95 -U --ignore-case --inline-source \
|
45
|
+
--op rdoc --title "RDoc documentations" src/*.f90 test/
|
46
|
+
|
47
|
+
Alternatively, you can parse only a part of files by creating a
|
48
|
+
"<tt>.document</tt>" file and writing names of the files and the
|
49
|
+
directories to the file.
|
50
|
+
|
51
|
+
For more information,
|
52
|
+
see http://www.ruby-doc.org/stdlib/libdoc/rdoc/rdoc/index.html
|
53
|
+
|
54
|
+
|
55
|
+
== RULES for RDocF95 Document
|
56
|
+
|
57
|
+
Refer to {parse_f95.rb}[link:files/lib/rdoc-f95/parsers/parse_f95_rb.html] which
|
58
|
+
explains parsed information, way of looking at documents,
|
59
|
+
the format of comment blocks in Fortran 90/95 source code.
|
60
|
+
If you use "--mathml" option (see below),
|
61
|
+
refer to <b>RDoc::Markup::ToXHtmlTexParser</b>, too.
|
62
|
+
For general information, see
|
63
|
+
http://www.ruby-doc.org/stdlib/libdoc/rdoc/rdoc/index.html
|
64
|
+
|
65
|
+
== SAMPLES
|
66
|
+
|
67
|
+
* {Code reference of gtool5 library that is a Fortran 90/95 library for numerical models for geophysical fluid (only JAPANESE)}[http://www.gfd-dennou.org/library/gtool/gtool5/gtool5_current/doc/develop_reference/]
|
68
|
+
|
69
|
+
* {Code reference of planetary atmospheric general circulation model DCPAM}[http://www.gfd-dennou.org/library/dcpam/dcpam5/dcpam5_current/doc/code_reference/xml]
|
70
|
+
|
71
|
+
== DIFFERENCES from original RDoc
|
72
|
+
|
73
|
+
This patch has been created for enhancing the Fortran 90/95 parser of RDoc .
|
74
|
+
{The Fortran 90/95 parse script}[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/rdoc/parser/f95.rb]
|
75
|
+
is mainly modified, and other programs are also improved.
|
76
|
+
|
77
|
+
|
78
|
+
The original RDoc has been developed by Dave Thomas and is now
|
79
|
+
maintained by Ryan Davis and Eric Hodel, etc. .
|
80
|
+
The RDoc is available from the Ruby source code repository.
|
81
|
+
See {Ruby Repository Guide}[http://www.ruby-lang.org/en/news/2006/12/22/cvs-repository-moved-to-svn/].
|
82
|
+
For more information about RDoc, see
|
83
|
+
http://www.ruby-doc.org/stdlib/libdoc/rdoc/rdoc/index.html
|
84
|
+
or
|
85
|
+
{RubyForge: rdoc Project}[http://rubyforge.org/projects/rdoc]
|
86
|
+
|
87
|
+
Differences to the original one are given below.
|
88
|
+
|
89
|
+
--
|
90
|
+
#<b>Enhancement of an analytical performance of Fortran 90/95 source codes</b> ::
|
91
|
+
# See lib/rdoc-f95/parsers/parse_f95.rb for details.
|
92
|
+
|
93
|
+
#<b>Modification of format of comment blocks</b> ::
|
94
|
+
# See lib/rdoc-f95/parsers/parse_f95.rb for details.
|
95
|
+
++
|
96
|
+
|
97
|
+
<b>Addition of <tt>--ignore-case</tt> option </b> ::
|
98
|
+
In the Fortran 90/95 Standard,
|
99
|
+
upper case letters are not distinguished from lower case letters,
|
100
|
+
although original RDoc produces case-dependently
|
101
|
+
cross-references of Class and Methods.
|
102
|
+
When this options is specified,
|
103
|
+
upper cases are not distinguished from lower cases.
|
104
|
+
|
105
|
+
<b>Cross-reference of file names</b> ::
|
106
|
+
Cross-reference of file names is available as well as
|
107
|
+
modules, subroutines, and so on.
|
108
|
+
|
109
|
+
<b>Modification of <tt>--style</tt> option</b> ::
|
110
|
+
Original RDoc can not treat relative path stylesheet.
|
111
|
+
Application of this patch modifies this function.
|
112
|
+
|
113
|
+
<b>Conversion of TeX formula into MathML</b>::
|
114
|
+
TeX formula can be converted into MathML format
|
115
|
+
with --mathml option,
|
116
|
+
if <b>MathML library for Ruby version 0.6b -- 0.8</b> is installed.
|
117
|
+
This library is available from {Bottega of Hiraku (only JAPANESE)}[http://www.hinet.mydns.jp/~hiraku/].
|
118
|
+
See <b>RDoc::Markup::ToXHtmlTexParser</b> about format.
|
119
|
+
|
120
|
+
<b>*** Caution ***</b>
|
121
|
+
Documents generated with "--mathml" option are not displayed correctly
|
122
|
+
according to browser and/or its setting.
|
123
|
+
We have been confirmed that
|
124
|
+
documents generated with "--mathml" option are displayed correctly
|
125
|
+
with {Mozilla Firefox}[http://www.mozilla.org/products/firefox/]
|
126
|
+
and Internet Explorer
|
127
|
+
(+ {MathPlayer}[http://www.dessci.com/en/products/mathplayer/]).
|
128
|
+
See {MathML Software - Browsers}[http://www.w3.org/Math/Software/mathml_software_cat_browsers.html]
|
129
|
+
for other browsers.
|
130
|
+
|
131
|
+
Some formats of comments in HTML document are changed
|
132
|
+
to improve the analysis features.
|
133
|
+
See {parse_f95.rb}[link:files/lib/rdoc-f95/parsers/parse_f95_rb.html]
|
134
|
+
|
135
|
+
== LICENSE
|
136
|
+
|
137
|
+
Licence of the enhanced version of RDoc Fortran 90/95 parser
|
138
|
+
conforms to that of original RDoc.
|
139
|
+
see http://rdoc.rubyforge.org/
|
140
|
+
|
141
|
+
|
142
|
+
== HISTORY
|
143
|
+
|
144
|
+
=== 0.0.1
|
145
|
+
|
146
|
+
* Initial release
|
147
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/rdoc-f95'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('rdoc-f95', RDocF95::VERSION) do |p|
|
7
|
+
p.developer('FIXME full name', 'morikawa@gfd-dennou.org')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# task :default => [:spec, :features]
|
data/bin/rdoc-f95
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# RDoc: Documentation tool for source code
|
4
|
+
# (see lib/rdoc/rdoc.rb for more information)
|
5
|
+
#
|
6
|
+
# Copyright (c) 2003 Dave Thomas
|
7
|
+
# Released under the same terms as Ruby
|
8
|
+
#
|
9
|
+
# $Revision: 1.2 $
|
10
|
+
|
11
|
+
## Transitional Hack ####
|
12
|
+
#
|
13
|
+
# RDoc was initially distributed independently, and installed
|
14
|
+
# itself into <prefix>/lib/ruby/site_ruby/<ver>/rdoc...
|
15
|
+
#
|
16
|
+
# Now that RDoc is part of the distribution, it's installed into
|
17
|
+
# <prefix>/lib/ruby/<ver>, which unfortunately appears later in the
|
18
|
+
# search path. This means that if you have previously installed RDoc,
|
19
|
+
# and then install from ruby-lang, you'll pick up the old one by
|
20
|
+
# default. This hack checks for the condition, and readjusts the
|
21
|
+
# search path if necessary.
|
22
|
+
|
23
|
+
#def adjust_for_existing_rdoc(path)
|
24
|
+
#
|
25
|
+
# $stderr.puts %{
|
26
|
+
# It seems as if you have a previously-installed RDoc in
|
27
|
+
# the directory #{path}.
|
28
|
+
#
|
29
|
+
# Because this is now out-of-date, you might want to consider
|
30
|
+
# removing the directories:
|
31
|
+
#
|
32
|
+
# #{File.join(path, "rdoc")}
|
33
|
+
#
|
34
|
+
# and
|
35
|
+
#
|
36
|
+
# #{File.join(path, "markup")}
|
37
|
+
#
|
38
|
+
# }
|
39
|
+
#
|
40
|
+
# # Move all the site_ruby directories to the end
|
41
|
+
# p $:
|
42
|
+
# $:.replace($:.partition {|path| /site_ruby/ !~ path}.flatten)
|
43
|
+
# p $:
|
44
|
+
#end
|
45
|
+
#
|
46
|
+
# $:.each do |path|
|
47
|
+
# if /site_ruby/ =~ path
|
48
|
+
# rdoc_path = File.join(path, 'rdoc', 'rdoc.rb')
|
49
|
+
# if File.exists?(rdoc_path)
|
50
|
+
# adjust_for_existing_rdoc(path)
|
51
|
+
# break
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
#end
|
55
|
+
|
56
|
+
## End of Transitional Hack ##
|
57
|
+
|
58
|
+
|
59
|
+
require 'rdoc-f95'
|
60
|
+
|
61
|
+
begin
|
62
|
+
r = RDocF95::RDocF95.new
|
63
|
+
r.document ARGV
|
64
|
+
rescue Interrupt
|
65
|
+
$stderr.puts
|
66
|
+
$stderr.puts "Interrupted"
|
67
|
+
rescue RDocF95::Error => e
|
68
|
+
$stderr.puts e.message
|
69
|
+
exit 1
|
70
|
+
end
|
data/lib/rdoc-f95.rb
ADDED
@@ -0,0 +1,306 @@
|
|
1
|
+
# See README.
|
2
|
+
#
|
3
|
+
|
4
|
+
|
5
|
+
require 'rdoc-f95/parsers/parse_rb.rb'
|
6
|
+
require 'rdoc-f95/parsers/parse_c.rb'
|
7
|
+
require 'rdoc-f95/parsers/parse_f95.rb'
|
8
|
+
require 'rdoc-f95/parsers/parse_simple.rb'
|
9
|
+
|
10
|
+
require 'rdoc-f95/stats'
|
11
|
+
require 'rdoc-f95/options'
|
12
|
+
|
13
|
+
require 'rdoc-f95/diagram'
|
14
|
+
|
15
|
+
require 'find'
|
16
|
+
require 'fileutils'
|
17
|
+
require 'time'
|
18
|
+
|
19
|
+
module RDocF95
|
20
|
+
|
21
|
+
##
|
22
|
+
# RDoc version you are using
|
23
|
+
|
24
|
+
VERSION = '0.0.1'
|
25
|
+
|
26
|
+
##
|
27
|
+
# Exception thrown by any rdoc error.
|
28
|
+
|
29
|
+
class Error < RuntimeError; end
|
30
|
+
|
31
|
+
RDocError = Error # :nodoc:
|
32
|
+
|
33
|
+
DOT_DOC_FILENAME = ".document"
|
34
|
+
|
35
|
+
GENERAL_MODIFIERS = %w[nodoc].freeze
|
36
|
+
|
37
|
+
CLASS_MODIFIERS = GENERAL_MODIFIERS
|
38
|
+
|
39
|
+
ATTR_MODIFIERS = GENERAL_MODIFIERS
|
40
|
+
|
41
|
+
CONSTANT_MODIFIERS = GENERAL_MODIFIERS
|
42
|
+
|
43
|
+
METHOD_MODIFIERS = GENERAL_MODIFIERS +
|
44
|
+
%w[arg args yield yields notnew not-new not_new doc]
|
45
|
+
|
46
|
+
##
|
47
|
+
# Encapsulate the production of rdoc documentation. Basically
|
48
|
+
# you can use this as you would invoke rdoc from the command
|
49
|
+
# line:
|
50
|
+
#
|
51
|
+
# rdoc = RDocF95::RDoc.new
|
52
|
+
# rdoc.document(args)
|
53
|
+
#
|
54
|
+
# where _args_ is an array of strings, each corresponding to
|
55
|
+
# an argument you'd give rdoc on the command line. See rdoc/rdoc.rb
|
56
|
+
# for details.
|
57
|
+
|
58
|
+
class RDocF95
|
59
|
+
|
60
|
+
Generator = Struct.new(:file_name, :class_name, :key)
|
61
|
+
|
62
|
+
##
|
63
|
+
# This is the list of output generator that we support
|
64
|
+
|
65
|
+
GENERATORS = {}
|
66
|
+
|
67
|
+
$LOAD_PATH.collect do |d|
|
68
|
+
File.expand_path d
|
69
|
+
end.find_all do |d|
|
70
|
+
File.directory? "#{d}/rdoc-f95/generator"
|
71
|
+
end.each do |dir|
|
72
|
+
Dir.entries("#{dir}/rdoc-f95/generator").each do |gen|
|
73
|
+
next unless /(\w+)\.rb$/ =~ gen
|
74
|
+
type = $1
|
75
|
+
unless GENERATORS.has_key? type
|
76
|
+
GENERATORS[type] = Generator.new("rdoc-f95/generator/#{gen}",
|
77
|
+
"#{type.upcase}".intern,
|
78
|
+
type)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def initialize
|
84
|
+
@stats = Stats.new
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Report an error message and exit
|
89
|
+
|
90
|
+
def error(msg)
|
91
|
+
raise ::RDocF95::Error, msg
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Create an output dir if it doesn't exist. If it does exist, but doesn't
|
96
|
+
# contain the flag file <tt>created.rid</tt> then we refuse to use it, as
|
97
|
+
# we may clobber some manually generated documentation
|
98
|
+
|
99
|
+
def setup_output_dir(op_dir, force)
|
100
|
+
flag_file = output_flag_file(op_dir)
|
101
|
+
if File.exist?(op_dir)
|
102
|
+
unless File.directory?(op_dir)
|
103
|
+
error "'#{op_dir}' exists, and is not a directory"
|
104
|
+
end
|
105
|
+
begin
|
106
|
+
created = File.read(flag_file)
|
107
|
+
rescue SystemCallError
|
108
|
+
error "\nDirectory #{op_dir} already exists, but it looks like it\n" +
|
109
|
+
"isn't an RDoc directory. Because RDoc doesn't want to risk\n" +
|
110
|
+
"destroying any of your existing files, you'll need to\n" +
|
111
|
+
"specify a different output directory name (using the\n" +
|
112
|
+
"--op <dir> option).\n\n"
|
113
|
+
else
|
114
|
+
last = (Time.parse(created) unless force rescue nil)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
FileUtils.mkdir_p(op_dir)
|
118
|
+
end
|
119
|
+
last
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Update the flag file in an output directory.
|
124
|
+
|
125
|
+
def update_output_dir(op_dir, time)
|
126
|
+
File.open(output_flag_file(op_dir), "w") {|f| f.puts time.rfc2822 }
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Return the path name of the flag file in an output directory.
|
131
|
+
|
132
|
+
def output_flag_file(op_dir)
|
133
|
+
File.join(op_dir, "created.rid")
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# The .document file contains a list of file and directory name patterns,
|
138
|
+
# representing candidates for documentation. It may also contain comments
|
139
|
+
# (starting with '#')
|
140
|
+
|
141
|
+
def parse_dot_doc_file(in_dir, filename, options)
|
142
|
+
# read and strip comments
|
143
|
+
patterns = File.read(filename).gsub(/#.*/, '')
|
144
|
+
|
145
|
+
result = []
|
146
|
+
|
147
|
+
patterns.split.each do |patt|
|
148
|
+
candidates = Dir.glob(File.join(in_dir, patt))
|
149
|
+
result.concat(normalized_file_list(options, candidates))
|
150
|
+
end
|
151
|
+
result
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Given a list of files and directories, create a list of all the Ruby
|
156
|
+
# files they contain.
|
157
|
+
#
|
158
|
+
# If +force_doc+ is true we always add the given files, if false, only
|
159
|
+
# add files that we guarantee we can parse. It is true when looking at
|
160
|
+
# files given on the command line, false when recursing through
|
161
|
+
# subdirectories.
|
162
|
+
#
|
163
|
+
# The effect of this is that if you want a file with a non-standard
|
164
|
+
# extension parsed, you must name it explicity.
|
165
|
+
|
166
|
+
def normalized_file_list(options, relative_files, force_doc = false,
|
167
|
+
exclude_pattern = nil)
|
168
|
+
file_list = []
|
169
|
+
|
170
|
+
relative_files.each do |rel_file_name|
|
171
|
+
next if exclude_pattern && exclude_pattern =~ rel_file_name
|
172
|
+
stat = File.stat(rel_file_name)
|
173
|
+
case type = stat.ftype
|
174
|
+
when "file"
|
175
|
+
next if @last_created and stat.mtime < @last_created
|
176
|
+
file_list << rel_file_name.sub(/^\.\//, '') if force_doc || ParserFactory.can_parse(rel_file_name)
|
177
|
+
when "directory"
|
178
|
+
next if rel_file_name == "CVS" || rel_file_name == ".svn"
|
179
|
+
dot_doc = File.join(rel_file_name, DOT_DOC_FILENAME)
|
180
|
+
if File.file?(dot_doc)
|
181
|
+
file_list.concat(parse_dot_doc_file(rel_file_name, dot_doc, options))
|
182
|
+
else
|
183
|
+
file_list.concat(list_files_in_directory(rel_file_name, options))
|
184
|
+
end
|
185
|
+
else
|
186
|
+
raise RDocF95::Error, "I can't deal with a #{type} #{rel_file_name}"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
file_list
|
191
|
+
end
|
192
|
+
|
193
|
+
##
|
194
|
+
# Return a list of the files to be processed in a directory. We know that
|
195
|
+
# this directory doesn't have a .document file, so we're looking for real
|
196
|
+
# files. However we may well contain subdirectories which must be tested
|
197
|
+
# for .document files.
|
198
|
+
|
199
|
+
def list_files_in_directory(dir, options)
|
200
|
+
files = Dir.glob File.join(dir, "*")
|
201
|
+
|
202
|
+
normalized_file_list options, files, false, options.exclude
|
203
|
+
end
|
204
|
+
|
205
|
+
##
|
206
|
+
# Parse each file on the command line, recursively entering directories.
|
207
|
+
|
208
|
+
def parse_files(options)
|
209
|
+
files = options.files
|
210
|
+
files = ["."] if files.empty?
|
211
|
+
|
212
|
+
file_list = normalized_file_list(options, files, true)
|
213
|
+
|
214
|
+
return [] if file_list.empty?
|
215
|
+
|
216
|
+
file_info = []
|
217
|
+
width = file_list.map { |name| name.length }.max + 1
|
218
|
+
|
219
|
+
file_list.each do |fn|
|
220
|
+
$stderr.printf("\n%*s: ", width, fn) unless options.quiet
|
221
|
+
|
222
|
+
content = if RUBY_VERSION >= '1.9' then
|
223
|
+
File.open(fn, "r:ascii-8bit") { |f| f.read }
|
224
|
+
else
|
225
|
+
File.read fn
|
226
|
+
end
|
227
|
+
|
228
|
+
if /coding:\s*(\S+)/ =~ content[/\A(?:.*\n){0,2}/]
|
229
|
+
if enc = Encoding.find($1)
|
230
|
+
content.force_encoding(enc)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
top_level = TopLevel.new(fn)
|
235
|
+
parser = ParserFactory.parser_for(top_level, fn, content, options, @stats)
|
236
|
+
file_info << parser.scan
|
237
|
+
@stats.num_files += 1
|
238
|
+
end
|
239
|
+
|
240
|
+
file_info
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# Format up one or more files according to the given arguments.
|
245
|
+
#
|
246
|
+
# For simplicity, _argv_ is an array of strings, equivalent to the strings
|
247
|
+
# that would be passed on the command line. (This isn't a coincidence, as
|
248
|
+
# we _do_ pass in ARGV when running interactively). For a list of options,
|
249
|
+
# see rdoc/rdoc.rb. By default, output will be stored in a directory
|
250
|
+
# called +doc+ below the current directory, so make sure you're somewhere
|
251
|
+
# writable before invoking.
|
252
|
+
#
|
253
|
+
# Throws: RDocF95::Error on error
|
254
|
+
|
255
|
+
def document(argv)
|
256
|
+
TopLevel::reset
|
257
|
+
|
258
|
+
@options = Options.new GENERATORS
|
259
|
+
@options.parse argv
|
260
|
+
|
261
|
+
@last_created = nil
|
262
|
+
|
263
|
+
unless @options.all_one_file
|
264
|
+
@last_created = setup_output_dir(@options.op_dir, @options.force_update)
|
265
|
+
end
|
266
|
+
|
267
|
+
start_time = Time.now
|
268
|
+
|
269
|
+
file_info = parse_files @options
|
270
|
+
|
271
|
+
@options.title = "RDoc Documentation"
|
272
|
+
|
273
|
+
if file_info.empty?
|
274
|
+
$stderr.puts "\nNo newer files." unless @options.quiet
|
275
|
+
else
|
276
|
+
@gen = @options.generator
|
277
|
+
|
278
|
+
$stderr.puts "\nGenerating #{@gen.key.upcase}..." unless @options.quiet
|
279
|
+
|
280
|
+
require @gen.file_name
|
281
|
+
|
282
|
+
gen_class = ::RDocF95::Generator.const_get @gen.class_name
|
283
|
+
@gen = gen_class.for @options
|
284
|
+
|
285
|
+
pwd = Dir.pwd
|
286
|
+
|
287
|
+
Dir.chdir(@options.op_dir) unless @options.all_one_file
|
288
|
+
|
289
|
+
begin
|
290
|
+
Diagram.new(file_info, @options).draw if @options.diagram
|
291
|
+
@gen.generate(file_info)
|
292
|
+
update_output_dir(".", start_time)
|
293
|
+
ensure
|
294
|
+
Dir.chdir(pwd)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
unless @options.quiet
|
299
|
+
puts
|
300
|
+
@stats.print
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|