aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/api_documentation_guidelines.md
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-09-01 17:08:06 -0400
committerPrem Sichanugrist <s@sikac.hu>2012-09-17 15:54:22 -0400
commit7bc1ca351523949f6b4ce96018e95e61cbc7719e (patch)
tree81d5fddb0511b309fa21c6883c8336533eeda9e5 /guides/source/api_documentation_guidelines.md
parent0867fcdb5a0d6b38a6326914984ad9d02c52dd0e (diff)
downloadrails-7bc1ca351523949f6b4ce96018e95e61cbc7719e.tar.gz
rails-7bc1ca351523949f6b4ce96018e95e61cbc7719e.tar.bz2
rails-7bc1ca351523949f6b4ce96018e95e61cbc7719e.zip
Convert code blocks into GFM style
Diffstat (limited to 'guides/source/api_documentation_guidelines.md')
-rw-r--r--guides/source/api_documentation_guidelines.md48
1 files changed, 24 insertions, 24 deletions
diff --git a/guides/source/api_documentation_guidelines.md b/guides/source/api_documentation_guidelines.md
index 3de5b119ee..3e8b86e35d 100644
--- a/guides/source/api_documentation_guidelines.md
+++ b/guides/source/api_documentation_guidelines.md
@@ -16,12 +16,12 @@ Write in present tense: "Returns a hash that...", rather than "Returned a hash t
Start comments in upper case. Follow regular punctuation rules:
-<ruby>
+```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 idioms recommended 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.
@@ -45,38 +45,38 @@ Use two spaces to indent chunks of code--that is, for markup purposes, two space
Short docs do not need an explicit "Examples" label to introduce snippets; they just follow paragraphs:
-<ruby>
+```ruby
# Converts a collection of elements into a formatted string by calling
# <tt>to_s</tt> on all elements and joining them.
#
# Blog.all.to_formatted_s # => "First PostSecond PostThird Post"
-</ruby>
+```
On the other hand, big chunks of structured documentation may have a separate "Examples" section:
-<ruby>
+```ruby
# ==== Examples
#
# Person.exists?(5)
# Person.exists?('5')
# Person.exists?(:name => "David")
# Person.exists?(['name LIKE ?', "%#{query}%"])
-</ruby>
+```
The results of expressions follow them and are introduced by "# => ", vertically aligned:
-<ruby>
+```ruby
# For checking if a fixnum is even or odd.
#
# 1.even? # => false
# 1.odd? # => true
# 2.even? # => true
# 2.odd? # => false
-</ruby>
+```
If a line is too long, the comment may be placed on the next line:
-<ruby>
+```ruby
# label(:post, :title)
# # => <label for="post_title">Title</label>
#
@@ -85,25 +85,25 @@ If a line is too long, the comment may be placed on the next line:
#
# label(:post, :title, "A short title", :class => "title_label")
# # => <label for="post_title" class="title_label">A short title</label>
-</ruby>
+```
Avoid using any printing methods like +puts+ or +p+ for that purpose.
On the other hand, regular comments do not use an arrow:
-<ruby>
+```ruby
# polymorphic_url(record) # same as comment_url(record)
-</ruby>
+```
h3. Filenames
As a rule of thumb, use filenames relative to the application root:
-<plain>
+```
config/routes.rb # YES
routes.rb # NO
RAILS_ROOT/config/routes.rb # NO
-</plain>
+```
h3. Fonts
@@ -117,7 +117,7 @@ Use fixed-width fonts for:
* Method parameters.
* File names.
-<ruby>
+```ruby
class Array
# Calls <tt>to_param</tt> on all its elements and joins the result with
# slashes. This is used by <tt>url_for</tt> in Action Pack.
@@ -125,7 +125,7 @@ class Array
collect { |e| e.to_param }.join '/'
end
end
-</ruby>
+```
WARNING: Using a pair of +&#43;...&#43;+ for fixed-width font only works with *words*; that is: anything matching <tt>\A\w&#43;\z</tt>. For anything else use +&lt;tt&gt;...&lt;/tt&gt;+, notably symbols, setters, inline snippets, etc.
@@ -133,7 +133,7 @@ h4. Regular Font
When "true" and "false" are English words rather than Ruby keywords use a regular font:
-<ruby>
+```ruby
# Runs all the validations within the specified context. Returns true if no errors are found,
# false otherwise.
#
@@ -145,15 +145,15 @@ When "true" and "false" are English words rather than Ruby keywords use a regula
def valid?(context = nil)
...
end
-</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>
+```ruby
# * <tt>:allow_nil</tt> - Skip validation if attribute is <tt>nil</tt>.
-</ruby>
+```
The description starts in upper case and ends with a full stop—it's standard English.
@@ -161,7 +161,7 @@ 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 away from the template:
-<ruby>
+```ruby
for severity in Severity.constants
class_eval <<-EOT, __FILE__, __LINE__
def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
@@ -173,11 +173,11 @@ for severity in Severity.constants
end # end
EOT
end
-</ruby>
+```
If the resulting lines are too wide, say 200 columns or more, put the comment above the call:
-<ruby>
+```ruby
# def self.find_by_login_and_activated(*args)
# options = args.extract_options!
# ...
@@ -188,4 +188,4 @@ self.class_eval %{
...
end
}
-</ruby>
+```