jeffreyhunter77-R2Doc 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGELOG +1 -0
  2. data/LICENSE +20 -0
  3. data/Manifest +50 -0
  4. data/R2Doc.gemspec +33 -0
  5. data/README +103 -0
  6. data/README.rdoc +103 -0
  7. data/Rakefile +9 -0
  8. data/bin/r2doc +157 -0
  9. data/lib/r2doc.rb +7 -0
  10. data/lib/r2doc/context_extensions.rb +237 -0
  11. data/lib/r2doc/erb_template_engine.rb +11 -0
  12. data/lib/r2doc/generator.rb +123 -0
  13. data/lib/r2doc/rdoc_v2_generator.rb +112 -0
  14. data/lib/r2doc/template.rb +95 -0
  15. data/lib/r2doc/template/r2doc/_aliases.html.erb +22 -0
  16. data/lib/r2doc/template/r2doc/_attributes.html.erb +24 -0
  17. data/lib/r2doc/template/r2doc/_classes_and_modules.html.erb +13 -0
  18. data/lib/r2doc/template/r2doc/_constants.html.erb +22 -0
  19. data/lib/r2doc/template/r2doc/_method_detail.html.erb +10 -0
  20. data/lib/r2doc/template/r2doc/_method_details.html.erb +17 -0
  21. data/lib/r2doc/template/r2doc/_method_listing.html.erb +37 -0
  22. data/lib/r2doc/template/r2doc/_method_listing_row.html.erb +4 -0
  23. data/lib/r2doc/template/r2doc/_nav.html.erb +40 -0
  24. data/lib/r2doc/template/r2doc/_nav_item.html.erb +1 -0
  25. data/lib/r2doc/template/r2doc/class.html.erb +71 -0
  26. data/lib/r2doc/template/r2doc/file.html.erb +52 -0
  27. data/lib/r2doc/template/r2doc/images/blue-arrow-right.png +0 -0
  28. data/lib/r2doc/template/r2doc/images/blue-arrow-up.png +0 -0
  29. data/lib/r2doc/template/r2doc/images/blue-box.png +0 -0
  30. data/lib/r2doc/template/r2doc/images/blue-plus.png +0 -0
  31. data/lib/r2doc/template/r2doc/images/close-button.png +0 -0
  32. data/lib/r2doc/template/r2doc/images/green-arrow-right.png +0 -0
  33. data/lib/r2doc/template/r2doc/images/green-arrow-up.png +0 -0
  34. data/lib/r2doc/template/r2doc/images/nav-back.png +0 -0
  35. data/lib/r2doc/template/r2doc/images/nav-bottom.png +0 -0
  36. data/lib/r2doc/template/r2doc/images/nav-top.png +0 -0
  37. data/lib/r2doc/template/r2doc/images/orange-hash.png +0 -0
  38. data/lib/r2doc/template/r2doc/images/red-dash.png +0 -0
  39. data/lib/r2doc/template/r2doc/images/search-back.png +0 -0
  40. data/lib/r2doc/template/r2doc/images/top-back.png +0 -0
  41. data/lib/r2doc/template/r2doc/images/top-left.png +0 -0
  42. data/lib/r2doc/template/r2doc/images/top-right.png +0 -0
  43. data/lib/r2doc/template/r2doc/index.html.erb +42 -0
  44. data/lib/r2doc/template/r2doc/jquery.js +19 -0
  45. data/lib/r2doc/template/r2doc/prototype.js +285 -0
  46. data/lib/r2doc/template/r2doc/r2doc.css +400 -0
  47. data/lib/r2doc/template/r2doc/rdoc-utils.js +510 -0
  48. data/lib/r2doc/template/r2doc/rdoc.js.erb +164 -0
  49. data/lib/r2doc/template_util.rb +82 -0
  50. data/lib/rdoc/discover.rb +4 -0
  51. data/lib/rdoc/generators/r2doc_generator.rb +105 -0
  52. metadata +155 -0
