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/docs/Glossary.md CHANGED
@@ -1,5 +1,4 @@
1
- Glossary
2
- ========
1
+ # Glossary
3
2
 
4
3
  * **Code Object**: Any explicitly defined Ruby source that describes a feature
5
4
  of the code. By default, this refers to classes, modules, methods, constants
data/docs/Handlers.md CHANGED
@@ -1,5 +1,6 @@
1
- Handlers Architecture
2
- =====================
1
+ # @title Handlers Architecture
2
+
3
+ # Handlers Architecture
3
4
 
4
5
  Handlers allow the processing of parsed source code. Handling is done after
5
6
  parsing to abstract away the implementation details of lexical and semantic
@@ -8,8 +9,7 @@ source statements as {file:docs/CodeObjects.md code objects}.
8
9
 
9
10
  ![Handlers Architecture Class Diagram](images/handlers-class-diagram.png)
10
11
 
11
- The Pipeline
12
- ------------
12
+ ## The Pipeline
13
13
 
14
14
  After the {file:docs/Parser.md parser component} finishes analyzing the
15
15
  source, it is handed off for post-processing to the {YARD::Handlers::Processor}
@@ -19,8 +19,7 @@ the parser and delegating them to matching handlers. Handlers match when the
19
19
  The handler can then perform any action after being invoked by the `process`
20
20
  method.
21
21
 
22
- The Processor Class
23
- -------------------
22
+ ## The Processor Class
24
23
 
25
24
  The main purpose of the processor, as mentioned above, is to traverse through
26
25
  the list of statements given to it by the parser. The processor also keeps
@@ -32,8 +31,7 @@ is most often the same as the namespace, except when parsing the body of a metho
32
31
  where the namespace would be the class/module the method is defined in and the
33
32
  owner would be the method object itself.
34
33
 
35
- Implementing a Handler
36
- ======================
34
+ ## Implementing a Handler
37
35
 
38
36
  This section covers the basics of implementing a *new-style* Ruby handler. For
39
37
  details on implementing a legacy handler, see the "API Differences" section below.
