yard 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
data/README.md CHANGED
@@ -8,8 +8,8 @@ YARD: Yay! A Ruby Documentation Tool
8
8
  **Contributors**: See Contributors section below
9
9
  **Copyright**: 2007-2011
10
10
  **License**: MIT License
11
- **Latest Version**: 0.6.7 (codename "No codename")
12
- **Release Date**: April 6th 2011
11
+ **Latest Version**: 0.7.0 (codename "Heroes")
12
+ **Release Date**: May 17th 2011
13
13
 
14
14
  Synopsis
15
15
  --------
@@ -139,7 +139,7 @@ YARD server, and so on. To view a list of available YARD commands, type:
139
139
  Plugins can also add commands to the `yard` executable to provide extra
140
140
  functionality.
141
141
 
142
- #### Generating Documentation
142
+ ### Generating Documentation
143
143
 
144
144
  <span class="note">The `yardoc` executable is a shortcut for `yard doc`.</span>
145
145
 
@@ -183,7 +183,7 @@ the switches separated by whitespace (newlines or space) to pass to yardoc
183
183
  whenever it is run. A full overview of the `.yardopts` file can be found in
184
184
  {YARD::CLI::Yardoc}.
185
185
 
186
- #### Queries
186
+ ### Queries
187
187
 
188
188
  The `yardoc` tool also supports a `--query` argument to only include objects
189
189
  that match a certain data or meta-data query. The query syntax is Ruby, though
