yard 0.9.29 → 0.9.30

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 (152) hide show
  1. checksums.yaml +4 -4
  2. data/docs/CodeObjects.md +115 -0
  3. data/docs/GettingStarted.md +679 -0
  4. data/docs/Handlers.md +152 -0
  5. data/docs/Overview.md +61 -0
  6. data/docs/Parser.md +191 -0
  7. data/docs/Tags.md +283 -0
  8. data/docs/TagsArch.md +123 -0
  9. data/docs/Templates.md +496 -0
  10. data/docs/WhatsNew.md +1245 -0
  11. data/docs/images/code-objects-class-diagram.png +0 -0
  12. data/docs/images/handlers-class-diagram.png +0 -0
  13. data/docs/images/overview-class-diagram.png +0 -0
  14. data/docs/images/parser-class-diagram.png +0 -0
  15. data/docs/images/tags-class-diagram.png +0 -0
  16. data/docs/templates/default/fulldoc/html/full_list_tag.erb +9 -0
  17. data/docs/templates/default/fulldoc/html/setup.rb +6 -0
  18. data/docs/templates/default/layout/html/setup.rb +9 -0
  19. data/docs/templates/default/layout/html/tag_list.erb +11 -0
  20. data/docs/templates/default/yard_tags/html/list.erb +18 -0
  21. data/docs/templates/default/yard_tags/html/setup.rb +26 -0
  22. data/docs/templates/plugin.rb +70 -0
  23. data/lib/yard/version.rb +1 -1
  24. data/po/ja.po +31108 -0
  25. data/templates/default/class/dot/setup.rb +7 -0
  26. data/templates/default/class/dot/superklass.erb +3 -0
  27. data/templates/default/class/html/constructor_details.erb +8 -0
  28. data/templates/default/class/html/setup.rb +2 -0
  29. data/templates/default/class/html/subclasses.erb +4 -0
  30. data/templates/default/class/setup.rb +36 -0
  31. data/templates/default/class/text/setup.rb +12 -0
  32. data/templates/default/class/text/subclasses.erb +5 -0
  33. data/templates/default/constant/text/header.erb +11 -0
  34. data/templates/default/constant/text/setup.rb +4 -0
  35. data/templates/default/docstring/html/abstract.erb +4 -0
  36. data/templates/default/docstring/html/deprecated.erb +1 -0
  37. data/templates/default/docstring/html/index.erb +5 -0
  38. data/templates/default/docstring/html/note.erb +6 -0
  39. data/templates/default/docstring/html/private.erb +4 -0
  40. data/templates/default/docstring/html/returns_void.erb +1 -0
  41. data/templates/default/docstring/html/text.erb +1 -0
  42. data/templates/default/docstring/html/todo.erb +6 -0
  43. data/templates/default/docstring/setup.rb +52 -0
  44. data/templates/default/docstring/text/abstract.erb +2 -0
  45. data/templates/default/docstring/text/deprecated.erb +2 -0
  46. data/templates/default/docstring/text/index.erb +2 -0
  47. data/templates/default/docstring/text/note.erb +4 -0
  48. data/templates/default/docstring/text/private.erb +2 -0
  49. data/templates/default/docstring/text/returns_void.erb +1 -0
  50. data/templates/default/docstring/text/text.erb +1 -0
  51. data/templates/default/docstring/text/todo.erb +4 -0
  52. data/templates/default/fulldoc/html/css/common.css +1 -0
  53. data/templates/default/fulldoc/html/css/full_list.css +58 -0
  54. data/templates/default/fulldoc/html/css/style.css +497 -0
  55. data/templates/default/fulldoc/html/frames.erb +17 -0
  56. data/templates/default/fulldoc/html/full_list.erb +37 -0
  57. data/templates/default/fulldoc/html/full_list_class.erb +2 -0
  58. data/templates/default/fulldoc/html/full_list_file.erb +7 -0
  59. data/templates/default/fulldoc/html/full_list_method.erb +10 -0
  60. data/templates/default/fulldoc/html/js/app.js +314 -0
  61. data/templates/default/fulldoc/html/js/full_list.js +216 -0
  62. data/templates/default/fulldoc/html/js/jquery.js +4 -0
  63. data/templates/default/fulldoc/html/setup.rb +241 -0
  64. data/templates/default/layout/dot/header.erb +6 -0
  65. data/templates/default/layout/dot/setup.rb +15 -0
  66. data/templates/default/layout/html/breadcrumb.erb +11 -0
  67. data/templates/default/layout/html/files.erb +11 -0
  68. data/templates/default/layout/html/footer.erb +5 -0
  69. data/templates/default/layout/html/headers.erb +15 -0
  70. data/templates/default/layout/html/index.erb +2 -0
  71. data/templates/default/layout/html/layout.erb +24 -0
  72. data/templates/default/layout/html/listing.erb +4 -0
  73. data/templates/default/layout/html/objects.erb +32 -0
  74. data/templates/default/layout/html/script_setup.erb +4 -0
  75. data/templates/default/layout/html/search.erb +13 -0
  76. data/templates/default/layout/html/setup.rb +89 -0
  77. data/templates/default/method/html/header.erb +17 -0
  78. data/templates/default/method/setup.rb +4 -0
  79. data/templates/default/method/text/header.erb +1 -0
  80. data/templates/default/method_details/html/header.erb +3 -0
  81. data/templates/default/method_details/html/method_signature.erb +25 -0
  82. data/templates/default/method_details/html/source.erb +10 -0
  83. data/templates/default/method_details/setup.rb +11 -0
  84. data/templates/default/method_details/text/header.erb +10 -0
  85. data/templates/default/method_details/text/method_signature.erb +12 -0
  86. data/templates/default/method_details/text/setup.rb +11 -0
  87. data/templates/default/module/dot/child.erb +1 -0
  88. data/templates/default/module/dot/dependencies.erb +3 -0
  89. data/templates/default/module/dot/header.erb +6 -0
  90. data/templates/default/module/dot/info.erb +14 -0
  91. data/templates/default/module/dot/setup.rb +15 -0
  92. data/templates/default/module/html/attribute_details.erb +10 -0
  93. data/templates/default/module/html/attribute_summary.erb +8 -0
  94. data/templates/default/module/html/box_info.erb +43 -0
  95. data/templates/default/module/html/children.erb +8 -0
  96. data/templates/default/module/html/constant_summary.erb +17 -0
  97. data/templates/default/module/html/defines.erb +3 -0
  98. data/templates/default/module/html/header.erb +5 -0
  99. data/templates/default/module/html/inherited_attributes.erb +14 -0
  100. data/templates/default/module/html/inherited_constants.erb +8 -0
  101. data/templates/default/module/html/inherited_methods.erb +19 -0
  102. data/templates/default/module/html/item_summary.erb +40 -0
  103. data/templates/default/module/html/method_details_list.erb +9 -0
  104. data/templates/default/module/html/method_summary.erb +14 -0
  105. data/templates/default/module/html/methodmissing.erb +12 -0
  106. data/templates/default/module/html/pre_docstring.erb +1 -0
  107. data/templates/default/module/setup.rb +167 -0
  108. data/templates/default/module/text/children.erb +10 -0
  109. data/templates/default/module/text/class_meths_list.erb +8 -0
  110. data/templates/default/module/text/extends.erb +8 -0
  111. data/templates/default/module/text/header.erb +7 -0
  112. data/templates/default/module/text/includes.erb +8 -0
  113. data/templates/default/module/text/instance_meths_list.erb +8 -0
  114. data/templates/default/module/text/setup.rb +13 -0
  115. data/templates/default/onefile/html/files.erb +5 -0
  116. data/templates/default/onefile/html/headers.erb +6 -0
  117. data/templates/default/onefile/html/layout.erb +17 -0
  118. data/templates/default/onefile/html/readme.erb +3 -0
  119. data/templates/default/onefile/html/setup.rb +62 -0
  120. data/templates/default/root/dot/child.erb +3 -0
  121. data/templates/default/root/dot/setup.rb +6 -0
  122. data/templates/default/root/html/setup.rb +2 -0
  123. data/templates/default/tags/html/example.erb +11 -0
  124. data/templates/default/tags/html/index.erb +3 -0
  125. data/templates/default/tags/html/option.erb +24 -0
  126. data/templates/default/tags/html/overload.erb +14 -0
  127. data/templates/default/tags/html/see.erb +8 -0
  128. data/templates/default/tags/html/tag.erb +20 -0
  129. data/templates/default/tags/setup.rb +57 -0
  130. data/templates/default/tags/text/example.erb +12 -0
  131. data/templates/default/tags/text/index.erb +1 -0
  132. data/templates/default/tags/text/option.erb +20 -0
  133. data/templates/default/tags/text/overload.erb +19 -0
  134. data/templates/default/tags/text/see.erb +11 -0
  135. data/templates/default/tags/text/tag.erb +13 -0
  136. data/templates/guide/class/html/setup.rb +2 -0
  137. data/templates/guide/docstring/html/setup.rb +2 -0
  138. data/templates/guide/fulldoc/html/css/style.css +108 -0
  139. data/templates/guide/fulldoc/html/js/app.js +33 -0
  140. data/templates/guide/fulldoc/html/setup.rb +74 -0
  141. data/templates/guide/layout/html/layout.erb +81 -0
  142. data/templates/guide/layout/html/setup.rb +25 -0
  143. data/templates/guide/method/html/header.erb +18 -0
  144. data/templates/guide/method/html/setup.rb +22 -0
  145. data/templates/guide/module/html/header.erb +7 -0
  146. data/templates/guide/module/html/method_list.erb +5 -0
  147. data/templates/guide/module/html/setup.rb +27 -0
  148. data/templates/guide/onefile/html/files.erb +4 -0
  149. data/templates/guide/onefile/html/setup.rb +6 -0
  150. data/templates/guide/onefile/html/toc.erb +3 -0
  151. data/templates/guide/tags/html/setup.rb +9 -0
  152. metadata +151 -2