@@ -60,8 +58,7 @@ node types respectively (the latter refers to classes defined as `class << Somet
60
58
  The {YARD::Handlers::Base#statement statement} attribute refers to the current
61
59
  node (or statement) that is being handled by the handler.
62
60
 
63
- Handling a Method Call
64
- ----------------------
61
+ ### Handling a Method Call
65
62
 
66
63
  In some cases, a developer might need to handle a method call. The parser can
67
64
  express a method call in many AST forms, so to simplify this process, a method
@@ -85,8 +82,7 @@ the following syntaxes:
85
82
  a_block
86
83
  end
87
84
 
88
- Creating a new Code Object
89
- --------------------------
85
+ ### Creating a new Code Object
90
86
 
91
87
  Usually (but not always) handling is performed to create new code objects to add
92
88
  to the registry (for information about code objects, see {file:docs/CodeObjects.md this document}).
@@ -96,8 +92,7 @@ will be enough to add them to the registry. There is also a convenience
96
92
  on the newly created object, such as the file, line, source and docstring of the
97
93
  object. This method will be seen in the next example.
98
94
 
99
- Handling an Inner Block
100
- -----------------------
95
+ ### Handling an Inner Block
101
96
 
102
97
  By default, the parser gives the processor class a list of all the top level
103
98
  statements and the processor parses only those top level statements. If an inner
@@ -125,8 +120,7 @@ wish to parse. Note here that when parsing objects like modules and classes,
125
120
  we set the namespace for the duration of the block parsing by setting options
126
121
  on the `parse_block` method.
127
122
 
128
- API Differences for Legacy Handler
129
- ----------------------------------
123
+ ### API Differences for Legacy Handler
130
124
 
131
125
  Because the legacy handler uses the legacy parser and therefore a different kind
132
126
  of AST, there are subtle differences in the handler API. Most importantly, the
data/docs/Overview.md CHANGED
@@ -1,5 +1,6 @@
1
- Architecture Overview
2
- =====================
1
+ # @title Architecture Overview
2
+
3
+ # Architecture Overview
3
4
 
4
5
  YARD is separated in three major components, each of which allows YARD to be
5
6
  extended for a separate purpose. The split also emphasizes YARD's design choice
@@ -23,17 +24,17 @@ following class diagram:
23
24
  ![Overview Class Diagram](images/overview-class-diagram.png)
24
25
 
25
26
  <a name="parsing"></a>
26
- Code Parsing & Processing Component
27
- -----------------------------------
27
+
28
+ ## Code Parsing & Processing Component
28
29
 
29
30
  This component is made up of four sub-components, each of which have separate
30
31
  tasks during the data gathering process (*note: the tag architecture is not*
31
32
  *shown in the class diagram*). These sub-components are:
32
33
 
33
- * {file:docs/Parser.md Parser Architecture}
34
- * {file:docs/Handlers.md Handler Architecture}
35
- * {file:docs/CodeObjects.md Code Object Architecture}
36
- * {file:docs/Tags.md Tag Architecture}
34
+ * {file:docs/Parser.md}
35
+ * {file:docs/Handlers.md}
36
+ * {file:docs/CodeObjects.md}
37
+ * {file:docs/Tags.md}
37
38
 
38
39
  The parser component reads source files and converts it into a set of statements
39
40
  which the handlers then process, creating code objects which in turn create tags
@@ -41,8 +42,8 @@ which the handlers then process, creating code objects which in turn create tags
41
42
  the data store component.
42
43
 
43
44
  <a name="storage"></a>
44
- Data Storage Component
45
- ----------------------
45
+
46
+ ## Data Storage Component
46
47
 
47
48
  This component is currently implemented as a simple Ruby marshalled flat namespace
48
49
  of object. The implementation is found in the single class {YARD::Registry}, which
@@ -51,10 +52,10 @@ are future plans to improve this storage mechanism to be backend agnostic and al
51
52
  for more robust storage.
52
53
 
53
54
  <a name="templates"></a>
54
- Post Processing & Templating System
55
- -----------------------------------
55
+
56
+ ## Post Processing & Templating System
56
57
 
57
58
  This component handles processing of objects from the registry through a templating
58
59
  engine that allows output to a variety of formats. Practically speaking, this is
59
60
  where templates can be implemented to change the design, output or structure of
60
- the data. See {file:docs/Templates.md Templates Architecture} for a complete overview.
61
+ the data. See {file:docs/Templates.md Templates Architecture} for a complete overview.
data/docs/Parser.md CHANGED
@@ -1,5 +1,6 @@
1
- Parser Architecture
2
- ===================
1
+ # @title Parser Architecture
2
+
3
+ # Parser Architecture
3
4
 
4
5
  The parser component of YARD is the first component in the data processing pipeline
5
6
  that runs before any handling is done on the source. The parser is meant to translate
@@ -13,8 +14,7 @@ system below:
13
14
 
14
15
  (Note: the RubyToken classes are omitted from the diagram)
15
16
 
16
- SourceParser
17
- ------------
17
+ ## SourceParser
18
18
 
19
19
  The main class {YARD::Parser::SourceParser} acts as a factory class, instantiating
20
20
  the correct parser class, an implementation of {YARD::Parser::Base}. The selected parser
@@ -28,8 +28,7 @@ the individual parser classes since it initiates the pipeline that runs the
28
28
  handlers on the parsed source. The parser used must also match the handlers,
29
29
  and this is coordinated by the `SourceParser` class as well.
30
30
 
31
- Using the SourceParser Class
32
- ----------------------------
31
+ ## Using the SourceParser Class
33
32
 
34
33
  The `SourceParser` class API is optimized for parsing globs of files. As such,
35
34
  the main method to use the class is the `parse` class method, which takes an
@@ -56,8 +55,7 @@ You can also provide the parser type explicitly as the second argument:
56
55
  Note that these two methods are aliased as {YARD.parse} and {YARD.parse_string} for
57
56
  convenience.
58
57
 
59
- Implementing and Registering a Custom Parser
60
- --------------------------------------------
58
+ ## Implementing and Registering a Custom Parser
61
59
 
62
60
  To implement a custom parser, subclass {YARD::Parser::Base}. Documentation on which
63
61
  abstract methods should be implemented are documented in that class. After the class
@@ -72,8 +70,7 @@ The last argument can be a single extension, a list of extensions (Array), a sin
72
70
  list of Regexps. Do not include the '.' in the extension.
73
71
 
74
72
 
75
- The Two Ruby Parser Types
76
- -------------------------
73
+ ## The Two Ruby Parser Types
77
74
 
78
75
  When parsing Ruby, the SourceParser can either instantiate the new {YARD::Parser::Ruby::RubyParser}
79
76
  class or the {YARD::Parser::Ruby::Legacy::StatementList} class. The first of the
@@ -83,8 +80,7 @@ compatibility is required. The choice of parser will affect which handlers
83
80
  ultimately get used, since new handlers can only use the new parser and the
84
81
  same requirement applies to the legacy parser & handlers.
85
82
 
86
- Switching to Legacy Parser
87
- --------------------------
83
+ ## Switching to Legacy Parser
88
84
 
89
85
  By default, running YARD under Ruby 1.9 will automatically select the new parser
90
86
  and new handlers by extension. Although YARD supports both handler styles, plugins
@@ -98,8 +94,7 @@ The default value is `:ruby`. Note that this cannot be forced the other way arou
98
94
  a parser type of `:ruby` cannot be set under Ruby 1.8.x as the new parser is not
99
95
  supported under 1.8.
100
96
 
101
- RubyParser (the New Parser)
102
- ===========================
97
+ ## RubyParser (the New Parser)
103
98
 
104
99
  The new Ruby parser uses the Ripper library that is packaged as part of stdlib
105
100
  in Ruby 1.9. Because of this, it can generate an AST from a string of Ruby input
@@ -107,8 +102,7 @@ that is similar to the style of other sexp libraries (such as ParseTree). Each
107
102
  node generated in the tree is of the base type {YARD::Parser::Ruby::AstNode},
108
103
  which has some subclasses for common node types.
109
104
 
110
- AstNode Basics
111
- --------------
105
+ ### AstNode Basics
112
106
 
113
107
  The `AstNode` class behaves like a standard Array class in which all of its data
114
108
  make up the list of elements in the array. Unlike other sexp style libraries, however,
@@ -131,8 +125,7 @@ the sexp declared above, we can do:
131
125
 
132
126
  node.children #=> [s(:int, "1"), s(:var_ref, s(:ident, "hello"))]
133
127
 
134
- AstNode#source and #line
135
- ------------------------
128
+ ### AstNode#source and #line
136
129
 
137
130
  Every node defines the `#source` method which returns the source code that the
138
131
  node represents. One of the most common things to do with a node is to grab its
@@ -157,8 +150,7 @@ We can also get the line and line ranges in a similar fashion:
157
150
  ast[0].line #=> 1
158
151
  ast[0].line_range #=> 1..3 (note the newlines in the source)
159
152
 
160
- AstNode#jump
161
- ------------
153
+ ### AstNode#jump
162
154
 
163
155
  Often the AST will be such that the node we care about might be buried arbitrarily
164
156
  deep in a node's hierarchy. The {YARD::Parser::Ruby::AstNode#jump} method exists
@@ -171,8 +163,7 @@ to quickly get at a node of a specific type in such a situation:
171
163
  Multiple types can be searched for at once. If none are found, the original root
172
164
  node is returned so that it may be chained.
173
165
 
174
- The Legacy Parser
175
- =================
166
+ ## The Legacy Parser
176
167
 
177
168
  The goal of the legacy parser is much the same as the new parser, but it is far
178
169
  more simplistic. Instead of a full-blown AST, the legacy parser simply groups
data/docs/Tags.md CHANGED
@@ -1,5 +1,6 @@
1
- Tags Overview
2
- =============
1
+ # @title Tags Overview
2
+
3
+ # Tags Overview
3
4
 
4
5
  Tags represent the metadata that can be added to documentation through the `@tag`
5
6
  style syntax:
@@ -15,8 +16,7 @@ way to access it later without having to parse the entire comment string. The
15
16
  rest of the document will describe the tag syntax, how to access the tag
16
17
  metadata and how to extend YARD to support custom tags or override existing tags.
17
18
 
18
- Tag Syntax
19
- ----------
19
+ ## Tag Syntax
20
20
 
21
21
  Tags begin with "@tagname" at the start of a comment line. Tags can span multiple
22
22
  lines if the subsequent lines are indented by more than one space. The following
@@ -87,8 +87,8 @@ As mentioned, types are optional, so the following is also valid:
87
87
 
88
88
 
89
89
  <a name="taglist"></a>
90
- List of Available Tags
91
- ----------------------
90
+
91
+ ## List of Available Tags
92
92
 
93
93
  YARD supplies the following built-in tags:
94
94
 
@@ -122,6 +122,12 @@ YARD supplies the following built-in tags:
122
122
 
123
123
  @attr_writer [Types] name description of writeonly attribute
124
124
 
125
+ * `@attribute`: Recognizes a DSL class method as an attribute with the given
126
+ name. Also accepts the r, w, or rw flag to signify that the attribute is
127
+ readonly, writeonly, or readwrite (default). Only used with DSL methods.
128
+
129
+ @attribute [rw|r|w] NAME
130
+
125
131
  * `@author`: List the author(s) of a class/method
126
132
 
127
133
  @author Full Name
@@ -137,6 +143,17 @@ YARD supplies the following built-in tags:
137
143
  @example Reverse a string
138
144
  "mystring".reverse #=> "gnirtsym"
139
145
 
146
+ * `@macro`: Registers or expands a new macro. See the [Macros](#macros)
147
+ section for more details. Note that the name parameter is never optional.
148
+
149
+ @macro [new|attached] macro_name
150
+ The macro contents to expand
151
+
152
+ * `@method`: Recognizes a DSL class method as a method with the given name
153
+ and optional signature. Only used with DSL methods.
154
+
155
+ @method method_signature(opts = {}, &block)
156
+
140
157
  * `@note`: Creates an emphasized note for the users to read about the
141
158
  object.
142
159
 
@@ -191,6 +208,11 @@ YARD supplies the following built-in tags:
191
208
  * `@return`: Describes return value of method
192
209
 
193
210
  @return [optional, types, ...] description
211
+
212
+ * `@scope`: Sets the scope of a DSL method. Only applicable to DSL method
213
+ calls. Acceptable values are 'class' or 'instance'
214
+
215
+ @scope class|instance
194
216
 
195
217
  * `@see`: "See Also" references for an object. Accepts URLs or
196
218
  other code objects with an optional description at the end.
@@ -213,6 +235,11 @@ YARD supplies the following built-in tags:
213
235
 
214
236
  @version 1.0
215
237
 
238
+ * `@visibility`: Sets the visibility of a DSL method. Only applicable to
239
+ DSL method calls. Acceptable values are public, protected, or private.
240
+
241
+ @visibility public|protected|private
242
+
216
243
  * `@yield`: Describes the block. Use types to list the parameter
217
244
  names the block yields.
218
245
 
@@ -229,8 +256,8 @@ YARD supplies the following built-in tags:
229
256
 
230
257
 
231
258
  <a name="reftags"></a>
232
- Reference Tags
233
- --------------
259
+
260
+ ## Reference Tags
234
261
 
235
262
  Although attempt is made in YARD to leave as many of the syntax details as
236
263
  possible to the factory provider, there is a special tag syntax for referencing
@@ -268,11 +295,179 @@ method only references one of the tags by adding `username` before the reference
268
295
  Reference tags are represented by the {YARD::Tags::RefTag} class and are created
269
296
  directly during parsing by {YARD::Docstring}.
270
297
 
271
- Programmatic API
272
- ================
298
+ <a name="macros"></a>
299
+
300
+ ## Macros
301
+
302
+ Macros enable the documenter to write repetitive documentation once and then
303
+ re-apply it to other objects. Macros are defined on docstrings using the
304
+ `@macro` tag. The same `@macro` tag is used to expand them. The following
305
+ is an example of a simple macro declaration and expansion:
306
+
307
+ # @macro [new] string_attr
308
+ # @return [String] the attribute +$1+ as a String
309
+ attr_accessor :foo
310
+
311
+ # @macro string_attr
312
+ attr_accessor :bar
313
+
314
+ In the above example, both attributes `foo` and `bar` will get the docstring
315
+ that includes a return tag "the attribute as a String". It would be equivalent
316
+ to writing the following:
317
+
318
+ # @return [String] the attribute +foo+ as a String
319
+ attr_accessor :foo
320
+
321
+ # @return [String] the attribute +bar+ as a String
322
+ attr_accessor :bar
323
+
324
+ ### Creating a Macro
325
+
326
+ If the macro does not already exist, it will be created if:
327
+
328
+ 1. there are interpolation variables (`$1`, `$2`, `${3-5}`, etc.) in the
329
+ docstring, or,
330
+ 2. the macro is specified with the `[new]` or `[attached]` flag.
331
+
332
+ For instance, creating a new macro might look like (see the section on
333
+ interpolation below for a description of the `$2` syntax):
334
+
335
+ # @macro the_macro_name
336
+ # @return [$2] the thing to return
337
+ typed_attribute :foo, String
338
+
339
+ Or:
340
+
341
+ # @macro [new] the_macro_name
342
+ # Returns a string!
343
+ def foo; end
344
+
345
+ You can also "attach" a macro to a method if it is in the class scope. In
346
+ this case, you do not need to also provide the 'new' flag, using 'attach'
347
+ is sufficient:
348
+
349
+ # @macro [attach] the_macro_name
350
+ # @return [String] the string value
351
+ def self.foo; end
352
+
353
+ Any time 'foo' is called in the class scope of an inheriting class, the macro
354
+ will automatically expand on that method call (potentially creating a new
355
+ method object). Attaching macros is discussed below.
356
+
357
+ Note that the name is never optional. Even if the macro is never re-used,
358
+ it must be named.
359
+
360
+ ### Indenting the Macro Data
361
+
362
+ If a macro tag has an indented body of macro data (shown below), it will be
363
+ the only portion of the docstring saved for re-use.
364
+
365
+ # @macro [new] macro_name
366
+ # The macro data is here.
367
+ # This data is only used for the current object
368
+ def method; end
369
+
370
+ In the above case, "The macro data is here." is the only portion that will be
371
+ re-used if the macro is called again on another object. However, for the case
372
+ of the above method, both the macro data and the local docstring will be
373
+ applied to the method, creating the docstring:
374
+
375
+ # The macro data is here.
376
+ # This data is only used for the current object.
377
+ def method; end
378
+
379
+ You can therefore keep portions of docstrings local to objects even when
380
+ creating a macro, by indenting the portion of the data that should be re-
381
+ expanded, and listing the local docstring data above or below.
382
+
383
+ If there is no indented macro data, the entire docstring is saved as the
384
+ macro data. For instance,
385
+
386
+ # @macro [new] macro_name
387
+ # The macro data is here.
388
+ # This data is also used for all macros.
389
+ def method; end
390
+
391
+ In the above case, the macro 'macro_name' will always show both lines of text
392
+ when expanded on other objects.
393
+
394
+ ### Attaching a Macro to a DSL (Class) Method
395
+
396
+ Macros can be created on class level methods (or class level method calls) in
397
+ order to implicitly expand a macro whenever that method is subsequently called
398
+ in a class, or any class that mixes in or inherits the method. These macros
399
+ are called "attached" and are declared with the `[attach]` flag. For instance,
400
+ a library that uses a class level method call `property` in its codebase can
401
+ document these declarations in any future call like so:
402
+
403
+ class Resource
404
+ # Defines a new property
405
+ # @param [String] name the property name
406
+ # @param [Class] type the property's type
407
+ # @macro [attach] property
408
+ # @return [$2] the $1 property
409
+ def self.property(name, type) end
410
+ end
411
+
412
+ class Post < Resource
413
+ property :title, String
414
+ property :view_count, Integer
415
+ end
416
+
417
+ If you cannot declare the macro on the actual method declaration, you can
418
+ arbitrarily attach the macro to any method call. Suppose we only had the
419
+ Post class in our codebase, we could add the macro to the first usage of
420
+ the `property` call:
421
+
422
+ class Post < Resource
423
+ # @macro [attach] property
424
+ # @return [$2] the $1 property
425
+ property :title, String
426
+ property :view_count, Integer
427
+ end
428
+
429
+ ### Macro Variable Interpolation Syntax
430
+
431
+ The interpolation syntax is similar to Ruby's regular expression variable syntax.
432
+ It uses $1, $2, $3, ..., referring to the Nth argument in the method call. Using
433
+ the above property example, $1 would be 'title', and $2 would be 'String'.
434
+ $0 is a special variable that refers to the method call itself, in this case
435
+ 'property'. Finally, there is a $& variable which refers to the full line,
436
+ or 'property :title, String'.
437
+
438
+ #### Ranges
439
+
440
+ Ranges are also acceptable with the syntax `${N-M}`. Negative values on either
441
+ N or M are valid, and refer to indexes from the end of the list. Consider
442
+ a DSL method that creates a method using the first argument with argument
443
+ names following, ending with the return type of the method. This could be
444
+ documented as:
445
+
446
+ # @macro dsl_method
447
+ # @method $1(${2--2})
448
+ # @return [${-1}] the return value of $0
449
+ create_method_with_args :foo, :a, :b, :c, String
450
+
451
+ As described, the method is using the signature `foo(a, b, c)` and the return
452
+ type from the last argument, `String`. When using ranges, tokens are joined
453
+ with commas. Note that this includes using $0:
454
+
455
+ $0-1 # => Interpolates to "create_method_with_args, foo"
456
+
457
+ If you want to separate them with spaces, use `$1 $2 $3 $4 ...`. Note that
458
+ if the token cannot be expanded, it will return the empty string (not an error),
459
+ so it would be safe to list `$1 $2 ... $10`, for example.
460
+
461
+ #### Escaping Interpolation
462
+
463
+ Interpolation can be escaped by prefixing the `$` with `\`, like so:
464
+
465
+ # @macro foo
466
+ # I have \$2.00 USD.
467
+
468
+ ## Programmatic API
273
469
 
274
- Accessing Tag Information
275
- -------------------------
470
+ ### Accessing Tag Information
276
471
 
277
472
  Tag metadata is added when a {YARD::Docstring} is added to a {file:docs/CodeObjects.md code object}
278
473
  using the {YARD::CodeObjects::Base#docstring=} attribute. In addition to adding
@@ -288,8 +483,7 @@ of tags. The `#tag` method is an alias for the first item in the list of tags.
288
483
  Also note that the `#tag`, `#tags` and `#has_tag?` methods are all convenience
289
484
  methods that delegate to the {YARD::Docstring} object described above.
290
485
 
291
- Adding Custom Tags
292
- ------------------
486
+ ### Adding Custom Tags
293
487
 
294
488
  The `@tagname` tag used in the above examples is clearly not part of the tags
295
489
  that come with YARD. If such a tag would actually be part of documentation under
@@ -304,8 +498,7 @@ tag that stores simple text like our `@tagname` tag above, use:
304
498
 
305
499
  This will now allow YARD to add the metadata from `@tagname` to the docstring.
306
500
 
307
- Tag Factory Architecture
308
- ------------------------
501
+ ## Tag Factory Architecture
309
502
 
310
503
  Recognizing a tag is one part of the process. Parsing the tag contents is the
311
504
  second step. YARD has a tag architecture that allows developers to add or completely