rdoc-f95 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +79 -0
  3. data/PostInstall.txt +7 -0
  4. data/README.rdoc +147 -0
  5. data/Rakefile +28 -0
  6. data/bin/rdoc-f95 +70 -0
  7. data/lib/rdoc-f95.rb +306 -0
  8. data/lib/rdoc-f95/code_objects.rb +776 -0
  9. data/lib/rdoc-f95/diagram.rb +342 -0
  10. data/lib/rdoc-f95/dot.rb +249 -0
  11. data/lib/rdoc-f95/generator.rb +1088 -0
  12. data/lib/rdoc-f95/generator/chm.rb +113 -0
  13. data/lib/rdoc-f95/generator/chm/chm.rb +98 -0
  14. data/lib/rdoc-f95/generator/html.rb +370 -0
  15. data/lib/rdoc-f95/generator/html/hefss.rb +414 -0
  16. data/lib/rdoc-f95/generator/html/html.rb +708 -0
  17. data/lib/rdoc-f95/generator/html/kilmer.rb +418 -0
  18. data/lib/rdoc-f95/generator/html/one_page_html.rb +121 -0
  19. data/lib/rdoc-f95/generator/ri.rb +229 -0
  20. data/lib/rdoc-f95/generator/xhtml.rb +106 -0
  21. data/lib/rdoc-f95/generator/xhtml/ctop.xsl +1318 -0
  22. data/lib/rdoc-f95/generator/xhtml/mathml.xsl +42 -0
  23. data/lib/rdoc-f95/generator/xhtml/pmathml.xsl +612 -0
  24. data/lib/rdoc-f95/generator/xhtml/pmathmlcss.xsl +872 -0
  25. data/lib/rdoc-f95/generator/xhtml/xhtml.rb +732 -0
  26. data/lib/rdoc-f95/generator/xml.rb +120 -0
  27. data/lib/rdoc-f95/generator/xml/rdf.rb +113 -0
  28. data/lib/rdoc-f95/generator/xml/xml.rb +111 -0
  29. data/lib/rdoc-f95/install.rb +166 -0
  30. data/lib/rdoc-f95/markup.rb +506 -0
  31. data/lib/rdoc-f95/markup/formatter.rb +14 -0
  32. data/lib/rdoc-f95/markup/fragments.rb +337 -0
  33. data/lib/rdoc-f95/markup/inline.rb +361 -0
  34. data/lib/rdoc-f95/markup/install.rb +57 -0
  35. data/lib/rdoc-f95/markup/lines.rb +152 -0
  36. data/lib/rdoc-f95/markup/mathml_wrapper.rb +91 -0
  37. data/lib/rdoc-f95/markup/preprocess.rb +71 -0
  38. data/lib/rdoc-f95/markup/sample/rdoc2latex.rb +16 -0
  39. data/lib/rdoc-f95/markup/sample/sample.rb +42 -0
  40. data/lib/rdoc-f95/markup/to_flow.rb +185 -0
  41. data/lib/rdoc-f95/markup/to_html.rb +357 -0
  42. data/lib/rdoc-f95/markup/to_html_crossref.rb +123 -0
  43. data/lib/rdoc-f95/markup/to_latex.rb +328 -0
  44. data/lib/rdoc-f95/markup/to_test.rb +50 -0
  45. data/lib/rdoc-f95/markup/to_xhtml_texparser.rb +234 -0
  46. data/lib/rdoc-f95/options.rb +745 -0
  47. data/lib/rdoc-f95/parsers/parse_c.rb +775 -0
  48. data/lib/rdoc-f95/parsers/parse_f95.rb +2499 -0
  49. data/lib/rdoc-f95/parsers/parse_rb.rb +2587 -0
  50. data/lib/rdoc-f95/parsers/parse_simple.rb +39 -0
  51. data/lib/rdoc-f95/parsers/parserfactory.rb +99 -0
  52. data/lib/rdoc-f95/ri.rb +2 -0
  53. data/lib/rdoc-f95/ri/cache.rb +188 -0
  54. data/lib/rdoc-f95/ri/descriptions.rb +147 -0
  55. data/lib/rdoc-f95/ri/display.rb +244 -0
  56. data/lib/rdoc-f95/ri/driver.rb +435 -0
  57. data/lib/rdoc-f95/ri/formatter.rb +603 -0
  58. data/lib/rdoc-f95/ri/paths.rb +105 -0
  59. data/lib/rdoc-f95/ri/reader.rb +106 -0
  60. data/lib/rdoc-f95/ri/util.rb +81 -0
  61. data/lib/rdoc-f95/ri/writer.rb +64 -0
  62. data/lib/rdoc-f95/stats.rb +23 -0
  63. data/lib/rdoc-f95/template.rb +64 -0
  64. data/lib/rdoc-f95/tokenstream.rb +33 -0
  65. data/lib/rdoc-f95/usage.rb +210 -0
  66. data/script/console +10 -0
  67. data/script/destroy +14 -0
  68. data/script/generate +14 -0
  69. data/test/test_helper.rb +3 -0
  70. data/test/test_rdoc-f95.rb +11 -0
  71. metadata +156 -0
