yard 0.2.2 → 0.2.3

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 (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +200 -0
  3. data/Rakefile +6 -1
  4. data/benchmarks/format_args.rb +46 -0
  5. data/benchmarks/parsing.rb +13 -1
  6. data/benchmarks/rdoc_vs_yardoc.rb +10 -0
  7. data/benchmarks/ripper_parser.rb +12 -0
  8. data/docs/CODE_OBJECTS.markdown +121 -0
  9. data/docs/FAQ.markdown +34 -0
  10. data/docs/GENERATORS.markdown +211 -0
  11. data/docs/GETTING_STARTED.markdown +263 -0
  12. data/docs/GLOSSARY.markdown +13 -0
  13. data/docs/HANDLERS.markdown +158 -0
  14. data/docs/OVERVIEW.markdown +64 -0
  15. data/docs/PARSER.markdown +180 -0
  16. data/docs/TAGS.markdown +181 -0
  17. data/docs/WHATSNEW.markdown +96 -0
  18. data/docs/images/code-objects-class-diagram.png +0 -0
  19. data/docs/images/handlers-class-diagram.png +0 -0
  20. data/docs/images/overview-class-diagram.png +0 -0
  21. data/docs/images/parser-class-diagram.png +0 -0
  22. data/docs/images/tags-class-diagram.png +0 -0
  23. data/lib/yard.rb +4 -1
  24. data/lib/yard/autoload.rb +79 -31
  25. data/lib/yard/cli/yard_graph.rb +8 -2
  26. data/lib/yard/cli/yardoc.rb +61 -8
  27. data/lib/yard/code_objects/base.rb +78 -135
  28. data/lib/yard/code_objects/class_object.rb +9 -8
  29. data/lib/yard/code_objects/constant_object.rb +1 -0
  30. data/lib/yard/code_objects/extended_method_object.rb +9 -0
  31. data/lib/yard/code_objects/method_object.rb +18 -5
  32. data/lib/yard/code_objects/module_object.rb +8 -1
  33. data/lib/yard/code_objects/namespace_object.rb +25 -16
  34. data/lib/yard/code_objects/proxy.rb +22 -22
  35. data/lib/yard/core_ext/file.rb +1 -1
  36. data/lib/yard/core_ext/string.rb +0 -4
  37. data/lib/yard/core_ext/symbol_hash.rb +3 -2
  38. data/lib/yard/docstring.rb +180 -0
  39. data/lib/yard/generators/base.rb +33 -13
  40. data/lib/yard/generators/class_generator.rb +4 -2
  41. data/lib/yard/generators/constants_generator.rb +3 -2
  42. data/lib/yard/generators/full_doc_generator.rb +76 -9
  43. data/lib/yard/generators/helpers/base_helper.rb +18 -1
  44. data/lib/yard/generators/helpers/filter_helper.rb +2 -2
  45. data/lib/yard/generators/helpers/html_helper.rb +94 -39
  46. data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
  47. data/lib/yard/generators/helpers/markup_helper.rb +86 -0
  48. data/lib/yard/generators/helpers/method_helper.rb +23 -7
  49. data/lib/yard/generators/method_generator.rb +15 -3
  50. data/lib/yard/generators/method_listing_generator.rb +3 -3
  51. data/lib/yard/generators/mixins_generator.rb +8 -2
  52. data/lib/yard/generators/module_generator.rb +3 -2
  53. data/lib/yard/generators/overloads_generator.rb +20 -0
  54. data/lib/yard/generators/quick_doc_generator.rb +3 -9
  55. data/lib/yard/generators/root_generator.rb +32 -0
  56. data/lib/yard/generators/source_generator.rb +2 -17
  57. data/lib/yard/generators/tags_generator.rb +34 -6
  58. data/lib/yard/generators/uml_generator.rb +16 -6
  59. data/lib/yard/handlers/base.rb +88 -253
  60. data/lib/yard/handlers/processor.rb +72 -0
  61. data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
  62. data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
  63. data/lib/yard/handlers/ruby/base.rb +72 -0
  64. data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
  65. data/lib/yard/handlers/ruby/class_handler.rb +74 -0
  66. data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
  67. data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
  68. data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
  69. data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
  70. data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
  71. data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
  72. data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
  73. data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
  74. data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
  75. data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
  76. data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
  77. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
  78. data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
  79. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
  80. data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
  81. data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
  82. data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
  83. data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
  84. data/lib/yard/handlers/ruby/method_handler.rb +48 -0
  85. data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
  86. data/lib/yard/handlers/ruby/module_handler.rb +9 -0
  87. data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
  88. data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
  89. data/lib/yard/parser/ruby/ast_node.rb +263 -0
  90. data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
  91. data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
  92. data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
  93. data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
  94. data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
  95. data/lib/yard/parser/source_parser.rb +76 -45
  96. data/lib/yard/rake/yardoc_task.rb +6 -1
  97. data/lib/yard/registry.rb +45 -19
  98. data/lib/yard/serializers/file_system_serializer.rb +8 -3
  99. data/lib/yard/tags/default_factory.rb +70 -10
  100. data/lib/yard/tags/default_tag.rb +12 -0
  101. data/lib/yard/tags/library.rb +65 -26
  102. data/lib/yard/tags/option_tag.rb +12 -0
  103. data/lib/yard/tags/overload_tag.rb +62 -0
  104. data/lib/yard/tags/ref_tag.rb +7 -0
  105. data/lib/yard/tags/ref_tag_list.rb +27 -0
  106. data/lib/yard/tags/tag.rb +1 -0
  107. data/lib/yard/tags/tag_format_error.rb +6 -0
  108. data/spec/cli/yardoc_spec.rb +43 -0
  109. data/spec/code_objects/base_spec.rb +56 -68
  110. data/spec/code_objects/class_object_spec.rb +18 -6
  111. data/spec/code_objects/constants_spec.rb +2 -0
  112. data/spec/code_objects/method_object_spec.rb +33 -5
  113. data/spec/code_objects/module_object_spec.rb +66 -8
  114. data/spec/code_objects/namespace_object_spec.rb +37 -17
  115. data/spec/code_objects/proxy_spec.rb +13 -2
  116. data/spec/core_ext/string_spec.rb +14 -2
  117. data/spec/core_ext/symbol_hash_spec.rb +9 -3
  118. data/spec/docstring_spec.rb +139 -0
  119. data/spec/generators/full_doc_generator_spec.rb +29 -0
  120. data/spec/generators/helpers/html_helper_spec.rb +74 -0
  121. data/spec/generators/helpers/markup_helper_spec.rb +95 -0
  122. data/spec/handlers/alias_handler_spec.rb +16 -3
  123. data/spec/handlers/attribute_handler_spec.rb +1 -1
  124. data/spec/handlers/base_spec.rb +15 -141
  125. data/spec/handlers/class_condition_handler_spec.rb +49 -0
  126. data/spec/handlers/class_handler_spec.rb +44 -3
  127. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  128. data/spec/handlers/constant_handler_spec.rb +1 -1
  129. data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
  130. data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
  131. data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
  132. data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
  133. data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
  134. data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
  135. data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
  136. data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
  137. data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
  138. data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
  139. data/spec/handlers/exception_handler_spec.rb +2 -2
  140. data/spec/handlers/extend_handler_spec.rb +15 -0
  141. data/spec/handlers/legacy_base_spec.rb +128 -0
  142. data/spec/handlers/method_condition_handler_spec.rb +14 -0
  143. data/spec/handlers/method_handler_spec.rb +38 -5
  144. data/spec/handlers/mixin_handler_spec.rb +15 -7
  145. data/spec/handlers/module_handler_spec.rb +5 -1
  146. data/spec/handlers/processor_spec.rb +19 -0
  147. data/spec/handlers/ruby/base_spec.rb +90 -0
  148. data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
  149. data/spec/handlers/spec_helper.rb +22 -16
  150. data/spec/handlers/visibility_handler_spec.rb +4 -4
  151. data/spec/handlers/yield_handler_spec.rb +1 -1
  152. data/spec/parser/ruby/ast_node_spec.rb +15 -0
  153. data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
  154. data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
  155. data/spec/parser/source_parser_spec.rb +0 -15
  156. data/spec/rake/yardoc_task_spec.rb +48 -0
  157. data/spec/registry_spec.rb +28 -2
  158. data/spec/serializers/file_system_serializer_spec.rb +7 -1
  159. data/spec/spec_helper.rb +1 -1
  160. data/spec/tags/default_factory_spec.rb +135 -0
  161. data/spec/tags/default_tag_spec.rb +11 -0
  162. data/spec/tags/overload_tag_spec.rb +35 -0
  163. data/spec/tags/ref_tag_list_spec.rb +53 -0
  164. data/templates/default/attributes/html/header.erb +17 -5
  165. data/templates/default/attributes/text/header.erb +1 -1
  166. data/templates/default/fulldoc/html/all_files.erb +19 -0
  167. data/templates/default/fulldoc/html/all_methods.erb +8 -7
  168. data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
  169. data/templates/default/fulldoc/html/app.js +1 -1
  170. data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
  171. data/templates/default/fulldoc/html/header.erb +1 -1
  172. data/templates/default/fulldoc/html/index.erb +4 -3
  173. data/templates/default/fulldoc/html/style.css +13 -3
  174. data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
  175. data/templates/default/method/text/header.erb +1 -0
  176. data/templates/default/method/text/title.erb +1 -0
  177. data/templates/default/methodsignature/html/main.erb +10 -8
  178. data/templates/default/methodsignature/text/main.erb +4 -1
  179. data/templates/default/methodsummary/html/summary.erb +8 -4
  180. data/templates/default/methodsummary/text/summary.erb +4 -1
  181. data/templates/default/mixins/html/header.erb +3 -3
  182. data/templates/default/overloads/html/header.erb +8 -0
  183. data/templates/default/overloads/text/header.erb +8 -0
  184. data/templates/default/root/html/header.erb +4 -0
  185. data/templates/default/tags/html/example.erb +20 -0
  186. data/templates/default/tags/html/option.erb +27 -0
  187. data/templates/default/tags/html/param.erb +21 -0
  188. data/templates/default/tags/html/tags.erb +4 -1
  189. data/templates/default/tags/html/todo.erb +8 -0
  190. data/templates/default/tags/text/example.erb +14 -0
  191. data/templates/default/tags/text/header.erb +3 -3
  192. data/templates/default/tags/text/option.erb +5 -0
  193. data/templates/default/tags/text/param.erb +9 -0
  194. data/templates/default/uml/dot/dependencies.erb +1 -1
  195. data/templates/default/uml/dot/info.erb +1 -1
  196. data/templates/default/uml/dot/superclasses.erb +2 -2
  197. data/templates/javadoc/methodsummary/html/summary.erb +2 -2
  198. data/templates/javadoc/mixins/html/header.erb +3 -3
  199. metadata +108 -139
  200. data/README +0 -211
  201. data/lib/yard/handlers/method_handler.rb +0 -27
  202. data/lib/yard/handlers/mixin_handler.rb +0 -16
  203. data/lib/yard/parser/statement_list.rb +0 -167
  204. data/lib/yard/tags/merbdoc_factory.rb +0 -47
@@ -0,0 +1,211 @@
1
+ Generators Architecture
2
+ =======================
3
+
4
+ Note: This document describes the architecture of the current generators
5
+ implementation which is likely to undergo large changes in the 0.2.4
6
+ release. Keep this in mind if you plan on extending or implementing
7
+ custom generators.
8
+
9
+ Generators are the main component in the output generation process of YARD,
10
+ which is invoked when conventional HTML/text output needs to be generated
11
+ for a set of code objects.
12
+
13
+ Design Goals
14
+ ------------
15
+
16
+ The general design attempts to be as abstracted from actual content and templates
17
+ as possible. Unlike RDoc which uses one file to describe the entire template,
18
+ YARD splits up the generation of code objects into small components, allowing
19
+ template modification for smaller subsets of a full template without having to
20
+ duplicate the entire template itself. This is necessary because of YARD's support
21
+ for plugins. YARD is designed for extensibility by external plugins, and because
22
+ of this, no one plugin can be responsible for the entire template because no
23
+ one plugin knows about the other plugins being used. For instance, if an RSpec
24
+ plugin was added to support and document specifications in class templates,
25
+ this information would need to be transparently added to the template to work
26
+ in conjunction with any other plugin that performed similar template modifications.
27
+ The design goals can be summarized as follows:
28
+
29
+ 1. Output should be able to be generated for any arbitrary format with little
30
+ modification to YARD's source code. The addition of extra templates should
31
+ be sufficient.
32
+ 2. The output generated for an object should independently generated data
33
+ from arbitrary sources. These independent components are called "sections".
34
+ 3. Sections should be able to be inserted into any object without affecting
35
+ any existing sections in the document. This allows for easy modification
36
+ of templates by plugins.
37
+
38
+ Generators
39
+ ----------
40
+
41
+ Generator classes are the objects used to orchestrate the design goals listed
42
+ above. Specifically, they organize the sections and render the template contents
43
+ depending on the format. The main method used to initiate output is the
44
+ {YARD::Generators::Base#generate #generate} method which takes a list of
45
+ objects to generate output for. A good example of this is the FullDocGenerator,
46
+ which generates conventional HTML documentation:
47
+
48
+ # all_objects is an array of module and class objects
49
+ Generators::FullDocGenerator.new(options).generate(all_objects)
50
+
51
+ Generator Options
52
+ -----------------
53
+
54
+ A generator keeps state when it is generating output. This state is kept in
55
+ an options hash which is initially passed to it during instantiation. Some
56
+ default options set the template style (`:template`), the output format (`:format`),
57
+ and the serializer to use (`:serializer`). For example, initializing the
58
+ {YARD::Generators::QuickDocGenerator} to output as text instead of HTML can be
59
+ done as follows:
60
+
61
+ YARD::Generators::QuickDocGenerator.new(:format => :text).generate(objects)
62
+
63
+ Serializer
64
+ ----------
65
+
66
+ This class abstracts the logic involved in deciding how to serialize data to
67
+ the expected endpoint. For instance, there is both a {YARD::Serializers::StdoutSerializer StdoutSerializer}
68
+ and {YARD::Serializers::FileSystemSerializer FileSystemSerializer} class for
69
+ outputting to console or to a file respectively. When endpoints with locations
70
+ are used (like files or URLs), the serializer implements the {YARD::Serializers::Base#serialized_path #serialized_path}
71
+ method. This allows the translation from a code object to its path at the endpoint,
72
+ which enables inter-document linking.
73
+
74
+ Generated objects are automatically serialized using the object if present,
75
+ otherwise the generated object is returned as a string to its parent. Nested
76
+ generator objects automatically set the serializer to nil so that they return
77
+ as a String to their parent.
78
+
79
+ Templates
80
+ ---------
81
+
82
+ Templates for a generator are by default found inside the one of the template
83
+ root paths (there can be multiple template paths). A standard template
84
+ directory looks like the following tree:
85
+
86
+ (Assuming templates/ is a template root path)
87
+ templates/
88
+ |-- default
89
+ | |-- attributes
90
+ | | |-- html
91
+ | | | `-- header.erb
92
+ | | `-- text
93
+ | | `-- header.erb
94
+ | |-- class
95
+ | | `-- html
96
+ | | `-- header.erb
97
+ | |-- constants
98
+ | | `-- html
99
+ | | |-- constants.erb
100
+ | | |-- header.erb
101
+ | | |-- included.erb
102
+ | | `-- inherited.erb
103
+ ...
104
+
105
+ The path `default` refers to the template style and the directories at the next
106
+ level (such as `attributes`) refer to templates for a generator. The next directory
107
+ refers to the output format being used defined by the `:format` generator option.
108
+ As we saw in the above example, the format option can be set to `:text`, which
109
+ would use the `text/` directory instead of `html/`. Finally, the individual .erb
110
+ files are the sections that make up the generator.
111
+
112
+ Sections
113
+ --------
114
+
115
+ As mentioned above, sections are smaller components that correlate to template
116
+ fragments. Practically speaking, a section can either be a template fragment
117
+ (a conventional .erb file or other supported templating language), a method
118
+ (which returns a String) or another Generator object (which in turn has its own
119
+ list of sections).
120
+
121
+ Creating a Generator
122
+ --------------------
123
+
124
+ To create a generator, subclass {YARD::Generators::Base} and implement the
125
+ `#sections_for(object)` method. This method should return a list of sections where
126
+ a Symbol refers to a method or template name and a class refers to a generator.
127
+
128
+ def sections_for(object)
129
+ case object
130
+ when MethodObject
131
+ [:main, [G(AnotherGenerator)], :footer]
132
+ else
133
+ []
134
+ end
135
+ end
136
+
137
+ A few points about the above example:
138
+
139
+ * The method can return different lists depending on the object.
140
+ * The list of objects is not flat, we will see how nested lists can be used
141
+ in a future example.
142
+ * The convenience method `G()` instantiates a generator out of the class using
143
+ the existing options.
144
+
145
+ If a section is a Symbol, the generator first checks if a method is defined
146
+ with that name, otherwise it checks in the template directories. If a method
147
+ by the symbol name is defined, you need to manually call {YARD::Generators::Base#render #render}
148
+ to return the contents of the template.
149
+
150
+ Nested Sections
151
+ ---------------
152
+
153
+ Sections often require the ability to encapsulate a set of sub-sections in markup
154
+ (HTML, for instance). Rather than use heavier Generator subclass objects, a more
155
+ lightweight solution is to nest a set of sub-sections as a list that follows
156
+ a section, for example:
157
+
158
+ def sections_for(object)
159
+ [:header, [:section_a, :section_b]]
160
+ end
161
+
162
+ The above example nests `section_a` and `section_b` within the `header` section.
163
+ Practically speaking, these sections can be placed in the result by `yield`ing
164
+ to them. A sample header.erb template might contain:
165
+
166
+ <h2>Header</h2>
167
+ <div id="contents">
168
+ <%= yield %>
169
+ </div>
170
+
171
+ This template code would place the output of `section_a` and `section_b` within
172
+ the above div element. Using yield, we can also change the object that is being
173
+ generated. For example, we may want to yield the first method of the class.
174
+ We can do this like so:
175
+
176
+ <h2>First method</h2>
177
+ <%= yield(current_object.meths.first) %>
178
+
179
+ This would run the nested sections for the method object instead of the class.
180
+
181
+ Before Filters
182
+ --------------
183
+
184
+ Generators can run before filters using the {YARD::Generators::Base.before_section before_section} method
185
+ for all or a specific section to test if the section should be generated or
186
+ skipped. For instance, we can do the following to generate the section :foo only
187
+ for MethodObjects:
188
+
189
+ class MyGenerator < YARD::Generators::Base
190
+ before_section :foo, :is_method?
191
+
192
+ def sections_for(object)
193
+ [:foo, :bar, :baz]
194
+ end
195
+
196
+ private
197
+
198
+ def is_method?(object)
199
+ object.is_a?(MethodObject)
200
+ end
201
+ end
202
+
203
+ Without the argument `:foo`, the before filter would be applied to all sections.
204
+ Note that we must return `false` to skip a section. A return type of nil is not
205
+ enough to skip the section.
206
+
207
+ There is also a {YARD::Generators::Base.before_list before_list} method to run
208
+ a filter before the entire generator is run. This is useful for doing necessary
209
+ filesystem setup or for generating assets (stylesheets) before generating output
210
+ for the objects. Note that in this case you will need to serialize your data directly
211
+ using the serializer object (described above).
@@ -0,0 +1,263 @@
1
+ Getting Started with YARD
2
+ =========================
3
+
4
+ There are a few ways which YARD can be of use to you or your project. This
5
+ document will cover the most common ways to use YARD:
6
+
7
+ * [Documenting Code with YARD](#docing)
8
+ * [Using YARD to Generate Documentation](#using)
9
+ * [Extending YARD](#extending)
10
+ * [Templating YARD](#templating)
11
+
12
+ <a name="docing"></a>
13
+ Documenting Code with YARD
14
+ ==========================
15
+
16
+ By default, YARD is compatible with the same RDoc syntax most Ruby developers
17
+ are already familiar with. However, one of the biggest advantages of YARD is
18
+ the extended meta-data syntax, commonly known as "tags", that you can use
19
+ to express small bits of information in a structured and formal manner. While
20
+ RDoc syntax expects you to describe your method in a completely free-form
21
+ manner, YARD recommends declaring your parameters, return types, etc. with
22
+ the `@tag` syntax, which makes outputting the documentation more consistent
23
+ and easier to read. Consider the RDoc documentation for a method reverse:
24
+
25
+ # Converts the object into textual markup given a specific `format`
26
+ # (defaults to `:html`)
27
+ #
28
+ # == Parameters:
29
+ # format::
30
+ # A Symbol declaring the format to convert the object to. This
31
+ # can be `:text` or `:html`.
32
+ #
33
+ # == Returns:
34
+ # A string representing the object in a specified
35
+ #
36
+ # format.
37
+ def to_format(format = :html)
38
+ # reverse the string
39
+ end
40
+
41
+ While this may seem easy enough to read and understand, it's hard for a machine
42
+ to properly pull this data back out of our documentation. Also we've tied our
43
+ markup to our content, and now our documentation becomes hard to maintain if
44
+ we decide later to change our markup style (maybe we don't want the ":" suffix
45
+ on our headers anymore).
46
+
47
+ In YARD, we would simply define our method as:
48
+
49
+ # Converts the object into textual markup given a specific format.
50
+ #
51
+ # @param [Symbol] format the format type, `:text` or `:html`
52
+ # @return [String] the object converted into the expected format.
53
+ def to_format(format = :html)
54
+ end
55
+
56
+ Using tags we can add semantic metadata to our code without worrying about
57
+ presentation. YARD will handle presentation for us when we decide to generate
58
+ documentation later.
59
+
60
+ Adding Tags to Documentation
61
+ ----------------------------
62
+
63
+ The tag syntax that YARD uses is the same @tag-style syntax you may have seen
64
+ if you've ever coded in Java, Python, PHP, Objective-C or a myriad of other
65
+ languages. The following tag adds an author tag to your class:
66
+
67
+ # @author Loren Segal
68
+ class MyClass
69
+ end
70
+
71
+ To allow for large amounts of text, the @tag syntax will recognize any indented
72
+ lines following a tag as part of the tag data. For example:
73
+
74
+ # @deprecated Use {#my_new_method} instead of this method because
75
+ # it uses a library that is no longer supported in Ruby 1.9.
76
+ # The new method accepts the same parameters.
77
+ def mymethod
78
+ end
79
+
80
+ Declaring Types
81
+ ---------------
82
+
83
+ Some tags also have an optional "types" field which let us declare a list of
84
+ types associated with the tag. For instance, a return tag can be declared
85
+ with or without a types field.
86
+
87
+ # @return [String, nil] the contents of our object or nil
88
+ # if the object has not been filled with data.
89
+ def validate; end
90
+
91
+ # We don't care about the "type" here:
92
+ # @return the object
93
+ def to_obj; end
94
+
95
+ The list of types is in the form `[type1, type2, ...]` and is mostly free-form,
96
+ so we can also specify duck-types or constant values. For example:
97
+
98
+ # @param [#to_s] argname any object that responds to `#to_s`
99
+ # @param [true, false] argname only true or false
100
+
101
+ Note the the latter example can be replaced by the meta-type "Boolean", and
102
+ numeric types can be replaced by "Number". These meta-types are by convention
103
+ only, but are recommended.
104
+
105
+ List types can be specified in the form `CollectionClass<ElementType, ...>`.
106
+ For instance, consider the following Array that holds a set of Strings and
107
+ Symbols:
108
+
109
+ # @param [Array<String, Symbol>] list the list of strings and symbols.
110
+
111
+ <a name="taglist"></a>
112
+ List of Tags
113
+ ------------
114
+
115
+ A list of common tags and example usage is below:
116
+
117
+ * `@author`: List the author(s) of a class/method
118
+
119
+ @author Full Name
120
+
121
+ * `@deprecated`: Marks a method/class as deprecated with an optional
122
+ reason.
123
+
124
+ @deprecated Describe the reason or provide alt. references here
125
+
126
+ * `@example`: Show an example snippet of code for an object. The
127
+ first line is an optional title.
128
+
129
+ @example Reverse a string
130
+ "mystring.reverse" #=> "gnirtsym"
131
+
132
+ * `@option`: Describe an options hash in a method. The tag takes the
133
+ name of the options parameter first, followed by optional types,
134
+ the option key name, an optional default value for the key and a
135
+ description of the option.
136
+
137
+ # @param [Hash] opts the options to create a message with.
138
+ # @option opts [String] :subject The subject
139
+ # @option opts [String] :from ('nobody') From address
140
+ # @option opts [String] :to Recipient email
141
+ # @option opts [String] :body ('') The email's body
142
+ def send_email(opts = {})
143
+ end
144
+
145
+ * `@overload`: Describe that your method can be used in various
146
+ contexts with various parameters or return types. The first
147
+ line should declare the new method signature, and the following
148
+ indented tag data will be a new documentation string with its
149
+ own tags adding metadata for such an overload.
150
+
151
+ # @overload set(key, value)
152
+ # Sets a value on key
153
+ # @param [Symbol] key describe key param
154
+ # @param [Object] value describe value param
155
+ # @overload set(value)
156
+ # Sets a value on the default key `:foo`
157
+ # @param [Object] value describe value param
158
+ def set(*args)
159
+ end
160
+
161
+ * `@param`: Defines method parameters
162
+
163
+ @param [optional, types, ...] argname description
164
+
165
+ * `@raise`: Describes an Exception that a method may throw
166
+
167
+ @raise [ExceptionClass] description
168
+
169
+ * `@return`: Describes return value of method
170
+
171
+ @return [optional, types, ...] description
172
+
173
+ * `@see`: "See Also" references for an object. Accepts URLs or
174
+ other code objects with an optional description at the end.
175
+
176
+ @see http://example.com Description of URL
177
+ @see SomeOtherClass#method
178
+
179
+ * `@since`: Lists the version the feature/object was first added
180
+
181
+ @since 1.2.4
182
+
183
+ * `@todo`: Marks a TODO note in the object being documented
184
+
185
+ @todo Add support for Jabberwocky service
186
+ There is an open source Jabberwocky library available
187
+ at http://somesite.com that can be integrated easily
188
+ into the project.
189
+
190
+ * `@version`: Lists the version of a class, module or method
191
+
192
+ @version 1.0
193
+
194
+ * `@yield`: Describes the block. Use types to list the parameter
195
+ names the block yields.
196
+
197
+ # for block {|a, b, c| ... }
198
+ @yield [a, b, c] Description of block
199
+
200
+ * `@yieldparam`: Defines parameters yielded by a block
201
+
202
+ @yieldparam [optional, types, ...] argname description
203
+
204
+ * `@yieldreturn`: Defines return type of a block
205
+
206
+ @yieldreturn [optional, types, ...] description
207
+
208
+ Other Extended Syntax
209
+ ---------------------
210
+
211
+ **Reference Tags**
212
+
213
+ To minimize rewriting of documentation and to ease maintenance, a special
214
+ tag syntax is allowed to reference tags from other objects. Doing this allows
215
+ a tag to be added as meta-data for multiple objects. A full example of this
216
+ syntax is found in the {file:TAGS.markdown#reftags TAGS.markdown} file.
217
+
218
+ **Inter-Document Links**
219
+
220
+ YARD supports a special syntax to link to other code objects or files.
221
+ The syntax is `{ObjectName#method OPTIONAL_TITLE}`. This syntax is acceptable
222
+ anywhere in documentation with the exception of the @see tag, which
223
+ automatically links its data.
224
+
225
+ <a name="using"></a>
226
+ Using YARD to Generate Documentation
227
+ ====================================
228
+
229
+ Obviously since YARD is a documentation tool, one of its primary goals is
230
+ to generate documentation for a variety of formats, most commonly HTML. The
231
+ `yardoc` tool that is installed with YARD allows you to quickly export code
232
+ documentation to HTML document files. In addition to this, YARD ships with
233
+ two more tools allowing you to quickly view `ri`-style documentation for
234
+ a specific class or method as well as an extra tool to generate UML diagrams
235
+ for your code using [Graphviz][graphviz]. An overview of these tools can
236
+ be found in the {file:README.markdown README} under the Usage section.
237
+
238
+ <a name="extending"></a>
239
+ Extending YARD
240
+ ==============
241
+
242
+ There are many ways to extend YARD to support non-standard Ruby syntax (DSLs),
243
+ add new meta-data tags or programmatically access the intermediate metadata
244
+ and documentation from code. An overview of YARD's full architecture can be
245
+ found in the {file:OVERVIEW.markdown} document.
246
+
247
+ For information on adding support for Ruby DSLs, see the {file:HANDLERS.markdown}
248
+ and {file:PARSER.markdown} architecture documents.
249
+
250
+ For information on adding extra tags, see {file:TAGS.markdown}.
251
+
252
+ For information on accessing the data YARD stores about your documentation,
253
+ look at the {file:CODE_OBJECTS.markdown} architecture document.
254
+
255
+ <a name="templating"></a>
256
+ Templating YARD
257
+ ===============
258
+
259
+ In many cases you may want to change the style of YARD's templates or add extra
260
+ information after extending it. The {file:GENERATORS.markdown} architecture
261
+ document covers the basics of how YARD's templating system works.
262
+
263
+ [graphviz]:http://www.graphviz.org