This guide documents the Ruby on Rails API documentation guidelines.
endprologue.
h3. RDoc
The Rails API documentation is generated with RDoc 2.5. Please consult the "RDoc documentation":http://rdoc.rubyforge.org/RDoc.htmlFor for help with its markup.
h3. Wording
Write simple, declarative sentences. Brevity is a plus: get to the point.
Write in present tense: "Returns a hash that...", rather than "Returned a hash that..." or "Will return a hash that...".
Start comments in upper case, follow regular punctuation rules:
<ruby>
# Declares an attribute reader backed by an internally-named instance variable.
def attr_internal_reader(*attrs)
...
end
</ruby>
Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the recommended idioms in edge, reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.
Documentation has to be concise but comprehensive. Explore and document edge cases. What happens if a module is anonymous? What if a collection is empty? What if an argument is nil?
The proper names of Rails components have a space in between the words, like "Active Support". +ActiveRecord+ is a Ruby module, whereas Active Record is an ORM. Historically there has been lack of consistency regarding this, but we checked with David when docrails started. All Rails documentation consistently refer to Rails components by their proper name, and if in your next blog post or presentation you remember this tidbit and take it into account that'd be fenomenal :).
WARNING: Using a pair of ++...++ for fixed-width font only works with *words*; that is: anything matching <tt>\A\w+\z</tt>. For anything else use +<tt>...</tt>+, notably symbols, setters, inline snippets, etc:
h4. Regular Font
When "true" and "false" are English words rather than Ruby keywords use a regular font:
<ruby>
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
# to make it reloadable:
#
# Dependencies.load_once_paths.delete lib_path
</ruby>
h3. Description Lists
In lists of options, parameters, etc. use a hyphen between the item and its description (reads better than a colon because normally options are symbols):
<ruby>
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
</ruby>
The description starts in upper case and ends with a full stop—it's standard English.
h3. Dynamically Generated Methods
Methods created with +(module|class)_eval(STRING)+ have a comment by their side with an instance of the generated code. That comment is 2 spaces apart from the template:
<%=guide("Caching with Rails",'caching_with_rails.html',:ticket=>10)do%>
<p>Various caching techniques provided by Rails.</p>
<%end%>
<%=guide("Contributing to Rails",'contributing_to_rails.html')do%>
<p>Rails is not "somebody else's framework." This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p>
<%end%>
</dl>
<h3>Extending Rails</h3>
...
...
@@ -147,6 +143,18 @@ Ruby on Rails Guides
<%end%>
</dl>
<h3>Contributing to Rails</h3>
<dl>
<%=guide("Contributing to Rails",'contributing_to_rails.html')do%>
<p>Rails is not "somebody else's framework." This guide covers a variety of ways that you can get involved in the ongoing development of Rails.</p>