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 @@
1
+ v0.1 First working version.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jeffrey Hunter and Mission Critical Labs, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ bin/r2doc
2
+ CHANGELOG
3
+ lib/r2doc/context_extensions.rb
4
+ lib/r2doc/erb_template_engine.rb
5
+ lib/r2doc/generator.rb
6
+ lib/r2doc/rdoc_v2_generator.rb
7
+ lib/r2doc/template/r2doc/_aliases.html.erb
8
+ lib/r2doc/template/r2doc/_attributes.html.erb
9
+ lib/r2doc/template/r2doc/_classes_and_modules.html.erb
10
+ lib/r2doc/template/r2doc/_constants.html.erb
11
+ lib/r2doc/template/r2doc/_method_detail.html.erb
12
+ lib/r2doc/template/r2doc/_method_details.html.erb
13
+ lib/r2doc/template/r2doc/_method_listing.html.erb
14
+ lib/r2doc/template/r2doc/_method_listing_row.html.erb
15
+ lib/r2doc/template/r2doc/_nav.html.erb
16
+ lib/r2doc/template/r2doc/_nav_item.html.erb
17
+ lib/r2doc/template/r2doc/class.html.erb
18
+ lib/r2doc/template/r2doc/file.html.erb
19
+ lib/r2doc/template/r2doc/images/blue-arrow-right.png
20
+ lib/r2doc/template/r2doc/images/blue-arrow-up.png
21
+ lib/r2doc/template/r2doc/images/blue-box.png
22
+ lib/r2doc/template/r2doc/images/blue-plus.png
23
+ lib/r2doc/template/r2doc/images/close-button.png
24
+ lib/r2doc/template/r2doc/images/green-arrow-right.png
25
+ lib/r2doc/template/r2doc/images/green-arrow-up.png
26
+ lib/r2doc/template/r2doc/images/nav-back.png
27
+ lib/r2doc/template/r2doc/images/nav-bottom.png
28
+ lib/r2doc/template/r2doc/images/nav-top.png
29
+ lib/r2doc/template/r2doc/images/orange-hash.png
30
+ lib/r2doc/template/r2doc/images/red-dash.png
31
+ lib/r2doc/template/r2doc/images/search-back.png
32
+ lib/r2doc/template/r2doc/images/top-back.png
33
+ lib/r2doc/template/r2doc/images/top-left.png
34
+ lib/r2doc/template/r2doc/images/top-right.png
35
+ lib/r2doc/template/r2doc/index.html.erb
36
+ lib/r2doc/template/r2doc/jquery.js
37
+ lib/r2doc/template/r2doc/prototype.js
38
+ lib/r2doc/template/r2doc/r2doc.css
39
+ lib/r2doc/template/r2doc/rdoc-utils.js
40
+ lib/r2doc/template/r2doc/rdoc.js.erb
41
+ lib/r2doc/template.rb
42
+ lib/r2doc/template_util.rb
43
+ lib/r2doc.rb
44
+ lib/rdoc/discover.rb
45
+ lib/rdoc/generators/r2doc_generator.rb
46
+ LICENSE
47
+ Manifest
48
+ Rakefile
49
+ README
50
+ README.rdoc
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{R2Doc}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jeffrey Hunter and Mission Critical Labs, Inc."]
9
+ s.date = %q{2009-07-17}
10
+ s.default_executable = %q{r2doc}
11
+ s.description = %q{R2Doc is an improved generator for RDoc. It provides an improved output template for documentation (including search and frameless navigation), but also aims to be more extensible so that template authoring is an easier task with a wider set of options.}
12
+ s.email = %q{r2doc@missioncriticallabs.com}
13
+ s.executables = ["r2doc"]
14
+ s.extra_rdoc_files = ["bin/r2doc", "CHANGELOG", "lib/r2doc/context_extensions.rb", "lib/r2doc/erb_template_engine.rb", "lib/r2doc/generator.rb", "lib/r2doc/rdoc_v2_generator.rb", "lib/r2doc/template/r2doc/_aliases.html.erb", "lib/r2doc/template/r2doc/_attributes.html.erb", "lib/r2doc/template/r2doc/_classes_and_modules.html.erb", "lib/r2doc/template/r2doc/_constants.html.erb", "lib/r2doc/template/r2doc/_method_detail.html.erb", "lib/r2doc/template/r2doc/_method_details.html.erb", "lib/r2doc/template/r2doc/_method_listing.html.erb", "lib/r2doc/template/r2doc/_method_listing_row.html.erb", "lib/r2doc/template/r2doc/_nav.html.erb", "lib/r2doc/template/r2doc/_nav_item.html.erb", "lib/r2doc/template/r2doc/class.html.erb", "lib/r2doc/template/r2doc/file.html.erb", "lib/r2doc/template/r2doc/images/blue-arrow-right.png", "lib/r2doc/template/r2doc/images/blue-arrow-up.png", "lib/r2doc/template/r2doc/images/blue-box.png", "lib/r2doc/template/r2doc/images/blue-plus.png", "lib/r2doc/template/r2doc/images/close-button.png", "lib/r2doc/template/r2doc/images/green-arrow-right.png", "lib/r2doc/template/r2doc/images/green-arrow-up.png", "lib/r2doc/template/r2doc/images/nav-back.png", "lib/r2doc/template/r2doc/images/nav-bottom.png", "lib/r2doc/template/r2doc/images/nav-top.png", "lib/r2doc/template/r2doc/images/orange-hash.png", "lib/r2doc/template/r2doc/images/red-dash.png", "lib/r2doc/template/r2doc/images/search-back.png", "lib/r2doc/template/r2doc/images/top-back.png", "lib/r2doc/template/r2doc/images/top-left.png", "lib/r2doc/template/r2doc/images/top-right.png", "lib/r2doc/template/r2doc/index.html.erb", "lib/r2doc/template/r2doc/jquery.js", "lib/r2doc/template/r2doc/prototype.js", "lib/r2doc/template/r2doc/r2doc.css", "lib/r2doc/template/r2doc/rdoc-utils.js", "lib/r2doc/template/r2doc/rdoc.js.erb", "lib/r2doc/template.rb", "lib/r2doc/template_util.rb", "lib/r2doc.rb", "lib/rdoc/discover.rb", "lib/rdoc/generators/r2doc_generator.rb", "LICENSE", "README", "README.rdoc"]
15
+ s.files = ["bin/r2doc", "CHANGELOG", "lib/r2doc/context_extensions.rb", "lib/r2doc/erb_template_engine.rb", "lib/r2doc/generator.rb", "lib/r2doc/rdoc_v2_generator.rb", "lib/r2doc/template/r2doc/_aliases.html.erb", "lib/r2doc/template/r2doc/_attributes.html.erb", "lib/r2doc/template/r2doc/_classes_and_modules.html.erb", "lib/r2doc/template/r2doc/_constants.html.erb", "lib/r2doc/template/r2doc/_method_detail.html.erb", "lib/r2doc/template/r2doc/_method_details.html.erb", "lib/r2doc/template/r2doc/_method_listing.html.erb", "lib/r2doc/template/r2doc/_method_listing_row.html.erb", "lib/r2doc/template/r2doc/_nav.html.erb", "lib/r2doc/template/r2doc/_nav_item.html.erb", "lib/r2doc/template/r2doc/class.html.erb", "lib/r2doc/template/r2doc/file.html.erb", "lib/r2doc/template/r2doc/images/blue-arrow-right.png", "lib/r2doc/template/r2doc/images/blue-arrow-up.png", "lib/r2doc/template/r2doc/images/blue-box.png", "lib/r2doc/template/r2doc/images/blue-plus.png", "lib/r2doc/template/r2doc/images/close-button.png", "lib/r2doc/template/r2doc/images/green-arrow-right.png", "lib/r2doc/template/r2doc/images/green-arrow-up.png", "lib/r2doc/template/r2doc/images/nav-back.png", "lib/r2doc/template/r2doc/images/nav-bottom.png", "lib/r2doc/template/r2doc/images/nav-top.png", "lib/r2doc/template/r2doc/images/orange-hash.png", "lib/r2doc/template/r2doc/images/red-dash.png", "lib/r2doc/template/r2doc/images/search-back.png", "lib/r2doc/template/r2doc/images/top-back.png", "lib/r2doc/template/r2doc/images/top-left.png", "lib/r2doc/template/r2doc/images/top-right.png", "lib/r2doc/template/r2doc/index.html.erb", "lib/r2doc/template/r2doc/jquery.js", "lib/r2doc/template/r2doc/prototype.js", "lib/r2doc/template/r2doc/r2doc.css", "lib/r2doc/template/r2doc/rdoc-utils.js", "lib/r2doc/template/r2doc/rdoc.js.erb", "lib/r2doc/template.rb", "lib/r2doc/template_util.rb", "lib/r2doc.rb", "lib/rdoc/discover.rb", "lib/rdoc/generators/r2doc_generator.rb", "LICENSE", "Manifest", "Rakefile", "README", "README.rdoc", "R2Doc.gemspec"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://r2doc.org}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "R2Doc", "--main", "README"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{r2doc}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{An extensible RDoc generator using ERB}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ else
30
+ end
31
+ else
32
+ end
33
+ end
data/README ADDED
@@ -0,0 +1,103 @@
1
+ = R2Doc
2
+
3
+ R2Doc began as a desire to to create a format for Ruby and Rails
4
+ documentation that would be more useful than anything currently available
5
+ (or at least more useful to me). Specifically, I had a small set of goals:
6
+
7
+ * To get rid of the really awful frames
8
+ * To allow easy searching by class or method name
9
+ * To make it easier to scan the lists of methods and attributes
10
+ * To limit line length for easier viewing on wide browsers
11
+
12
+ As RDoc version 1.0.1 was already packaged as part of the Ruby core and
13
+ version 2 did not yet appear to be stable when I started, I began by
14
+ building a template for version 1. As soon as I scratched the surface of
15
+ RDoc, I became immediately dismayed by what I found. The template format
16
+ was arcane, and much of the presentation logic I hoped to change was
17
+ embedded in the generator code. R2Doc quickly evolved into more than just
18
+ another template. While still in its very early stages of development,
19
+ R2Doc is a generator that is more easily extended and is very much a second
20
+ set of thoughts on what a framework for documentation generators could and
21
+ _should_ be. It is my hope that, more than anything, R2Doc will be a
22
+ contribution to the dialog about the future directions of RDoc.
23
+
24
+ == Features
25
+
26
+ [RDoc version independent]
27
+ The R2Doc generator is not limited to a particular version of RDoc. It
28
+ has been tested to work with version 1.0.1 and 2.3.0. Additional
29
+ versions will be tested as development progresses.
30
+ [Support for multiple templates]
31
+ While others will hopefully find the default template useful, some people
32
+ will almost certainly have different preferences for the format. The
33
+ beauty of R2Doc is not in its template, but rather in the facilities it
34
+ provides for creating templates more easily.
35
+ [Pushes presentation logic into the template]
36
+ My biggest gripe with the current version of RDoc is that more attention
37
+ should be paid to what makes Rails so successful as a web development
38
+ framework. Part of what really works for Rails is that it makes it easy
39
+ to build an application using a straight-forward MVC pattern and
40
+ encourages a clean separation between each of the three components of that
41
+ architecture. RDoc is made up of parts which correspond to each of those
42
+ components as well. A generator is a controller; the context objects
43
+ representing the classes, modules, files, and methods found in the code are
44
+ models; and a template is a view. R2Doc extends the model classes with
45
+ methods that provide information about the code being documented without
46
+ directly generating HTML. This pushes presentation logic into the view,
47
+ making for cleaner code and more powerful templates.
48
+ [More powerful capabilities within the templates]
49
+ Another key to the success of Rails is the large collection of utility
50
+ methods which are specifically made available for use within views. They
51
+ make common coding tasks easier to accomplish. R2Doc adds a small
52
+ collection of utility methods specifically design to facilitate template
53
+ authoring.
54
+ [Extensible set of template formats]
55
+ R2Doc provides an ERB engine for templates by default, but it is not
56
+ limited to only ERB templates. Much like Rails, the file extension of a
57
+ template dictates which engine it is written for. Template engines can be
58
+ added to R2Doc and registered to work with additional extensions. So,
59
+ engines can easily be added to allow template creation in HAML, XML
60
+ builder, or nearly anything else you care for.
61
+
62
+ == Usage
63
+
64
+ R2Doc is a standard generator, and, as such, can be specified using the
65
+ <tt>-f</tt> or <tt>--fmt</tt> options with the <tt>rdoc</tt> command. Its
66
+ gem will be automatically discovered by version 2 of RDoc, but version 1 is
67
+ slightly trickier as it relies on the <tt>$:</tt> variable. To facilitate
68
+ use, R2Doc provides the <tt>r2doc</tt> command. It's usage is:
69
+
70
+ r2doc [options] [names...] # normal usage
71
+ r2doc [options] --gems gems... # generate docs for installed gems
72
+
73
+ The first usage sets options for using R2Doc as the generator and passes
74
+ everything else on to <tt>rdoc</tt>. The second usage is a specialized
75
+ form for generating docs for an installed gem using the R2Doc generator.
76
+ By default <tt>r2doc</tt> uses whatever version of RDoc is your default,
77
+ but it includes one additional option, <tt>--rdoc-version</tt>, which allows
78
+ you to specify the RDoc version when multiple gems are installed.
79
+
80
+ == Creating Templates
81
+
82
+ R2Doc searches a registered list of directories for templates. Additional
83
+ directories may be added by calling TemplateManager.add_template_directory
84
+ Templates are folders within registered directories. So, the default
85
+ directory registered by the gem is lib/r2doc/template (relative to the
86
+ directory where the gem is installed) and the default r2doc template is in the
87
+ folder named lib/r2doc/template/r2doc.
88
+
89
+ The generator requires template files for index.html, class.html,
90
+ file.html, and rdoc.js. All non-template files within the template folder
91
+ are copied to the output directory unchanged (this is useful for supporting
92
+ files such as images and stylesheets). The best reference for writing
93
+ templates are the included template files themselves. Utility methods
94
+ specific to templates can be found in the R2Doc::TemplateUtil module. It
95
+ may also be useful to look over the additions to the context objects, which
96
+ are found in the R2Doc::ContextExtensions, R2Doc::ClassExtensions, and
97
+ R2Doc::MethodExtensions modules.
98
+
99
+ == Creating New Template Engines
100
+
101
+ Requirements for template engines are explained in the
102
+ R2Doc::TemplateManager class. Additional engines can be added by calling
103
+ TemplateManager.register_engine.
@@ -0,0 +1,103 @@
1
+ = R2Doc
2
+
3
+ R2Doc began as a desire to to create a format for Ruby and Rails
4
+ documentation that would be more useful than anything currently available
5
+ (or at least more useful to me). Specifically, I had a small set of goals:
6
+
7
+ * To get rid of the really awful frames
8
+ * To allow easy searching by class or method name
9
+ * To make it easier to scan the lists of methods and attributes
10
+ * To limit line length for easier viewing on wide browsers
11
+
12
+ As RDoc version 1.0.1 was already packaged as part of the Ruby core and
13
+ version 2 did not yet appear to be stable when I started, I began by
14
+ building a template for version 1. As soon as I scratched the surface of
15
+ RDoc, I became immediately dismayed by what I found. The template format
16
+ was arcane, and much of the presentation logic I hoped to change was
17
+ embedded in the generator code. R2Doc quickly evolved into more than just
18
+ another template. While still in its very early stages of development,
19
+ R2Doc is a generator that is more easily extended and is very much a second
20
+ set of thoughts on what a framework for documentation generators could and
21
+ _should_ be. It is my hope that, more than anything, R2Doc will be a
22
+ contribution to the dialog about the future directions of RDoc.
23
+
24
+ == Features
25
+
26
+ [RDoc version independent]
27
+ The R2Doc generator is not limited to a particular version of RDoc. It
28
+ has been tested to work with version 1.0.1 and 2.3.0. Additional
29
+ versions will be tested as development progresses.
30
+ [Support for multiple templates]
31
+ While others will hopefully find the default template useful, some people
32
+ will almost certainly have different preferences for the format. The
33
+ beauty of R2Doc is not in its template, but rather in the facilities it
34
+ provides for creating templates more easily.
35
+ [Pushes presentation logic into the template]
36
+ My biggest gripe with the current version of RDoc is that more attention
37
+ should be paid to what makes Rails so successful as a web development
38
+ framework. Part of what really works for Rails is that it makes it easy
39
+ to build an application using a straight-forward MVC pattern and
40
+ encourages a clean separation between each of the three components of that
41
+ architecture. RDoc is made up of parts which correspond to each of those
42
+ components as well. A generator is a controller; the context objects
43
+ representing the classes, modules, files, and methods found in the code are
44
+ models; and a template is a view. R2Doc extends the model classes with
45
+ methods that provide information about the code being documented without
46
+ directly generating HTML. This pushes presentation logic into the view,
47
+ making for cleaner code and more powerful templates.
48
+ [More powerful capabilities within the templates]
49
+ Another key to the success of Rails is the large collection of utility
50
+ methods which are specifically made available for use within views. They
51
+ make common coding tasks easier to accomplish. R2Doc adds a small
52
+ collection of utility methods specifically design to facilitate template
53
+ authoring.
54
+ [Extensible set of template formats]
55
+ R2Doc provides an ERB engine for templates by default, but it is not
56
+ limited to only ERB templates. Much like Rails, the file extension of a
57
+ template dictates which engine it is written for. Template engines can be
58
+ added to R2Doc and registered to work with additional extensions. So,
59
+ engines can easily be added to allow template creation in HAML, XML
60
+ builder, or nearly anything else you care for.
61
+
62
+ == Usage
63
+
64
+ R2Doc is a standard generator, and, as such, can be specified using the
65
+ <tt>-f</tt> or <tt>--fmt</tt> options with the <tt>rdoc</tt> command. Its
66
+ gem will be automatically discovered by version 2 of RDoc, but version 1 is
67
+ slightly trickier as it relies on the <tt>$:</tt> variable. To facilitate
68
+ use, R2Doc provides the <tt>r2doc</tt> command. It's usage is:
69
+
70
+ r2doc [options] [names...] # normal usage
71
+ r2doc [options] --gems gems... # generate docs for installed gems
72
+
73
+ The first usage sets options for using R2Doc as the generator and passes
74
+ everything else on to <tt>rdoc</tt>. The second usage is a specialized
75
+ form for generating docs for an installed gem using the R2Doc generator.
76
+ By default <tt>r2doc</tt> uses whatever version of RDoc is your default,
77
+ but it includes one additional option, <tt>--rdoc-version</tt>, which allows
78
+ you to specify the RDoc version when multiple gems are installed.
79
+
80
+ == Creating Templates
81
+
82
+ R2Doc searches a registered list of directories for templates. Additional
83
+ directories may be added by calling TemplateManager.add_template_directory
84
+ Templates are folders within registered directories. So, the default
85
+ directory registered by the gem is lib/r2doc/template (relative to the
86
+ directory where the gem is installed) and the default r2doc template is in the
87
+ folder named lib/r2doc/template/r2doc.
88
+
89
+ The generator requires template files for index.html, class.html,
90
+ file.html, and rdoc.js. All non-template files within the template folder
91
+ are copied to the output directory unchanged (this is useful for supporting
92
+ files such as images and stylesheets). The best reference for writing
93
+ templates are the included template files themselves. Utility methods
94
+ specific to templates can be found in the R2Doc::TemplateUtil module. It
95
+ may also be useful to look over the additions to the context objects, which
96
+ are found in the R2Doc::ContextExtensions, R2Doc::ClassExtensions, and
97
+ R2Doc::MethodExtensions modules.
98
+
99
+ == Creating New Template Engines
100
+
101
+ Requirements for template engines are explained in the
102
+ R2Doc::TemplateManager class. Additional engines can be added by calling
103
+ TemplateManager.register_engine.
@@ -0,0 +1,9 @@
1
+ require 'echoe'
2
+
3
+ Echoe.new('R2Doc') do |p|
4
+ p.author = 'Jeffrey Hunter and Mission Critical Labs, Inc.'
5
+ p.summary = 'An extensible RDoc generator using ERB'
6
+ p.description = 'R2Doc is an improved generator for RDoc. It provides an improved output template for documentation (including search and frameless navigation), but also aims to be more extensible so that template authoring is an easier task with a wider set of options.'
7
+ p.url = 'http://r2doc.org'
8
+ p.email = 'r2doc@missioncriticallabs.com'
9
+ end
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # r2doc is a wrapper script for using the r2doc generator with rdoc.
4
+ #
5
+ # Usage:
6
+ #
7
+ # r2doc [options] [names...]
8
+ # r2doc [options] --gems gems...
9
+ #
10
+ # The second format generates documentation for the named gems. All
11
+ # other options are passed to rdoc. See the RDoc documenation for more
12
+ # information.
13
+ #
14
+
15
+ require 'rubygems'
16
+ require 'r2doc'
17
+
18
+ # Output a help message and continue
19
+ def help_message
20
+ $stderr.puts <<-EOM
21
+ Usage:
22
+
23
+ r2doc [options] [names...]
24
+ r2doc [options] --gems gems...
25
+
26
+ The first format calls rdoc normally with r2doc set as
27
+ the generator. The second format sets rdoc as the
28
+ generator and generates documentation for the named
29
+ gems. One additional option (see below) is specific to
30
+ r2doc. All other options are passed through to rdoc.
31
+ Help for rdoc follows.
32
+
33
+ r2doc-specifc options:
34
+
35
+ --rdoc-version version
36
+ Specifices the rdoc version to require.
37
+ The version string is passed to gem.
38
+
39
+ EOM
40
+ end
41
+
42
+ # Pre-processes arguments before padding to rdoc.
43
+ #
44
+ # This method attempts to be forward-compatible by following very generic
45
+ # rules for processing options. Theoretically it could handle the short
46
+ # format option (f) incorrectly, because without knowledge of the
47
+ # supported short options, if the f option follows a series of short
48
+ # options which do not accept arguments, it becomes ambiguous. For
49
+ # example, in the following contrived scenario you can only distinguish
50
+ # between the two uses correctly if you know that the o option accepts
51
+ # and argument and the a flag does not:
52
+ #
53
+ # r2doc -afchm # equivalent of -a -f chm
54
+ # r2doc -aofchm # equivalent of -a -o fchm
55
+ #
56
+ # The risk here seems pretty minimal, however, since something's probably
57
+ # amiss anyway if you're passing the format option to r2doc.
58
+ def process_r2doc_args(args, overrides)
59
+ processed = []
60
+ local_options = {}
61
+
62
+ # add the overrides first
63
+ overrides.each do |o|
64
+ processed.push "--#{o[0]}"
65
+ processed.push o[2]
66
+ end
67
+
68
+ while args.length > 0 do
69
+ thisOpt = args.shift
70
+ thisParam = nil
71
+ if thisOpt =~ /^-/
72
+ # -- signals the end of options
73
+ if thisOpt == '--'
74
+ processed.push thisOpt
75
+ processed.concat(args) if args.length > 0
76
+ return processed, local_options
77
+ end
78
+
79
+ # this is an option, see if we have an argument
80
+ if longMatch = /^--([^=]+)=(.*)/.match(thisOpt)
81
+ if longMatch[1] == 'rdoc-version'
82
+ local_options['rdoc-version'] = longMatch[2]
83
+ else
84
+ # don't pass overrides through
85
+ processed.push thisOpt unless overrides.find{|o| o[0] == longMatch[1]}
86
+ end
87
+ elsif longMatch = /^--(.*)/.match(thisOpt)
88
+ # special case for help, gems, and rdoc-version options
89
+ if longMatch[1] == 'help'
90
+ help_message
91
+ processed.push thisOpt
92
+ elsif longMatch[1] == 'gems'
93
+ local_options['gems'] = args
94
+ return processed, local_options
95
+ elsif longMatch[1] == 'rdoc-version'
96
+ local_options['rdoc-version'] = args.shift
97
+ else
98
+ # an argument could follow as the next item
99
+ thisParam = args.shift unless args.first =~ /^-/
100
+ unless overrides.find{|o| o[0] == longMatch[1]}
101
+ processed.push thisOpt
102
+ processed.push thisParam unless thisParam.nil?
103
+ end
104
+ end
105
+ else
106
+ # short option
107
+ flag = thisOpt.slice(1, thisOpt.length - 1)
108
+ if flag == 'h' || flag == '?'
109
+ help_message
110
+ processed.push thisOpt
111
+ else
112
+ thisParam = args.shift unless args.first =~ /^-/
113
+ unless overrides.find{|o| o[1] == flag}
114
+ processed.push thisOpt
115
+ processed.push thisParam unless thisParam.nil?
116
+ end
117
+ end
118
+ end
119
+ else
120
+ # not an option, so processing stops
121
+ processed.push thisOpt
122
+ processed.concat(args) if args.length > 0
123
+ return processed, local_options
124
+ end
125
+ end
126
+
127
+ return processed, local_options
128
+ end
129
+
130
+ begin
131
+ arguments, local_options = process_r2doc_args(ARGV, [['fmt', 'f', 'r2doc']])
132
+
133
+ gem 'rdoc', local_options['rdoc-version'] if local_options.has_key?('rdoc-version')
134
+ require 'rdoc/rdoc'
135
+
136
+ # for gems
137
+ if local_options.has_key?('gems') && local_options['gems'].length > 0
138
+ require 'rubygems/doc_manager'
139
+ Gem::DocManager.configured_args = arguments
140
+ specs = local_options['gems'].inject([]) do |s,name|
141
+ found = Gem::SourceIndex.from_installed_gems.find_name(name)
142
+ spec = found.sort_by {|g| g.version }.last
143
+ s << spec if spec
144
+ s
145
+ end
146
+ specs.each{|s| Gem::DocManager.new(s).generate_rdoc}
147
+
148
+ # default
149
+ else
150
+ r = RDoc::RDoc.new
151
+ r.document(arguments)
152
+ end
153
+
154
+ rescue StandardError => e
155
+ $stderr.puts e.message
156
+ exit(1)
157
+ end