@@ -254,14 +254,14 @@ RubyGems. To serve documentation for a project you are working on, simply run:
254
254
  And the project inside the current directory will be parsed (if the source has
255
255
  not yet been scanned by YARD) and served at [http://localhost:8808](http://localhost:8808).
256
256
 
257
- #### Live Reloading
257
+ ### Live Reloading
258
258
 
259
259
  If you want to serve documentation on a project while you document it so that
260
260
  you can preview the results, simply pass `--reload` (`-r`) to the above command
261
261
  and YARD will reload any changed files on each request. This will allow you to
262
262
  change any documentation in the source and refresh to see the new contents.
263
263
 
264
- #### Serving Gems
264
+ ### Serving Gems
265
265
 
266
266
  To serve documentation for all installed gems, call:
267
267
 
@@ -289,6 +289,16 @@ More options can be seen by typing `yard-graph --help`, but here is an example:
289
289
  Changelog
290
290
  ---------
291
291
 
292
+ - **May.17.11**: 0.7.0 release
293
+ - See the {docs/WhatsNew.md} document for details on added features
294
+ - Make sure that Docstring#line_range is filled when possible (#243)
295
+ - Set #verifier in YardocTask (#282)
296
+ - Parse BOM in UTF-8 files (#288)
297
+ - Fix instance attributes not showing up in method list (#302)
298
+ - Fix rendering of %w() literals in constants (#306)
299
+ - Ignore keyboard shortcuts when an input is active (#312)
300
+ - And more...
301
+
292
302
  - **April.14.11**: 0.6.8 release
293
303
  - Fix regression in RDoc 1.x markup loading
294
304
  - Fix regression in loading of markup libraries for `yard server`
data/docs/CodeObjects.md CHANGED
@@ -1,13 +1,13 @@
1
- CodeObjects Architecture
2
- ========================
1
+ # @title CodeObjects Architecture
2
+
3
+ # CodeObjects Architecture
3
4
 
4
5
  Code objects are Ruby objects that describe the code being documented. For instance,
5
6
  all classes, modules, methods, etc. are all extracted from the Ruby source as code
6
7
  objects. All of these code objects extend from the {YARD::CodeObjects::Base} class, which
7
8
  provides basic attributes like source location, source code, name and path.
8
9
 
9
- CodeObjects Organization
10
- ------------------------
10
+ ## CodeObjects Organization
11
11
 
12
12
  Code objects are divided into two basic types. {YARD::CodeObjects::NamespaceObject NamespaceObjects}
13
13
  and non-namespace objects. A namespace object refers to any object in Ruby that can have
@@ -23,8 +23,7 @@ The following is an overview of the classes within the `CodeObjects` namespace:
23
23
 
24
24
  ![CodeObjects Class Diagram](images/code-objects-class-diagram.png)
25
25
 
26
- Unique Path Representation
27
- --------------------------
26
+ ## Unique Path Representation
28
27
 
29
28
  All CodeObjects are uniquely defined by their implementation of {YARD::CodeObjects::Base#path}.
30
29
  This path is used to locate or store a code object in the {YARD::Registry}. It is therefore
@@ -41,8 +40,7 @@ would have the following respective paths:
41
40
  * Constant `VERSION` inside class `YARD`: `YARD::VERSION`
42
41
  * Class variable `@@abc` inside class `A`: `A::@@abc`
43
42
 
44
- Registry
45
- --------
43
+ ## Registry
46
44
 
47
45
  CodeObjects classes are coupled with the {YARD::Registry} class which keeps track of
48
46
  all instantiated code objects. This is an explicit design choice to allow objects
@@ -51,8 +49,7 @@ above, this coupling is a result of the fact that each object is uniquely identi
51
49
  its path, which is used to implement lookups. You can read more about the registry
52
50
  in the {YARD::Registry} class.
53
51
 
54
- Identity Map
55
- ------------
52
+ ## Identity Map
56
53
 
57
54
  Code objects are instantiated using an identity-map like implementation that guarantees
58
55
  only one unique Ruby object exists for an object described by a specific path. This
@@ -62,8 +59,7 @@ the {YARD::Registry}. The following example will only create one object:
62
59
  id = ClassObject.new(:root, "MyClass").object_id #=> 13352
63
60
  ClassObject.new(:root, "MyClass").object_id #=> 13352
64
61
 
65
- Proxy Objects
66
- -------------
62
+ ## Proxy Objects
67
63
 
68
64
  In addition to providing access to existing objects, a {YARD::CodeObjects::Proxy}
69
65
  class exists which can represent an object at a path that may or may not have been
@@ -80,8 +76,7 @@ for example:
80
76
  P(:InvalidObject).type == :proxy #=> true
81
77
  P(:InvalidObject).is_a?(Proxy) #=> true
82
78
 
83
- Adding Data to Code Objects
84
- ---------------------------
79
+ ## Adding Data to Code Objects
85
80
 
86
81
  Code objects act as hash-like structures that allow any arbitrary value to be set.
87
82
  This allows easy extending of existing objects without creating custom subclasses.
@@ -96,8 +91,7 @@ well as like any other method:
96
91
 
97
92
  object.modified_at #=> 2009-06-03 20:08:46 -0400
98
93
 
99
- Creating a Custom CodeObject
100
- ----------------------------
94
+ ## Creating a Custom CodeObject
101
95
 
102
96
  It should first be mentioned that creating a custom code object should not be
103
97
  necessary in most cases, except when functionality that cannot be represented
@@ -1,5 +1,6 @@
1
- Getting Started with YARD
2
- =========================
1
+ # @title Getting Started Guide
2
+
3
+ # Getting Started with YARD
3
4
 
4
5
  There are a few ways which YARD can be of use to you or your project. This
5
6
  document will cover the most common ways to use YARD:
@@ -12,8 +13,8 @@ document will cover the most common ways to use YARD:
12
13
  * [Plugin Support](#plugins)
13
14
 
14
15
  <a name="docing"></a>
15
- Documenting Code with YARD
16
- ==========================
16
+
17
+ ## Documenting Code with YARD
17
18
 
18
19
  By default, YARD is compatible with the same RDoc syntax most Ruby developers
19
20
  are already familiar with. However, one of the biggest advantages of YARD is
@@ -60,8 +61,7 @@ Using tags we can add semantic metadata to our code without worrying about
60
61
  presentation. YARD will handle presentation for us when we decide to generate
61
62
  documentation later.
62
63
 
63
- Which Markup Format?
64
- --------------------
64
+ ## Which Markup Format?
65
65
 
66
66
  YARD does not impose a specific markup. The above example uses standard RDoc
67
67
  markup formatting, but YARD also supports textile and markdown via the
@@ -71,8 +71,7 @@ using markdown. YARD, however, does add a few important syntaxes that are
71
71
  processed no matter which markup formatting you use, such as tag support
72
72
  and inter-document linking. These syntaxes are discussed below.
73
73
 
74
- Adding Tags to Documentation
75
- ----------------------------
74
+ ## Adding Tags to Documentation
76
75
 
77
76
  The tag syntax that YARD uses is the same @tag-style syntax you may have seen
78
77
  if you've ever coded in Java, Python, PHP, Objective-C or a myriad of other
@@ -149,8 +148,7 @@ and return tags:
149
148
  The above copies all of the param and return tags from `#get`. Note that you
150
149
  cannot copy individual tags of a specific type with this syntax.
151
150
 
152
- Declaring Types
153
- ---------------
151
+ ## Declaring Types
154
152
 
155
153
  Some tags also have an optional "types" field which let us declare a list of
156
154
  types associated with the tag. For instance, a return tag can be declared
@@ -186,15 +184,130 @@ and recommended conventions for writing type specifications, see
186
184
  {http://yardoc.org/types.html}. Note that these conventions may change every now
187
185
  and then, although we are working on a more "formal" type specification proposal.
188
186
 
189
- Inter-document Linking
190
- ----------------------
187
+ ## Documenting DSL Methods
188
+
189
+ Application code in Ruby often makes use of DSL style metaprogrammed methods.
190
+ The most common is the `attr_accessor` method, which of course has built-in
191
+ support in YARD. However, frameworks and libraries often expose custom
192
+ methods that perform similar metaprogramming tasks, and it is often useful
193
+ to document their functionality in your application. Consider the `property`
194
+ method in a project like {http://datamapper.org DataMapper}, which creates
195
+ a typed attribute for a database model. The code might look like:
196
+
197
+ class Post
198
+ include DataMapper::Resource
199
+
200
+ property :title, String
201
+ end
202
+
203
+ As of version 0.7.0, YARD will automatically pick up on these basic methods if
204
+ you document them with a docstring. Therefore, simply adding some comments to
205
+ the code will cause it to generate documentation:
206
+
207
+ class Post
208
+ include DataMapper::Resource
209
+
210
+ # @return [String] the title property of the post
211
+ property :title, String
212
+ end
213
+
214
+ Note that YARD uses the first argument in the method call to determine the
215
+ method name. In some cases, this would not be the method name, and you would
216
+ need to declare it manually. You can do so with the `@method` tag:
217
+
218
+ # @method foo
219
+ create_a_foo_method
220
+
221
+ The @method tag can also accept a full method signature with parameters:
222
+
223
+ # @method foo(name, opts = {})
224
+ create_a_foo_method
225
+
226
+ You can also set visibility and scope, or modify the method signature with
227
+ extra tags. The following adds documentation for a private class method:
228
+
229
+ # @method foo(opts = {})
230
+ # The foo method!
231
+ # @scope class
232
+ # @visibility private
233
+ create_a_private_foo_class_method
234
+
235
+ Finally, you can tag a method as an attribute by replacing the @method
236
+ tag with @attribute. The @attribute tag allows for the flags [r], [w], or
237
+ [rw] to declare a readonly, writeonly, or readwrite attribute, respectively.
238
+
239
+ # @attribute [w]
240
+ # The writeonly foo attribute!
241
+ a_writeonly_attribute :foo
242
+
243
+ (Note that if the name can be automatically detected, you do not need to
244
+ specify it in the @method or @attribute tag)
245
+
246
+ However, you will notice a few drawbacks with this basic support:
247
+
248
+ 1. There is a fair bit of duplication in such documentation. Specifically, we
249
+ repeat the term String and title twice in the property example.
250
+ 2. We must write a code comment for this property to show up in the documentation.
251
+ If we do not write a comment, it is ignored.
252
+
253
+ ### Macros
254
+
255
+ Fortunately YARD 0.7.0 also adds macros, a powerful way to add support for
256
+ these DSL methods on the fly without writing extra plugins. Macros allow
257
+ you to interpolate arguments from the method call inside the docstring,
258
+ reducing duplication. If we re-wrote the `property` example from above
259
+ using a macro, it might look like:
260
+
261
+ class Post
262
+ include DataMapper::Resource
263
+
264
+ # @macro dm.property
265
+ # @return [$2] the $1 $0 of the post
266
+ property :title, String
267
+ end
268
+
269
+ (Note that $0 represents the method call, in this case `property`. The rest
270
+ are arguments in the method call.)
271
+
272
+ The above example is equivalent to the first version shown in the previous
273
+ section. There is also some extra benefit to using this macro, in that we
274
+ can re-apply it to any other property in our class by simply calling on
275
+ the macro. The following:
276
+
277
+ # @macro dm.property
278
+ property :view_count, Integer
279
+
280
+ Would be equivalent to:
281
+
282
+ # @return [Integer] the view_count property of the post
283
+ property :view_count, Integer
284
+
285
+ Finally, macros can be "attached" to method calls, allowing them to be implicitly
286
+ activated every time the method call is seen in the source code of the class,
287
+ or an inheriting class. By simply adding the `[attach]` flag, the macro
288
+ becomes implicit on future calls. All of the properties below get documented
289
+ by using this snippet:
290
+
291
+ class Post
292
+ include DataMapper::Resource
293
+
294
+ # @macro [attach] dm.property
295
+ # @return [$2] the $1 $0 of the post
296
+ property :title, String
297
+ property :view_count, Integer
298
+ property :email, String
299
+ end
300
+
301
+ You can read more about macros in the {file:docs/Tags.md Tags Overview} document.
302
+
303
+ ## Customized YARD Markup
191
304
 
192
305
  YARD supports a special syntax to link to other code objects, URLs, files,
193
306
  or embed docstrings between documents. This syntax has the general form
194
307
  of `{Name OptionalTitle}` (where `OptionalTitle` can have spaces, but `Name`
195
308
  cannot).
196
309
 
197
- ### Linking Objects
310
+ ### Linking Objects `{...}`
198
311
 
199
312
  To link another "object" (class, method, module, etc.), use the format:
200
313
 
@@ -212,14 +325,14 @@ the link syntax in this tag:
212
325
  # @see #methodname <- Correct.
213
326
  # @see {#methodname} <- Incorrect.
214
327
 
215
- ### Linking URLs
328
+ ### Linking URLs `{http://...}`
216
329
 
217
330
  URLs are also linked using this `{...}` syntax:
218
331
 
219
332
  {http://example.com Optional Title}
220
333
  {mailto:email@example.com}
221
334
 
222
- ### Linking Files
335
+ ### Linking Files `{file:...}`
223
336
 
224
337
  Files can also be linked using this same syntax but by adding the `file:`
225
338
  prefix to the object name. Files refer to extra readme files you added
@@ -230,7 +343,7 @@ via the command-line. Consider the following examples:
230
343
 
231
344
  As shown, you can also add an optional `#anchor` if the page is an HTML link.
232
345
 
233
- ### Embedding Docstrings
346
+ ### Embedding Docstrings `{include:...}`
234
347
 
235
348
  We saw the `(see ...)` syntax above, which allowed us to link an entire docstring
236
349
  with another. Sometimes, however, we just want to copy docstring text without
@@ -248,14 +361,43 @@ The docstring for Bar becomes:
248
361
 
249
362
  "This is another class. This class is cool too!"
250
363
 
251
- Note that this prefix currently only works for objects.
364
+ ### Embedding Files `{include:file:...}`
365
+
366
+ You can embed the contents of files using `{include:file:path/to/file}`,
367
+ similar to the `{include:OBJECT}` tag above. If the file uses a specific markup
368
+ type, it will be applied and embedded as marked up text. The following
369
+ shows how the tag can be used inside of comments:
370
+
371
+ # Here is an example of a highlighted Ruby file:
372
+ #
373
+ # {include:file:examples/test.rb}
374
+
375
+ ### Rendering Objects `{render:...}`
376
+
377
+ Entire objects can also be rendered in place in documentation. This can be
378
+ used for guide-style documentation which does not document the entire source
379
+ tree, but instead selectively renders important classes or methods. Consider
380
+ the following documentation inside of a README file:
381
+
382
+ = igLatinPay!
383
+
384
+ This library adds pig latin methods to the string class, allowing you
385
+ to transform sentences into pig latin.
386
+
387
+ {render:String#pig_latin}
388
+
389
+ You can also un-pig-latin-ify a word or sentence:
390
+
391
+ {render:String#de_pig_latin}
392
+
393
+ The above would render the methods in place inside the README document,
394
+ allowing you to summarize a small library in a single file.
252
395
 
253
396
  <a name="using"></a>
254
- Using YARD to Generate Documentation
255
- ====================================
256
397
 
257
- `yard` Executable
258
- -----------------
398
+ ## Using YARD to Generate Documentation
399
+
400
+ ### `yard` Executable
259
401
 
260
402
  YARD ships with a single executable aptly named `yard`. In addition to
261
403
  generating standard documentation for your project, you would use this tool
@@ -287,8 +429,7 @@ full list):
287
429
  Note that `yardoc` is an alias for `yard doc`, and `yri` is an alias for
288
430
  `yard ri`. These commands are maintained for backwards compatibility.
289
431
 
290
- `.yardopts` Options File
291
- ------------------------
432
+ ### `.yardopts` Options File
292
433
 
293
434
  Unless your documentation is very small, you'll end up needing to run `yardoc`
294
435
  with many options. The `yardoc` tool will use the options found in this file.
@@ -313,9 +454,68 @@ Any extra switches passed to the command-line now will be appended to your
313
454
  Note that options for `yardoc` are discussed in the {file:README.md README},
314
455
  and a full overview of the `.yardopts` file can be found in {YARD::CLI::Yardoc}.
315
456
 
316
- <a name="docing"></a>
317
- Configuring YARD
318
- ================
457
+ ### Documenting Extra Files
458
+
459
+ "Extra files" are extra guide style documents that help to give a brief overview
460
+ of how to use your library/framework, as well as any extra information that
461
+ might be vital for your users. The most common "extra file" is the README,
462
+ which is automatically detected by YARD if found in the root of your project
463
+ (any file starting with `README*`). You can specify extra files on the command
464
+ line (or in the `.yardopts` file) by listing them after the '-' separator:
465
+
466
+ yardoc lib/**/*.rb ext/**/*.c - LICENSE.txt
467
+
468
+ Note that the README will automatically be picked up, so you do not need to
469
+ specify it. If you don't want to modify the default file globs, you can ignore
470
+ the first set of arguments:
471
+
472
+ yardoc - LICENSE.txt
473
+
474
+ Below you can read about how to customize the look of these extra files, both
475
+ with markup and pretty titles.
476
+
477
+ #### Adding Meta-Data to Extra Files
478
+
479
+ You can add YARD-style `@tag` metadata to the top of any extra file if prefixed
480
+ by a `#` hash comment. YARD allows for arbitrary meta-data, but pays special
481
+ attention to the tags `@markup`, `@encoding`, and `@title`. Note that there
482
+ cannot be any whitespace before the tags. Here is an example of some tag data
483
+ in a README:
484
+
485
+ # @markup markdown
486
+ # @title The Best Library in the World!
487
+ # @author The Author Name
488
+
489
+ This is the best library you will ever meet. Lipsum ...
490
+
491
+ The `@markup` tag allows you to specify a markup format to use for the file,
492
+ including "markdown", "textile", "rdoc", "ruby", "text", "html", or "none"
493
+ (no markup). This can be used when the markup cannot be auto-detected using
494
+ the extension of the filename, if the file has no extension, or if you want
495
+ to override the auto-detection.
496
+
497
+ By using `@encoding` you can specify a non-standard encoding. Note that
498
+ `yardoc --charset` sets the global encoding (for all comments / files),
499
+ so if you are using unicode across all your files, you can specify it there.
500
+ Using the `@encoding` tag might be used to override the default global
501
+ charset, say, if you had a localized `README.jp` file with SJIS data.
502
+ Also note that this only affects Ruby 1.9.x, as Ruby 1.8 is not properly
503
+ encoding aware.
504
+
505
+ The `@title` tag allows you to specify a full title name for the document.
506
+ By default, YARD uses the filename as the title of the document and lists
507
+ it in the file list in the index and file menu. In some cases, the file name
508
+ might not be descriptive enough, so YARD allows you to specify a full title:
509
+
510
+ contents of TITLE.txt:
511
+ # @title The Title of The Document
512
+
513
+ Currently all other meta-data is hidden from view, though accessible
514
+ programmatically using the {YARD::CodeObjects::ExtraFileObject} class.
515
+
516
+ <a name="config"></a>
517
+
518
+ ## Configuring YARD
319
519
 
320
520
  YARD (0.6.2+) supports a global configuration file stored in `~/.yard/config`.
321
521
  This file is stored as a YAML file and can contain arbitrary keys and values
@@ -336,8 +536,8 @@ using the `yard config` command. To list your configuration, use `yard config --
336
536
  To view a key, use `yard config ITEM`, and to set it, use `yard config ITEM VALUE`.
337
537
 
338
538
  <a name="extending"></a>
339
- Extending YARD
340
- ==============
539
+
540
+ ## Extending YARD
341
541
 
342
542
  There are many ways to extend YARD to support non-standard Ruby syntax (DSLs),
343
543
  add new meta-data tags or programmatically access the intermediate metadata
@@ -353,16 +553,16 @@ For information on accessing the data YARD stores about your documentation,
353
553
  look at the {file:docs/CodeObjects.md} architecture document.
354
554
 
355
555
  <a name="templating"></a>
356
- Templating YARD
357
- ===============
556
+
557
+ ## Templating YARD
358
558
 
359
559
  In many cases you may want to change the style of YARD's templates or add extra
360
560
  information after extending it. The {file:docs/Templates.md} architecture
361
561
  document covers the basics of how YARD's templating system works.
362
562
 
363
563
  <a name="plugins"></a>
364
- Plugin Support
365
- ==============
564
+
565
+ ## Plugin Support
366
566
 
367
567
  As of 0.4, YARD will automatically load any gem named with the prefix of
368
568
  `yard-` or `yard_`. You can use this to load a custom plugin that