data/docs/Tags.md ADDED
@@ -0,0 +1,283 @@
1
+ # @title Tags Overview
2
+
3
+ # Tags Overview
4
+
5
+ Tags represent meta-data as well as behavioural data that can be added to
6
+ documentation through the `@tag` style syntax. As mentioned, there are two
7
+ basic types of tags in YARD, "meta-data tags" and "behavioural tags", the
8
+ latter is more often known as "directives". These two tag types can be
9
+ visually identified by their prefix. Meta-data tags have a `@` prefix,
10
+ while directives have a prefix of `@!` to indicate that the directive
11
+ performs some potentially mutable action on or with the docstring. The
12
+ two tag types would be used in the following way, respectively:
13
+
14
+ # @meta_data_tag some data
15
+ # @!directive_tag some data
16
+ class Foo; end
17
+
18
+ This document describes how tags can be specified, how they affect your
19
+ documentation, and how to use specific built-in tags in YARD, as well
20
+ as how to define custom tags.
21
+
22
+ ## Meta-Data Tags
23
+
24
+ Meta-data tags are useful to add arbitrary meta-data about a documented
25
+ object. These tags simply add data to objects that can be looked up later,
26
+ either programmatically, or displayed in templates. The benefit to describing
27
+ objects using meta-data tags is that your documentation can be organized
28
+ semantically. Rather than having a huge listing of text with no distinction
29
+ of what each paragraph is discussing, tags allow you to focus in on specific
30
+ elements of your documentation.
31
+
32
+ For example, describing parameters of a method can often be important to your
33
+ documentation, but should not be mixed up with the documentation that describes
34
+ what the method itself does. In this case, separating the parameter documentation
35
+ into {tag:param} tags can yield much better organized documentation, both in
36
+ source and in your output, without having to manually format the data using
37
+ standard markup.
38
+
39
+ All of this meta-data can be easily parsed by tools and used both in your templates
40
+ as well as in code checker tools. An example of how you can leverage tags
41
+ programmatically is shown in the {tag:todo} tag, which lists a small snippet of
42
+ Ruby code that can list all of your TODO items, if they are properly tagged.
43
+
44
+ Custom meta-data tags can be added either programmatically or via the YARD
45
+ command-line. This is discussed in the "[Adding Custom Tags](#Adding_Custom_Tags)"
46
+ section.
47
+
48
+ A list of built-in meta-data tags are found below in the [Tag List](#Tag_List).
49
+
50
+ ## Directives
51
+
52
+ Directives are similar to meta-data tags in the way they are specified, but they
53
+ do not add meta-data to the object directly. Instead, they affect the parsing
54
+ context and objects themselves, allowing a developer to create objects
55
+ (like methods) outright, rather than simply add text to an existing object.
56
+ Directives have a `@!` prefix to differentiate these tags from meta-data tags,
57
+ as well as to indicate that the tag may modify or create new objects when
58
+ it is called.
59
+
60
+ A list of built-in directives are found below in the [Directive List](#Directive_List).
61
+
62
+ ## Tag Syntax
63
+
64
+ Tags begin with the `@` or `@!` prefix at the start of a comment line, followed
65
+ immediately by the tag name, and then optional tag data (if the tag requires it).
66
+ Unless otherwise specified by documentation for the tag, all "description" text
67
+ is considered free-form data and can include any arbitrary textual data.
68
+
69
+ ### Multi-line Tags
70
+
71
+ Tags can span multiple lines if the subsequent lines are indented by more than
72
+ one space. The typical convention is to indent subsequent lines by 2 spaces.
73
+ In the following example, `@tagname` will have the text *"This is indented tag data"*:
74
+
75
+ # @tagname This is
76
+ # indented tag data
77
+ # but this is not
78
+
79
+ For most tags, newlines and indented data are not significant and do not impact
80
+ the result of the tag. In other words, you can decide to span a tag onto multiple
81
+ lines at any point by creating an indented block. However, some tags like
82
+ {tag:example}, {tag:overload}, {tag:!macro}, {tag:!method}, and {tag:!attribute}
83
+ rely on the first line for special information about the tag, and you cannot
84
+ split this first line up. For instance, the {tag:example} tag uses the first line
85
+ to indicate the example's title.
86
+
87
+ ### Common Tag Syntaxes
88
+
89
+ Although custom tags can be parsed in any way, the built-in tags follow a few
90
+ common syntax structures by convention in order to simplify the syntax. The
91
+ following syntaxes are available:
92
+
93
+ 1. **Freeform data** — In this case, any amount of textual data is allowed,
94
+ including no data. In some cases, no data is necessary for the tag.
95
+ 2. **Freeform data with a types specifier list** — Mostly freeform data
96
+ beginning with an *optional* types specifier list surrounded in `[brackets]`.
97
+ Note that for extensibility, other bracket types are allowed, such as `<>`,
98
+ `()` and `{}`. The contents of the list are discussed in detail below.
99
+ 3. **Freeform data with a name and types specifier list** &mdash; freeform
100
+ data beginning with an *optional* types list, as well as a name key, placed
101
+ either before or after the types list. The name key is *required*. Note that
102
+ for extensibility, the name can be placed *before* the types list, like:
103
+ `name [Types] description`. In this case, a separating space is not required
104
+ between the name and types, and you can still use any of the other brackets
105
+ that the type specifier list allows.
106
+ 4. **Freeform data with title** &mdash; freeform data where the first line cannot
107
+ be split into multiple lines. The first line must also always refer to the
108
+ "title" portion, and therefore, if there is no title, the first line must
109
+ be blank. The "title" might occasionally be listed by another name in tag
110
+ documentation, however, you can identify this syntax by the existence of
111
+ a multi-line signature with "Indented block" on the second line.
112
+
113
+ In the tag list below, the term "description" implies freeform data, `[Types]`
114
+ implies a types specifier list, "name" implies a name key, and "title" implies
115
+ the first line is a newline significant field that cannot be split into multiple
116
+ lines.
117
+
118
+ ### Types Specifier List
119
+
120
+ In some cases, a tag will allow for a "types specifier list"; this will be evident
121
+ from the use of the `[Types]` syntax in the tag signature. A types specifier list
122
+ is a comma separated list of types, most often classes or modules, but occasionally
123
+ literals. For example, the following {tag:return} tag lists a set of types returned
124
+ by a method:
125
+
126
+ # Finds an object or list of objects in the db using a query
127
+ # @return [String, Array<String>, nil] the object or objects to
128
+ # find in the database. Can be nil.
129
+ def find(query) finder_code_here end
130
+
131
+ A list of conventions for type names is specified below. Typically, however,
132
+ any Ruby literal or class/module is allowed here. Duck-types (method names
133
+ prefixed with "#") are also allowed.
134
+
135
+ Note that the type specifier list is always an optional field and can be omitted
136
+ when present in a tag signature. This is the reason why it is surrounded by
137
+ brackets. It is also a freeform list, and can contain any list of values, though
138
+ a set of conventions for how to list types is described below.
139
+
140
+ ### Type List Conventions
141
+
142
+ <p class="note">
143
+ A list of examples of common type listings and what they translate into is
144
+ available at <a href="http://yardoc.org/types">http://yardoc.org/types</a>.
145
+ </p>
146
+
147
+ Typically, a type list contains a list of classes or modules that are associated
148
+ with the tag. In some cases, however, certain special values are allowed or required
149
+ to be listed. This section discusses the syntax for specifying Ruby types inside of
150
+ type specifier lists, as well as the other non-Ruby types that are accepted by
151
+ convention in these lists.
152
+
153
+ It's important to realize that the conventions listed here may not always adequately
154
+ describe every type signature, and is not meant to be a complete syntax. This is
155
+ why the types specifier list is freeform and can contain any set of values. The
156
+ conventions defined here are only conventions, and if they do not work for your
157
+ type specifications, you can define your own appropriate conventions.
158
+
159
+ Note that a types specifier list might also be used for non-Type values. In this
160
+ case, the tag documentation will describe what values are allowed within the
161
+ type specifier list.
162
+
163
+ #### Class or Module Types
164
+
165
+ Any Ruby type is allowed as a class or module type. Such a type is simply the name
166
+ of the class or module.
167
+
168
+ Note that one extra type that is accepted by convention is the `Boolean` type,
169
+ which represents both the `TrueClass` and `FalseClass` types. This type does not
170
+ exist in Ruby, however.
171
+
172
+ #### Parametrized Types
173
+
174
+ In addition to basic types (like String or Array), YARD conventions allow for
175
+ a "generics" like syntax to specify container objects or other parametrized types.
176
+ The syntax is `Type<SubType, OtherSubType, ...>`. For instance, an Array might
177
+ contain only String objects, in which case the type specification would be
178
+ `Array<String>`. Multiple parametrized types can be listed, separated by commas.
179
+
180
+ Note that parametrized types are typically not order-dependent, in other words,
181
+ a list of parametrized types can occur in any order inside of a type. An array
182
+ specified as `Array<String, Fixnum>` can contain any amount of Strings or Fixnums,
183
+ in any order. When the order matters, use "order-dependent lists", described below.
184
+
185
+ #### Duck-Types
186
+
187
+ Duck-types are allowed in type specifier lists, and are identified by method
188
+ names beginning with the "#" prefix. Typically, duck-types are recommended
189
+ for {tag:param} tags only, though they can be used in other tags if needed.
190
+ The following example shows a method that takes a parameter of any type
191
+ that responds to the "read" method:
192
+
193
+ # Reads from any I/O object.
194
+ # @param io [#read] the input object to read from
195
+ def read(io) io.read end
196
+
197
+ #### Hashes
198
+
199
+ Hashes can be specified either via the parametrized type discussed above,
200
+ in the form `Hash<KeyType, ValueType>`, or using the hash specific syntax:
201
+ `Hash{KeyTypes=>ValueTypes}`. In the latter case, KeyTypes or ValueTypes can
202
+ also be a list of types separated by commas.
203
+
204
+ #### Order-Dependent Lists
205
+
206
+ An order dependent list is a set of types surrounded by "()" and separated by
207
+ commas. This list must contain exactly those types in exactly the order specified.
208
+ For instance, an Array containing a String, Fixnum and Hash in that order (and
209
+ having exactly those 3 elements) would be listed as: `Array<(String, Fixnum, Hash)>`.
210
+
211
+ #### Literals
212
+
213
+ Some literals are accepted by virtue of being Ruby literals, but also by YARD
214
+ conventions. Here is a non-exhaustive list of certain accepted literal values:
215
+
216
+ * `true`, `false`, `nil` &mdash; used when a method returns these explicit literal
217
+ values. Note that if your method returns both `true` or `false`, you should use
218
+ the `Boolean` conventional type instead.
219
+ * `self` &mdash; has the same meaning as Ruby's "self" keyword in the context of
220
+ parameters or return types. Recommended mostly for {tag:return} tags that are
221
+ chainable.
222
+ * `void` &mdash; indicates that the type for this tag is explicitly undefined.
223
+ Mostly used to specify {tag:return} tags that do not care about their return
224
+ value. Using a `void` return tag is recommended over no type, because it makes
225
+ the documentation more explicit about what the user should expect. YARD will
226
+ also add a note for the user if they have undefined return types, making things
227
+ clear that they should not use the return value of such a method.
228
+
229
+ <a name="reftags"></a>
230
+
231
+ ### Reference Tags
232
+
233
+ <p class="note">
234
+ Reference tag syntax applies only to meta-data tags, not directives.
235
+ </p>
236
+
237
+ If a tag's data begins with `(see OBJECT)` it is considered a "reference tag".
238
+ A reference tag literally copies the tag data by the given tag name from the
239
+ specified OBJECT. For instance, a method may copy all {tag:param} tags from
240
+ a given object using the reference tag syntax:
241
+
242
+ # @param user [String] the username for the operation
243
+ # @param host [String] the host that this user is associated with
244
+ # @param time [Time] the time that this operation took place
245
+ def clean(user, host, time = Time.now) end
246
+
247
+ # @param (see #clean)
248
+ def activate(user, host, time = Time.now) end
249
+
250
+ ## Adding Custom Tags
251
+
252
+ <p class="note">If a tag is specific to a given project, consider namespacing
253
+ it by naming it in the form <tt>projectname.tagname</tt>, ie.,
254
+ <tt>yard.tag_signature</tt>.</p>
255
+
256
+ Custom tags can be added to YARD either via the command-line or programmatically.
257
+ The programmatic method is not discussed in this document, but rather in the
258
+ {file:docs/TagsArch.md} document.
259
+
260
+ To add a custom tag via the command-line or .yardopts file, you can use the
261
+ `--*-tag` options. A few different options are available for the common tag
262
+ syntaxes described above. For example, to add a basic freeform tag, use:
263
+
264
+ !!!sh
265
+ $ yard doc --tag rest_url:"REST URL"
266
+
267
+ This will register the `@rest_url` tag for use in your documentation and display
268
+ this tag in HTML output wherever it is used with the heading "REST URL".
269
+ Note that the tag title should follow the tag name with a colon (`:`). Other
270
+ tag syntaxes exist, such as the type specifier list freeform tag
271
+ (`--type-tag`), or a named key tag with types (`--type-name-tag`).
272
+
273
+ If you want to create a tag but not display it in output (it is only for
274
+ programmatic use), add `--hide-tag tagname` after the definition:
275
+
276
+ !!!sh
277
+ $ yard doc --tag complexity:"McCabe Complexity" --hide-tag complexity
278
+
279
+ Note that you might not need a tag title if you are hiding it. The title
280
+ part can be omitted.
281
+
282
+ {yard:include_tags}
283
+
data/docs/TagsArch.md ADDED
@@ -0,0 +1,123 @@
1
+ # @title Tags Architecture
2
+
3
+ # Tags Architecture
4
+
5
+ ## Programmatic API
6
+
7
+ ### Accessing Tag Information
8
+
9
+ Tag metadata is added when a {YARD::Docstring} is added to a {file:docs/CodeObjects.md code object}
10
+ using the {YARD::CodeObjects::Base#docstring=} attribute. In addition to adding
11
+ conventional comments, tags are parsed and associated with the object. The easiest
12
+ way to access tags on an object is to use the {YARD::CodeObjects::Base#tag} and `#tags`
13
+ methods, for example:
14
+
15
+ # Using the Foo class object from above
16
+ obj.tags(:tagname).first.text #=> "some data"
17
+
18
+ Because multiple tags can be stored with the same name, they are stored as a list
19
+ of tags. The `#tag` method is an alias for the first item in the list of tags.
20
+ Also note that the `#tag`, `#tags` and `#has_tag?` methods are all convenience
21
+ methods that delegate to the {YARD::Docstring} object described above.
22
+
23
+ ### Adding Custom Tags
24
+
25
+ The `@tagname` tag used in the above examples is clearly not part of the tags
26
+ that come with YARD. If such a tag would actually be part of documentation under
27
+ a default install, YARD would raise a warning that the tag does not exist. It is,
28
+ however, trivial to add this tag to be recognized by YARD.
29
+
30
+ All tags in YARD are added to the {YARD::Tags::Library tag library} which makes
31
+ use of a tag factory class to parse the data inside the tags. To simply add a
32
+ tag that stores simple text like our `@tagname` tag above, use:
33
+
34
+ YARD::Tags::Library.define_tag("A Sample Tag", :tagname)
35
+
36
+ This will now allow YARD to add the metadata from `@tagname` to the docstring.
37
+
38
+ ## Tag Factory Architecture
39
+
40
+ Recognizing a tag is one part of the process. Parsing the tag contents is the
41
+ second step. YARD has a tag architecture that allows developers to add or completely
42
+ change the way tags contents can be parsed.
43
+
44
+ The separation of registration and tag creation can be seen in the following
45
+ class diagram:
46
+
47
+ ![Tags Architecture Class Diagram](images/tags-class-diagram.png)
48
+
49
+ ### DefaultFactory
50
+
51
+ By default, YARD has a few standard syntaxes that can be parsed for tags. These
52
+ are all implemented by the {YARD::Tags::DefaultFactory} class. These syntaxes
53
+ are:
54
+
55
+ * Standard text: no parsing is done, but text is stripped of newlines and
56
+ multiple spaces.
57
+
58
+ * Raw text: does no parsing at all, no stripping of newlines or spaces. This
59
+ is best used for code snippets.
60
+
61
+ * Raw text with title: does no parsing on the text but extracts the first line
62
+ of the metadata as the "title", useful for tags such as `@example`:
63
+
64
+ # @example Inspect an element
65
+ # myobj.inspect #=> #<Object:0x123525>
66
+
67
+ * Text with types: parses a list of types at the beginning of the text. Types
68
+ are optional. The standard syntax is in the form `[type1, type2, ...]`,
69
+ for example:
70
+
71
+ # @return [String, Symbol] a description here
72
+ # @return description here with no types
73
+
74
+ * Text with types and a name: parses a list of types at the beginning of text
75
+ followed by a name and extra descriptive text. For example:
76
+
77
+ # @param [String] str the string to reverse
78
+ def reverse(str) '...' end
79
+
80
+ As mentioned above, this syntax is implemented by the `DefaultFactory` which can
81
+ be swapped out for any factory. In some cases, a developer may want to change
82
+ the type declaration syntax to be in the form:
83
+
84
+ # @tagname name <Types, here> description
85
+
86
+ This can be done by simply implementing a new factory that parses the data in
87
+ this form.
88
+
89
+ ### Implementing a Factory
90
+
91
+ Factories should implement the method `parse_tag` as well as any `parse_tag_SUFFIX`
92
+ method where SUFFIX refers to the suffix added when declaring the tag. For example,
93
+ a tag can also be declared as follows:
94
+
95
+ YARD::Tags::Library.define_tag "Parameter", :param, :with_types
96
+
97
+ In such a case, the factory will be called with method `parse_tag_with_types`. In
98
+ all cases, the method should return a new {YARD::Tags::Tag} object. Generally,
99
+ the `parse_tag` methods take 2 or 3 parameters. A simple tag can be implemented
100
+ as:
101
+
102
+ def parse_tag(tag_name, text)
103
+ Tag.new(tag_name, text)
104
+ end
105
+
106
+ The text parameter contains pre-parsed text with extra spaces and newlines removed.
107
+ If required, the method could also be declared with a third parameter containing
108
+ unmodified raw text:
109
+
110
+ def parse_tag_with_raw_text(tag_name, text, raw_text)
111
+ Tag.new(tag_name, raw_text)
112
+ end
113
+
114
+ Note that this method would be invoked for a tag declared with the `:with_raw_text`
115
+ suffix.
116
+
117
+ ### Changing the Factory
118
+
119
+ To change the factory, set the {YARD::Tags::Library.default_factory} attribute:
120
+
121
+ YARD::Tags::Library.default_factory = MyFactory
122
+
123
+ This must be done before any parsing is done, or the factory will not be used.