@@ -0,0 +1,95 @@
1
+ module R2Doc
2
+
3
+ # Thrown when a template file cannot be found
4
+ class TemplateMissingError < StandardError
5
+ # name of the missing template
6
+ attr_reader :template
7
+
8
+ def initialize(template)
9
+ super "Could not find template \"#{template}\""
10
+ @template = template
11
+ end
12
+ end
13
+
14
+ # The TemplateManager class handles loading and parsing of templates.
15
+ # The actual details of reading the file and creating a parsed template
16
+ # object is handled by a template engine class. TemplateManager's
17
+ # responsibilities are to record registration of template directories
18
+ # and engines, to locate the correct template source file, and then
19
+ # dispatch to the right engine.
20
+ #
21
+ # A template engine class need only supply a very limited interface.
22
+ # It must supply a class method named +load+ which accepts a file name
23
+ # as a single argument. The +load+ method is expected to return an
24
+ # instance representing that template. The returned instance must
25
+ # supply a +result+ method wich accepts a binding as its single
26
+ # argument. The +result+ method is expected to return the rendered
27
+ # template as a string. A single template instance may have its
28
+ # +result+ method invoked multiple times with different bindings.
29
+ class TemplateManager
30
+ # The collection of template engines by extension
31
+ @@template_engines = {}
32
+ # The list of template directories
33
+ @@template_directories = [File.join(File.expand_path(File.dirname(__FILE__)), 'template')]
34
+ # Cache for loaded templates
35
+ @@templates = {}
36
+
37
+ # Register a template engine for an extension
38
+ def self.register_engine(extension, klass)
39
+ @@template_engines[extension.to_sym] = klass
40
+ end
41
+
42
+ # Add a template directory to search
43
+ def self.add_template_directory(dir)
44
+ @@template_directories.push dir
45
+ end
46
+
47
+ # Return the list of template directories
48
+ def self.template_directories
49
+ @@template_directories
50
+ end
51
+
52
+ # Return the list of registered extensions
53
+ def self.registered_extensions
54
+ @@template_engines.keys
55
+ end
56
+
57
+ # Load a template and return its instance
58
+ def self.load_template(name)
59
+ return @@templates[name.to_sym] if @@templates.has_key?(name.to_sym)
60
+
61
+ # find the file
62
+ filename = self.find_template_file(name) or raise TemplateMissingError.new(name)
63
+ fileext = self.file_extension(filename)
64
+ @@templates[name.to_sym] = @@template_engines[fileext.to_sym].load(filename)
65
+ end
66
+
67
+ # Determine the extension for a filename (not including the leading dot)
68
+ def self.file_extension(name)
69
+ m = /\.([^.]+)$/.match(name)
70
+ m.nil? ? nil : m[1]
71
+ end
72
+
73
+ # Determine if a given extension is a registered extension
74
+ def self.is_registered_extension?(ext)
75
+ @@template_engines.has_key?(ext.nil? ? nil : ext.to_sym)
76
+ end
77
+
78
+ protected
79
+
80
+ # Determine the filename for a template
81
+ def self.find_template_file(name)
82
+ @@template_directories.each do |d|
83
+ @@template_engines.each_key do |ext|
84
+ ['html', 'js'].each do |type|
85
+ test = File.join(File.expand_path(d), "#{name.to_s}.#{type}.#{ext.to_s}")
86
+ return test if File.exists?(test)
87
+ end
88
+ end
89
+ end
90
+ nil
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -0,0 +1,22 @@
1
+ <h2><a name="aliases"></a>Aliases</h2>
2
+
3
+ <% if ctx.has_aliases? %>
4
+ <table class="members aliases">
5
+ <thead>
6
+ <tr>
7
+ <th class="namehead">Method</th>
8
+ <th>Alias</th>
9
+ <th>Description</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% ctx.aliases.each_with_index{|al,i| %>
14
+ <tr class="<%= stripe_class i %>">
15
+ <td class="name"><%=h al[:old_name] %></td>
16
+ <td class="new_name">&rarr; <%=h al[:new_name] %></td>
17
+ <td class="description"><%= al[:description] %></td>
18
+ </tr>
19
+ <% } %>
20
+ </tbody>
21
+ </table>
22
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <h2><a name="attributes"></a>Attributes</h2>
2
+
3
+ <% if ctx.has_attributes? %>
4
+ <table class="members attributes">
5
+ <thead>
6
+ <tr>
7
+ <th class="namehead">Name</th>
8
+ <th>Visibility</th>
9
+ <th>R/W</th>
10
+ <th>Description</th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <% ctx.attributes.each_with_index{|attribute,i| %>
15
+ <tr class="<%= stripe_class i %> <%=h attribute[:visibility].to_s %>">
16
+ <td class="name"><%=h attribute[:name] %></td>
17
+ <td class="visiblity"><%=h attribute[:visibility].to_s %></td>
18
+ <td class="rw"><%=h attribute[:rw] %></td>
19
+ <td class="description"><%= attribute[:description] %></td>
20
+ </tr>
21
+ <% } %>
22
+ </tbody>
23
+ </table>
24
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <h2><a name="classes_and_modules"></a>Classes &amp; Modules</h2>
2
+
3
+ <% if ctx.has_classes_or_modules? %>
4
+ <ul class="classlist">
5
+ <% ctx.modules.each {|m| %>
6
+ <li class="module"><%= link_to h(m.name), m %></li>
7
+ <% } %>
8
+ <% ctx.classes.each {|c| %>
9
+ <li class="class"><%= link_to h(c.name), c %></li>
10
+ <% } %>
11
+ </ul>
12
+ <% end %>
13
+
@@ -0,0 +1,22 @@
1
+ <h2><a name="constants"></a>Constants</h2>
2
+
3
+ <% if ctx.has_constants? %>
4
+ <table class="members constants">
5
+ <thead>
6
+ <tr>
7
+ <th class="namehead">Name</th>
8
+ <th>&nbsp;</th>
9
+ <th>Description</th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <% ctx.constants.each_with_index{|constant,i| %>
14
+ <tr class="<%= stripe_class i %>">
15
+ <td class="name"><%=h constant[:name] %></td>
16
+ <td class="value">= <%=h constant[:value] %></td>
17
+ <td class="description"><%= constant[:description] %></td>
18
+ </tr>
19
+ <% } %>
20
+ </tbody>
21
+ </table>
22
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <h4 class="method_detail"><a name="<%=h method[:anchor] %>"></a>
2
+ <% if method[:callseq] %>
3
+ <span class="name"><%= method[:callseq] %></span>
4
+ <% else %>
5
+ <span class="name"><%= h(method[:name]) %></span><span class="args"><%= method[:params] %></span>
6
+ <% end %>
7
+ </h4>
8
+ <div class="method_description">
9
+ <%= method[:description] %>
10
+ </div>
@@ -0,0 +1,17 @@
1
+ <a name="method_detail"></a>
2
+
3
+ <% if ctx.has_class_methods? %>
4
+ <h2 class="detail"><a name="class_method_detail"></a>Class Method Detail</h2>
5
+
6
+ <% ctx.class_methods.each{|method| %>
7
+ <%= render_partial :method_detail, {:method=>method} %>
8
+ <% } %>
9
+ <% end %>
10
+
11
+ <% if ctx.has_instance_methods? %>
12
+ <h2 class="detail"><a name="instance_method_detail"></a>Instance Method Detail</h2>
13
+
14
+ <% ctx.instance_methods.each{|method| %>
15
+ <%= render_partial :method_detail, {:method=>method} %>
16
+ <% } %>
17
+ <% end %>
@@ -0,0 +1,37 @@
1
+ <h2><a name="methods"></a>Methods</h2>
2
+
3
+ <% if ctx.has_class_methods? %>
4
+ <h3><a name="class_methods"></a>Class</h3>
5
+
6
+ <table class="members methods">
7
+ <thead>
8
+ <tr>
9
+ <th class="namehead">Visibility</th>
10
+ <th>Signature</th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <% ctx.class_methods.each_with_index{|method,i| %>
15
+ <%= render_partial :method_listing_row, {:method=>method, :i=>i} %>
16
+ <% } %>
17
+ </tbody>
18
+ </table>
19
+ <% end %>
20
+
21
+ <% if ctx.has_instance_methods? %>
22
+ <h3><a name="instance_methods"></a>Instance</h3>
23
+
24
+ <table class="members methods">
25
+ <thead>
26
+ <tr>
27
+ <th class="namehead">Visibility</th>
28
+ <th>Signature</th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <% ctx.instance_methods.each_with_index{|method,i| %>
33
+ <%= render_partial :method_listing_row, {:method=>method, :i=>i} %>
34
+ <% } %>
35
+ </tbody>
36
+ </table>
37
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <tr class="<%= stripe_class i %> <%=h method[:visibility].to_s %>">
2
+ <td class="visibility"><%=h method[:visibility].to_s %></td>
3
+ <td class="name"><%= link_to h(method[:name]), method[:url] %> <span class="params"><%= method[:params] %></span></td>
4
+ </tr>
@@ -0,0 +1,40 @@
1
+ <div id="nav">
2
+ <div class="search"><div class="searchback">
3
+ <form id="searchform">
4
+ <input type="text" id="search_criteria" name="q" accesskey="s" />
5
+ <input type="submit" class="invisible" name="go" value="search" />
6
+ <div class="autocompleteChoices" id="search_choices"></div>
7
+ </form>
8
+ </div></div>
9
+ <div id="searchresults"></div>
10
+ <div id="navcontents">
11
+ <% if ctx.name_path_to_parent.length > 0 %>
12
+ <ul>
13
+ <li><%= link_to h(@options.title), 'index.html', :title=>@options.title %></li>
14
+ <% ctx.name_path_to_parent.each{|mod| %>
15
+ <li>
16
+ <%= link_to h(mod.short_name), mod, :title=>mod.name %>
17
+ <% if ((mod == ctx.parent) && mod.has_classes_or_modules?) %>
18
+ <ul>
19
+ <% mod.modules.each {|child| %><%= render_partial(:nav_item, {:type=>'module', :ctx=>ctx, :child=>child}) %><% } %>
20
+ <% mod.classes.each {|child| %><%= render_partial(:nav_item, {:type=>'class', :ctx=>ctx, :child=>child}) %><% } %>
21
+ </ul>
22
+ <% end %>
23
+ </li>
24
+ <% } %>
25
+ </ul>
26
+ <% else %>
27
+ <ul>
28
+ <li><%= link_to h(@options.title), 'index.html', :title=>@options.title %>
29
+ <% if (@topclasses.length > 0 || @topmodules.length > 0) %>
30
+ <ul>
31
+ <% @topmodules.find_all{|m| m.document_self || m.has_classes_or_modules?}.each {|child| %><%= render_partial(:nav_item, {:type=>'module', :ctx=>ctx, :child=>child}) %><% } %>
32
+ <% @topclasses.find_all{|c| c.document_self}.each {|child| %><%= render_partial(:nav_item, {:type=>'class', :ctx=>ctx, :child=>child}) %><% } %>
33
+ </ul>
34
+ <% end %>
35
+ </li>
36
+ </ul>
37
+ <% end %>
38
+ </div>
39
+ <div class="endcap"></div>
40
+ </div>
@@ -0,0 +1 @@
1
+ <li class="<%= type %><%= (child == ctx) ? ' thispage' : '' %>"><%= (child == ctx) ? h(child.short_name) : link_to(h(child.short_name), child, :title=>child.name) %></li>
@@ -0,0 +1,71 @@
1
+ <?xml version="1.0" encoding="<%=h @options.charset %>"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <title><%=h "#{klass.name} - #{@options.title}"%></title>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=<%=h @options.charset %>" />
7
+ <link rel="stylesheet" href="<%=h path_to(@options.css.nil? ? 'r2doc.css' : @options.css)%>" type="text/css" />
8
+ <script type="text/javascript" src="<%= path_to 'jquery.js' %>"></script>
9
+ <script type="text/javascript" src="<%= path_to 'prototype.js' %>"></script>
10
+ <script type="text/javascript" src="<%= path_to 'rdoc-utils.js' %>"></script>
11
+ <script type="text/javascript" src="<%= path_to 'rdoc.js' %>"></script>
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+ rdoc.currentPath = "<%= @current_path %>";
15
+ // ]]>
16
+ </script>
17
+ </head>
18
+ <body>
19
+ <%= render_partial :nav, {:ctx=>klass} %>
20
+
21
+ <div id="rightside">
22
+ <div id="topbar">
23
+ <div class="topcap"><div class="endcap">
24
+ <div class="quicklinks">
25
+ <a href="#constants">constants</a> |
26
+ <a href="#attributes">attributes</a> |
27
+ <a href="#methods">methods</a>
28
+ </div>
29
+ <div class="type"><%= klass.context.is_module? ? 'Module' : 'Class' %></div>
30
+ <h1><%=h klass.name %></h1>
31
+ </div></div>
32
+ </div>
33
+
34
+ <div id="content">
35
+ <dl class="class_properties">
36
+ <dt>Inheritance</dt>
37
+ <dd><% p = klass.superclass; while p do %>
38
+ <% if p.respond_to?(:path) %>
39
+ &lt; <%= link_to h(p.name), p %> <% p = p.superclass %>
40
+ <% else %>
41
+ &lt; <%= h(p) %> <% p = nil %>
42
+ <% end %>
43
+ <% end %></dd>
44
+ <% if klass.has_includes? %>
45
+ <dt>Included Modules</dt>
46
+ <dd><%= klass.includes.collect{|m| m.has_key?(:url) ? link_to(h(m[:name]), m[:url]) : m[:name]}.join(', ') %></dd>
47
+ <% end %>
48
+ </dl>
49
+
50
+ <div class="description">
51
+ <%= klass.description %>
52
+ </div>
53
+
54
+ <%= render_partial(:classes_and_modules, {:ctx=>klass}) if klass.has_classes_or_modules? %>
55
+
56
+ <%= render_partial(:constants, {:ctx=>klass}) if klass.has_constants? %>
57
+
58
+ <%= render_partial(:attributes, {:ctx=>klass}) if klass.has_attributes? %>
59
+
60
+ <%= render_partial(:aliases, {:ctx=>klass})if klass.has_aliases? %>
61
+
62
+ <%= render_partial(:method_listing, {:ctx=>klass}) if (klass.has_class_methods? || klass.has_instance_methods?) %>
63
+
64
+ <%= render_partial(:method_details, {:ctx=>klass}) if (klass.has_class_methods? || klass.has_instance_methods?) %>
65
+
66
+ </div>
67
+ </div>
68
+
69
+ <!-- R2Doc template by Mission Critical Labs, Inc. - http://www.missioncriticallabs.com/ -->
70
+ </body>
71
+ </html>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="<%=h @options.charset %>"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <title><%=h "#{file.name} - #{@options.title}"%></title>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=<%=h @options.charset %>" />
7
+ <link rel="stylesheet" href="<%=h path_to(@options.css.nil? ? 'r2doc.css' : @options.css)%>" type="text/css" />
8
+ <script type="text/javascript" src="<%= path_to 'jquery.js' %>"></script>
9
+ <script type="text/javascript" src="<%= path_to 'prototype.js' %>"></script>
10
+ <script type="text/javascript" src="<%= path_to 'rdoc-utils.js' %>"></script>
11
+ <script type="text/javascript" src="<%= path_to 'rdoc.js' %>"></script>
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+ rdoc.currentPath = "<%= @current_path %>";
15
+ // ]]>
16
+ </script>
17
+ </head>
18
+ <body>
19
+ <%= render_partial :nav, {:ctx=>file} %>
20
+
21
+ <div id="rightside">
22
+ <div id="topbar">
23
+ <div class="topcap"><div class="endcap">
24
+ <div class="type">File</div>
25
+ <h1><%=h file.name %></h1>
26
+ </div></div>
27
+ </div>
28
+
29
+ <div id="content">
30
+
31
+ <div class="description">
32
+ <%= file.description %>
33
+ </div>
34
+
35
+ <%= render_partial(:classes_and_modules, {:ctx=>file}) if file.has_classes_or_modules? %>
36
+
37
+ <%= render_partial(:constants, {:ctx=>file}) if file.has_constants? %>
38
+
39
+ <%= render_partial(:attributes, {:ctx=>file}) if file.has_attributes? %>
40
+
41
+ <%= render_partial(:aliases, {:ctx=>file}) if file.has_aliases? %>
42
+
43
+ <%= render_partial(:method_listing, {:ctx=>file}) if (file.has_class_methods? || file.has_instance_methods?) %>
44
+
45
+ <%= render_partial(:method_details, {:ctx=>file}) if (file.has_class_methods? || file.has_instance_methods?) %>
46
+
47
+ </div>
48
+ </div>
49
+
50
+ <!-- R2Doc template by Mission Critical Labs, Inc. - http://www.missioncriticallabs.com/ -->
51
+ </body>
52
+ </html>