You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/source/api_documentation_guidelines.md
+21-26Lines changed: 21 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,28 +23,28 @@ in the rails root directory, run `bundle install` and execute:
23
23
$ bundle exec rake rdoc
24
24
```
25
25
26
-
Resulting HTML files can be found in the ./doc/rdoc directory.
26
+
Resulting HTML files can be found in the `./doc/rdoc` directory.
27
27
28
-
NOTE: Please consult the RDoc [Markup Reference][RDoc Markup] for help with the syntax.
28
+
NOTE: Please consult the [RDoc Markup Reference][] for help with the syntax.
29
29
30
30
Links
31
31
-----
32
32
33
-
Rails API documentation are not meant to be viewed on GitHub and therefore links should use the RDoc [`link`][RDoc Links] markup relative to the current API.
33
+
Rails API documentation are not meant to be viewed on GitHub and therefore links should use the [RDoc link markup][] markup relative to the current API.
34
34
35
35
This is due to differences between GitHub Markdown and the generated RDoc that is published at [api.rubyonrails.org](https://api.rubyonrails.org) and [edgeapi.rubyonrails.org](https://edgeapi.rubyonrails.org).
36
36
37
37
For example, we use `[link:classes/ActiveRecord/Base.html]` to create a link to the `ActiveRecord::Base` class generated by RDoc.
38
38
39
39
This is preferred over absolute URLs such as `[https://api.rubyonrails.org/classes/ActiveRecord/Base.html]`, which would take the reader outside their current documentation version (e.g. edgeapi.rubyonrails.org).
[RDoc link markup]: https://ruby.github.io/rdoc/RDoc/MarkupReference.html#class-RDoc::MarkupReference-label-Links
43
43
44
44
Wording
45
45
-------
46
46
47
-
Write simple, declarative sentences. Brevity is a plus: get to the point.
47
+
Write simple, declarative sentences. Brevity is a plus. Get to the point.
48
48
49
49
Write in present tense: "Returns a hash that...", rather than "Returned a hash that..." or "Will return a hash that...".
50
50
@@ -110,7 +110,7 @@ Example Code
110
110
111
111
Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas.
112
112
113
-
Use two spaces to indent chunks of code--that is, for markup purposes, two spaces with respect to the left margin. The examples themselves should use [Rails coding conventions](contributing_to_ruby_on_rails.html#follow-the-coding-conventions).
113
+
For proper rendering, indent code by two spaces from the left margin. The examples themselves should use [Rails coding conventions](contributing_to_ruby_on_rails.html#follow-the-coding-conventions).
114
114
115
115
Short docs do not need an explicit "Examples" label to introduce snippets; they just follow paragraphs:
116
116
@@ -177,7 +177,7 @@ For example,
177
177
178
178
### IRB
179
179
180
-
When documenting the behavior for IRB, Ruby's interactive REPL, always prefix commands with `irb>` and the output should be prefixed with `=>`.
180
+
When documenting the behavior for IRB, Ruby's interactive REPL, always prefix commands with `irb>`. The output should be prefixed with `=>`.
181
181
182
182
For example,
183
183
@@ -189,7 +189,7 @@ For example,
189
189
190
190
### Bash / Command-line
191
191
192
-
For command-line examples, always prefix the command with `$`, the output doesn't have to be prefixed with anything.
192
+
For command-line examples, always prefix the command with `$`. The output doesn't have to be prefixed with anything.
193
193
194
194
```ruby
195
195
# Run the following command:
@@ -200,11 +200,11 @@ For command-line examples, always prefix the command with `$`, the output doesn'
200
200
Booleans
201
201
--------
202
202
203
-
In predicates and flags prefer documenting boolean semantics over exact values.
203
+
For predicates and flags, prefer documenting boolean semantics over exact values.
204
204
205
205
When "true" or "false" are used as defined in Ruby use regular font. The
206
206
singletons `true` and `false` need fixed-width font. Please avoid terms like
207
-
"truthy", Ruby defines what is true and false in the language, and thus those
207
+
"truthy". Ruby defines what is true and false in the language, and thus those
208
208
words have a technical meaning and need no substitutes.
209
209
210
210
As a rule of thumb, do not document singletons unless absolutely necessary. That
@@ -231,7 +231,7 @@ An example with a predicate:
231
231
# +collection.size.zero?+. If the collection has not been loaded,
232
232
# it is equivalent to +!collection.exists?+. If the collection has
233
233
# not already been loaded and you are going to fetch the records
234
-
# anyway it is better to check +collection.length.zero?+.
234
+
# anyway, it is better to check +collection.length.zero?+.
235
235
defempty?
236
236
if loaded?
237
237
size.zero?
@@ -242,18 +242,13 @@ end
242
242
```
243
243
244
244
The API is careful not to commit to any particular value, the method has
245
-
predicate semantics, that's enough.
245
+
predicate semantics, which is sufficient.
246
246
247
247
File Names
248
248
----------
249
249
250
250
As a rule of thumb, use filenames relative to the application root:
251
-
252
-
```
253
-
config/routes.rb # YES
254
-
routes.rb # NO
255
-
RAILS_ROOT/config/routes.rb # NO
256
-
```
251
+
`config/routes.rb` instead of `routes.rb` or `RAILS_ROOT/config/routes.rb`.
257
252
258
253
Fonts
259
254
-----
@@ -262,12 +257,12 @@ Fonts
262
257
263
258
Use fixed-width fonts for:
264
259
265
-
* Constants, in particular class and module names.
266
-
* Method names.
267
-
* Literals like `nil`, `false`, `true`, `self`.
268
-
* Symbols.
269
-
* Method parameters.
270
-
* File names.
260
+
* Constants, in particular class and module names
261
+
* Method names
262
+
* Literals like `nil`, `false`, `true`, `self`
263
+
* Symbols
264
+
* Method parameters
265
+
* File names
271
266
272
267
```ruby
273
268
classArray
@@ -281,7 +276,7 @@ end
281
276
282
277
WARNING: Using `+...+` for fixed-width font only works with simple content like
0 commit comments