@@ -0,0 +1,105 @@
1
+ require 'rdoc-f95/ri'
2
+
3
+ ##
4
+ # Encapsulate all the strangeness to do with finding out where to find RDoc
5
+ # files
6
+ #
7
+ # We basically deal with three directories:
8
+ #
9
+ # 1. The 'system' documentation directory, which holds the documentation
10
+ # distributed with Ruby, and which is managed by the Ruby install process
11
+ # 2. The 'site' directory, which contains site-wide documentation added
12
+ # locally.
13
+ # 3. The 'user' documentation directory, stored under the user's own home
14
+ # directory.
15
+ #
16
+ # There's contention about all this, but for now:
17
+ #
18
+ # system:: $datadir/ri/<ver>/system/...
19
+ # site:: $datadir/ri/<ver>/site/...
20
+ # user:: ~/.rdoc
21
+
22
+ module RDocF95::RI::Paths
23
+
24
+ #:stopdoc:
25
+ require 'rbconfig'
26
+
27
+ DOC_DIR = "doc/rdoc"
28
+
29
+ version = Config::CONFIG['ruby_version']
30
+ # version = RbConfig::CONFIG['ruby_version'] # RbConfig is invalid in Ruby 1.8.2
31
+
32
+ base = File.join(Config::CONFIG['datadir'], "ri", version)
33
+ # base = File.join(RbConfig::CONFIG['datadir'], "ri", version) # RbConfig is invalid in Ruby 1.8.2
34
+
35
+ SYSDIR = File.join(base, "system")
36
+ SITEDIR = File.join(base, "site")
37
+ homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
38
+
39
+ if homedir then
40
+ HOMEDIR = File.join(homedir, ".rdoc")
41
+ else
42
+ HOMEDIR = nil
43
+ end
44
+
45
+ # This is the search path for 'ri'
46
+ PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)}
47
+
48
+ begin
49
+ require 'rubygems' unless defined?(Gem) and defined?(Gem::Enable) and
50
+ Gem::Enable
51
+
52
+ # HACK dup'd from Gem.latest_partials and friends
53
+ all_paths = []
54
+
55
+ all_paths = Gem.path.map do |dir|
56
+ Dir[File.join(dir, 'doc', '*', 'ri')]
57
+ end.flatten
58
+
59
+ ri_paths = {}
60
+
61
+ all_paths.each do |dir|
62
+ base = File.basename File.dirname(dir)
63
+ if base =~ /(.*)-((\d+\.)*\d+)/ then
64
+ name, version = $1, $2
65
+ ver = Gem::Version.new version
66
+ if ri_paths[name].nil? or ver > ri_paths[name][0] then
67
+ ri_paths[name] = [ver, dir]
68
+ end
69
+ end
70
+ end
71
+
72
+ GEMDIRS = ri_paths.map { |k,v| v.last }.sort
73
+ GEMDIRS.each { |dir| PATH << dir }
74
+ rescue LoadError
75
+ GEMDIRS = []
76
+ end
77
+
78
+ # Returns the selected documentation directories as an Array, or PATH if no
79
+ # overriding directories were given.
80
+
81
+ def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
82
+ path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
83
+ return path.select { |directory| File.directory? directory }
84
+ end
85
+
86
+ # Returns the selected documentation directories including nonexistent
87
+ # directories. Used to print out what paths were searched if no ri was
88
+ # found.
89
+
90
+ def self.raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
91
+ return PATH unless use_system or use_site or use_home or use_gems or
92
+ not extra_dirs.empty?
93
+
94
+ path = []
95
+ path << extra_dirs unless extra_dirs.empty?
96
+ path << SYSDIR if use_system
97
+ path << SITEDIR if use_site
98
+ path << HOMEDIR if use_home
99
+ path << GEMDIRS if use_gems
100
+
101
+ return path.flatten.compact
102
+ end
103
+
104
+ end
105
+
@@ -0,0 +1,106 @@
1
+ require 'rdoc-f95/ri'
2
+ require 'rdoc-f95/ri/descriptions'
3
+ require 'rdoc-f95/ri/writer'
4
+ require 'rdoc-f95/markup/to_flow'
5
+
6
+ class RDocF95::RI::Reader
7
+
8
+ def initialize(ri_cache)
9
+ @cache = ri_cache
10
+ end
11
+
12
+ def top_level_namespace
13
+ [ @cache.toplevel ]
14
+ end
15
+
16
+ def lookup_namespace_in(target, namespaces)
17
+ result = []
18
+ for n in namespaces
19
+ result.concat(n.contained_modules_matching(target))
20
+ end
21
+ result
22
+ end
23
+
24
+ def find_class_by_name(full_name)
25
+ names = full_name.split(/::/)
26
+ ns = @cache.toplevel
27
+ for name in names
28
+ ns = ns.contained_class_named(name)
29
+ return nil if ns.nil?
30
+ end
31
+ get_class(ns)
32
+ end
33
+
34
+ def find_methods(name, is_class_method, namespaces)
35
+ result = []
36
+ namespaces.each do |ns|
37
+ result.concat ns.methods_matching(name, is_class_method)
38
+ end
39
+ result
40
+ end
41
+
42
+ ##
43
+ # Return the MethodDescription for a given MethodEntry by deserializing the
44
+ # YAML
45
+
46
+ def get_method(method_entry)
47
+ path = method_entry.path_name
48
+ File.open(path) { |f| RI::Description.deserialize(f) }
49
+ end
50
+
51
+ ##
52
+ # Return a class description
53
+
54
+ def get_class(class_entry)
55
+ result = nil
56
+ for path in class_entry.path_names
57
+ path = RiWriter.class_desc_path(path, class_entry)
58
+ desc = File.open(path) {|f| RI::Description.deserialize(f) }
59
+ if result
60
+ result.merge_in(desc)
61
+ else
62
+ result = desc
63
+ end
64
+ end
65
+ result
66
+ end
67
+
68
+ ##
69
+ # Return the names of all classes and modules
70
+
71
+ def full_class_names
72
+ res = []
73
+ find_classes_in(res, @cache.toplevel)
74
+ end
75
+
76
+ ##
77
+ # Return a list of all classes, modules, and methods
78
+
79
+ def all_names
80
+ res = []
81
+ find_names_in(res, @cache.toplevel)
82
+ end
83
+
84
+ private
85
+
86
+ def find_classes_in(res, klass)
87
+ classes = klass.classes_and_modules
88
+ for c in classes
89
+ res << c.full_name
90
+ find_classes_in(res, c)
91
+ end
92
+ res
93
+ end
94
+
95
+ def find_names_in(res, klass)
96
+ classes = klass.classes_and_modules
97
+ for c in classes
98
+ res << c.full_name
99
+ res.concat c.all_method_names
100
+ find_names_in(res, c)
101
+ end
102
+ res
103
+ end
104
+
105
+ end
106
+
@@ -0,0 +1,81 @@
1
+ require 'rdoc-f95/ri'
2
+
3
+ class RDocF95::RI::Error < RuntimeError; end
4
+
5
+ ##
6
+ # Break argument into its constituent class or module names, an
7
+ # optional method type, and a method name
8
+
9
+ class RDocF95::RI::NameDescriptor
10
+
11
+ attr_reader :class_names
12
+ attr_reader :method_name
13
+
14
+ ##
15
+ # true and false have the obvious meaning. nil means we don't care
16
+
17
+ attr_reader :is_class_method
18
+
19
+ ##
20
+ # +arg+ may be
21
+ #
22
+ # 1. A class or module name (optionally qualified with other class or module
23
+ # names (Kernel, File::Stat etc)
24
+ # 2. A method name
25
+ # 3. A method name qualified by a optionally fully qualified class or module
26
+ # name
27
+ #
28
+ # We're fairly casual about delimiters: folks can say Kernel::puts,
29
+ # Kernel.puts, or Kernel\#puts for example. There's one exception: if you
30
+ # say IO::read, we look for a class method, but if you say IO.read, we look
31
+ # for an instance method
32
+
33
+ def initialize(arg)
34
+ @class_names = []
35
+ separator = nil
36
+
37
+ tokens = arg.split(/(\.|::|#)/)
38
+
39
+ # Skip leading '::', '#' or '.', but remember it might
40
+ # be a method name qualifier
41
+ separator = tokens.shift if tokens[0] =~ /^(\.|::|#)/
42
+
43
+ # Skip leading '::', but remember we potentially have an inst
44
+
45
+ # leading stuff must be class names
46
+
47
+ while tokens[0] =~ /^[A-Z]/
48
+ @class_names << tokens.shift
49
+ unless tokens.empty?
50
+ separator = tokens.shift
51
+ break unless separator == "::"
52
+ end
53
+ end
54
+
55
+ # Now must have a single token, the method name, or an empty array
56
+ unless tokens.empty?
57
+ @method_name = tokens.shift
58
+ # We may now have a trailing !, ?, or = to roll into
59
+ # the method name
60
+ if !tokens.empty? && tokens[0] =~ /^[!?=]$/
61
+ @method_name << tokens.shift
62
+ end
63
+
64
+ if @method_name =~ /::|\.|#/ or !tokens.empty?
65
+ raise RiError.new("Bad argument: #{arg}")
66
+ end
67
+ if separator && separator != '.'
68
+ @is_class_method = separator == "::"
69
+ end
70
+ end
71
+ end
72
+
73
+ # Return the full class name (with '::' between the components) or "" if
74
+ # there's no class name
75
+
76
+ def full_class_name
77
+ @class_names.join("::")
78
+ end
79
+
80
+ end
81
+
@@ -0,0 +1,64 @@
1
+ require 'fileutils'
2
+ require 'rdoc-f95/ri'
3
+
4
+ class RDocF95::RI::Writer
5
+
6
+ def self.class_desc_path(dir, class_desc)
7
+ File.join(dir, "cdesc-" + class_desc.name + ".yaml")
8
+ end
9
+
10
+ ##
11
+ # Convert a name from internal form (containing punctuation) to an external
12
+ # form (where punctuation is replaced by %xx)
13
+
14
+ def self.internal_to_external(name)
15
+ name.gsub(/\W/) { "%%%02x" % $&[0].ord }
16
+ end
17
+
18
+ ##
19
+ # And the reverse operation
20
+
21
+ def self.external_to_internal(name)
22
+ name.gsub(/%([0-9a-f]{2,2})/) { $1.to_i(16).chr }
23
+ end
24
+
25
+ def initialize(base_dir)
26
+ @base_dir = base_dir
27
+ end
28
+
29
+ def remove_class(class_desc)
30
+ FileUtils.rm_rf(path_to_dir(class_desc.full_name))
31
+ end
32
+
33
+ def add_class(class_desc)
34
+ dir = path_to_dir(class_desc.full_name)
35
+ FileUtils.mkdir_p(dir)
36
+ class_file_name = self.class.class_desc_path(dir, class_desc)
37
+ File.open(class_file_name, "w") do |f|
38
+ f.write(class_desc.serialize)
39
+ end
40
+ end
41
+
42
+ def add_method(class_desc, method_desc)
43
+ dir = path_to_dir(class_desc.full_name)
44
+ file_name = self.class.internal_to_external(method_desc.name)
45
+ meth_file_name = File.join(dir, file_name)
46
+ if method_desc.is_singleton
47
+ meth_file_name += "-c.yaml"
48
+ else
49
+ meth_file_name += "-i.yaml"
50
+ end
51
+
52
+ File.open(meth_file_name, "w") do |f|
53
+ f.write(method_desc.serialize)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def path_to_dir(class_name)
60
+ File.join(@base_dir, *class_name.split('::'))
61
+ end
62
+
63
+ end
64
+
@@ -0,0 +1,23 @@
1
+ ##
2
+ # Simple stats collector
3
+
4
+ class RDocF95::Stats
5
+
6
+ attr_accessor :num_files, :num_classes, :num_modules, :num_methods
7
+
8
+ def initialize
9
+ @num_files = @num_classes = @num_modules = @num_methods = 0
10
+ @start = Time.now
11
+ end
12
+
13
+ def print
14
+ puts "Files: #@num_files"
15
+ puts "Classes: #@num_classes"
16
+ puts "Modules: #@num_modules"
17
+ puts "Methods: #@num_methods"
18
+ puts "Elapsed: " + sprintf("%0.3fs", Time.now - @start)
19
+ end
20
+
21
+ end
22
+
23
+
@@ -0,0 +1,64 @@
1
+ require 'erb'
2
+
3
+ ##
4
+ # An ERB wrapper.
5
+ #
6
+ # This TemplatePage operates similarly to RDoc 1.x's TemplatePage, but uses
7
+ # ERB instead of a custom template language.
8
+ #
9
+ # Converting from a RDoc 1.x template to an RDoc 2.x template is fairly easy.
10
+ #
11
+ # * %blah% becomes <%= values["blah"] %>
12
+ # * !INCLUDE! becomes <%= template_include %>
13
+ # * HREF:aref:name becomes <%= href values["aref"], values["name"] %>
14
+ # * IF:blah becomes <% if values["blah"] then %>
15
+ # * IFNOT:blah becomes <% unless values["blah"] then %>
16
+ # * ENDIF:blah becomes <% end %>
17
+ # * START:blah becomes <% values["blah"].each do |blah| %>
18
+ # * END:blah becomes <% end %>
19
+ #
20
+ # To make nested loops easier to convert, start by converting START statements
21
+ # to:
22
+ #
23
+ # <% values["blah"].each do |blah| $stderr.puts blah.keys %>
24
+ #
25
+ # So you can see what is being used inside which loop.
26
+
27
+ module RDocF95
28
+ end
29
+ class RDocF95::TemplatePage
30
+
31
+ ##
32
+ # Create a new TemplatePage that will use +templates+.
33
+
34
+ def initialize(*templates)
35
+ @templates = templates
36
+ end
37
+
38
+ ##
39
+ # Returns "<a href=\"#{ref}\">#{name}</a>"
40
+
41
+ def href(ref, name)
42
+ if ref then
43
+ "<a href=\"#{ref}\">#{name}</a>"
44
+ else
45
+ name
46
+ end
47
+ end
48
+
49
+ ##
50
+ # Process the template using +values+, writing the result to +io+.
51
+
52
+ def write_html_on(io, values)
53
+ b = binding
54
+ template_include = ""
55
+
56
+ @templates.reverse_each do |template|
57
+ template_include = ERB.new(template).result b
58
+ end
59
+
60
+ io.write template_include
61
+ end
62
+
63
+ end
64
+