|
| 1 | +# RDoc - Ruby Documentation System |
| 2 | + |
| 3 | +- GitHub: [https://github.com/ruby/rdoc](https://github.com/ruby/rdoc) |
| 4 | +- Issues: [https://github.com/ruby/rdoc/issues](https://github.com/ruby/rdoc/issues) |
| 5 | + |
| 6 | +## Description |
| 7 | + |
| 8 | +RDoc produces HTML and command-line documentation for Ruby projects. RDoc includes the `rdoc` and `ri` tools for generating and displaying documentation from the command-line. |
| 9 | + |
| 10 | +## Generating Documentation |
| 11 | + |
| 12 | +Once installed, you can create documentation using the `rdoc` command |
| 13 | + |
| 14 | +```shell |
| 15 | +rdoc [options] [names...] |
| 16 | +``` |
| 17 | + |
| 18 | +For an up-to-date option summary, type |
| 19 | + |
| 20 | +```shell |
| 21 | +rdoc --help |
| 22 | +``` |
| 23 | + |
| 24 | +A typical use might be to generate documentation for a package of Ruby source (such as RDoc itself). |
| 25 | + |
| 26 | +```shell |
| 27 | +rdoc |
| 28 | +``` |
| 29 | + |
| 30 | +This command generates documentation for all the Ruby and C source files in and below the current directory. These will be stored in a documentation tree starting in the subdirectory `doc`. |
| 31 | + |
| 32 | +You can make this slightly more useful for your readers by having the index page contain the documentation for the primary file. In our case, we could type |
| 33 | + |
| 34 | +```shell |
| 35 | +rdoc --main README.md |
| 36 | +``` |
| 37 | + |
| 38 | +You'll find information on the various formatting tricks you can use in comment blocks in the documentation this generates. |
| 39 | + |
| 40 | +RDoc uses file extensions to determine how to process each file. File names ending `.rb` and `.rbw` are assumed to be Ruby source. Files ending `.c` are parsed as C files. All other files are assumed to contain just Markup-style markup (with or without leading `#` comment markers). If directory names are passed to RDoc, they are scanned recursively for C and Ruby source files only. |
| 41 | + |
| 42 | +To generate documentation using `rake` see [RDoc::Task](https://ruby.github.io/rdoc/RDoc/Task.html). |
| 43 | + |
| 44 | +To generate documentation programmatically: |
| 45 | + |
| 46 | +```rb |
| 47 | +require 'rdoc/rdoc' |
| 48 | + |
| 49 | +options = RDoc::Options.new |
| 50 | +options.files = ['a.rb', 'b.rb'] |
| 51 | +options.setup_generator 'darkfish' |
| 52 | +# see RDoc::Options |
| 53 | + |
| 54 | +rdoc = RDoc::RDoc.new |
| 55 | +rdoc.document options |
| 56 | +# see RDoc::RDoc |
| 57 | +``` |
| 58 | + |
| 59 | +You can specify the target files for document generation with `.document` file in the project root directory. `.document` file contains a list of file and directory names including comment lines starting with `#`. See [https://github.com/ruby/rdoc/blob/master/.document](https://github.com/ruby/rdoc/blob/master/.document) as an example. |
| 60 | + |
| 61 | +## Writing Documentation |
| 62 | + |
| 63 | +To write documentation for RDoc place a comment above the class, module, method, constant, or attribute you want documented: |
| 64 | + |
| 65 | +```rb |
| 66 | +## |
| 67 | +# This class represents an arbitrary shape by a series of points. |
| 68 | +class Shape |
| 69 | + ## |
| 70 | + # Creates a new shape described by a +polyline+. |
| 71 | + # |
| 72 | + # If the +polyline+ does not end at the same point it started at the |
| 73 | + # first pointed is copied and placed at the end of the line. |
| 74 | + # |
| 75 | + # An ArgumentError is raised if the line crosses itself, but shapes may |
| 76 | + # be concave. |
| 77 | + def initialize polyline |
| 78 | + # ... |
| 79 | + end |
| 80 | +end |
| 81 | +``` |
| 82 | + |
| 83 | +The default comment markup format is the RDoc::Markup format. TomDoc, Markdown and RD format comments are also supported. You can set the default comment format for your entire project by creating a `.rdoc_options` file. See RDoc::Options@Saved+Options for instructions on creating one. You can also set the comment format for a single file through the `:markup:` directive, but this is only recommended if you wish to switch markup formats. See RDoc::Markup@Other+directives. |
| 84 | + |
| 85 | +Comments can contain directives that tell RDoc information that it cannot otherwise discover through parsing. See RDoc::Markup@Directives to control what is or is not documented, to define method arguments or to break up methods in a class by topic. See RDoc::Parser::Ruby for directives used to teach RDoc about metaprogrammed methods. |
| 86 | + |
| 87 | +See RDoc::Parser::C for documenting C extensions with RDoc. |
| 88 | + |
| 89 | +To determine how well your project is documented run `rdoc -C lib` to get a documentation coverage report. `rdoc -C1 lib` includes parameter names in the documentation coverage report. |
| 90 | + |
| 91 | +## Theme Options |
| 92 | + |
| 93 | +There are a few community-maintained themes for RDoc: |
| 94 | + |
| 95 | +- [rorvswild-theme-rdoc](https://github.com/BaseSecrete/rorvswild-theme-rdoc) |
| 96 | +- [hanna](https://github.com/jeremyevans/hanna) (a fork maintained by [Jeremy Evans](https://github.com/jeremyevans)) |
| 97 | + |
| 98 | +Please follow the theme's README for usage instructions. |
| 99 | + |
| 100 | +## Bugs |
| 101 | + |
| 102 | +See CONTRIBUTING.rdoc for information on filing a bug report. It's OK to file a bug report for anything you're having a problem with. If you can't figure out how to make RDoc produce the output you like that is probably a documentation bug. |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +RDoc is Copyright (c) 2001-2003 Dave Thomas, The Pragmatic Programmers. Portions (c) 2007-2011 Eric Hodel. Portions copyright others, see individual files and LEGAL.rdoc for details. |
| 107 | + |
| 108 | +RDoc is free software, and may be redistributed under the terms specified in LICENSE.rdoc. |
| 109 | + |
| 110 | +## Warranty |
| 111 | + |
| 112 | +This software is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose. |
0 commit comments