yard 0.7.5 → 0.8.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 (339) hide show
  1. data/.yardopts +10 -2
  2. data/ChangeLog +1263 -38
  3. data/LEGAL +5 -5
  4. data/LICENSE +1 -1
  5. data/README.md +91 -82
  6. data/Rakefile +6 -6
  7. data/benchmarks/builtins_vs_eval.rb +1 -1
  8. data/benchmarks/erb_vs_erubis.rb +4 -4
  9. data/benchmarks/generation.rb +5 -5
  10. data/benchmarks/parsing.rb +2 -2
  11. data/benchmarks/registry_store_types.rb +48 -0
  12. data/bin/yard +9 -1
  13. data/bin/yardoc +9 -1
  14. data/bin/yri +10 -2
  15. data/docs/CodeObjects.md +10 -10
  16. data/docs/GettingStarted.md +85 -83
  17. data/docs/Handlers.md +21 -21
  18. data/docs/Overview.md +7 -7
  19. data/docs/Parser.md +30 -30
  20. data/docs/Tags.md +250 -554
  21. data/docs/TagsArch.md +123 -0
  22. data/docs/Templates.md +58 -80
  23. data/docs/WhatsNew.md +378 -133
  24. data/docs/templates/default/fulldoc/html/full_list_tag.erb +7 -0
  25. data/docs/templates/default/fulldoc/html/setup.rb +6 -0
  26. data/docs/templates/default/layout/html/setup.rb +8 -0
  27. data/docs/templates/default/layout/html/tag_list.erb +11 -0
  28. data/docs/templates/default/yard_tags/html/list.erb +18 -0
  29. data/docs/templates/default/yard_tags/html/setup.rb +27 -0
  30. data/docs/templates/plugin.rb +65 -0
  31. data/lib/yard.rb +1 -10
  32. data/lib/yard/autoload.rb +75 -27
  33. data/lib/yard/cli/command.rb +5 -2
  34. data/lib/yard/cli/command_parser.rb +3 -2
  35. data/lib/yard/cli/diff.rb +1 -1
  36. data/lib/yard/cli/i18n.rb +69 -0
  37. data/lib/yard/cli/list.rb +1 -1
  38. data/lib/yard/cli/server.rb +30 -7
  39. data/lib/yard/cli/stats.rb +5 -6
  40. data/lib/yard/cli/yardoc.rb +95 -45
  41. data/lib/yard/cli/yri.rb +24 -3
  42. data/lib/yard/code_objects/base.rb +35 -4
  43. data/lib/yard/code_objects/extra_file_object.rb +1 -1
  44. data/lib/yard/code_objects/macro_object.rb +56 -99
  45. data/lib/yard/code_objects/method_object.rb +44 -6
  46. data/lib/yard/config.rb +18 -8
  47. data/lib/yard/core_ext/symbol_hash.rb +1 -1
  48. data/lib/yard/docstring.rb +45 -85
  49. data/lib/yard/docstring_parser.rb +269 -0
  50. data/lib/yard/handlers/base.rb +129 -118
  51. data/lib/yard/handlers/c/alias_handler.rb +15 -0
  52. data/lib/yard/handlers/c/attribute_handler.rb +13 -0
  53. data/lib/yard/handlers/c/base.rb +110 -0
  54. data/lib/yard/handlers/c/class_handler.rb +26 -0
  55. data/lib/yard/handlers/c/constant_handler.rb +12 -0
  56. data/lib/yard/handlers/c/handler_methods.rb +165 -0
  57. data/lib/yard/handlers/c/init_handler.rb +16 -0
  58. data/lib/yard/handlers/c/method_handler.rb +35 -0
  59. data/lib/yard/handlers/c/mixin_handler.rb +13 -0
  60. data/lib/yard/handlers/c/module_handler.rb +16 -0
  61. data/lib/yard/handlers/c/override_comment_handler.rb +22 -0
  62. data/lib/yard/handlers/c/path_handler.rb +10 -0
  63. data/lib/yard/handlers/c/struct_handler.rb +12 -0
  64. data/lib/yard/handlers/c/symbol_handler.rb +7 -0
  65. data/lib/yard/handlers/processor.rb +41 -30
  66. data/lib/yard/handlers/ruby/alias_handler.rb +0 -2
  67. data/lib/yard/handlers/ruby/attribute_handler.rb +16 -17
  68. data/lib/yard/handlers/ruby/base.rb +10 -6
  69. data/lib/yard/handlers/ruby/comment_handler.rb +9 -0
  70. data/lib/yard/handlers/ruby/dsl_handler.rb +14 -0
  71. data/lib/yard/handlers/ruby/dsl_handler_methods.rb +71 -0
  72. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +0 -3
  73. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +16 -17
  74. data/lib/yard/handlers/ruby/legacy/base.rb +28 -6
  75. data/lib/yard/handlers/ruby/legacy/comment_handler.rb +9 -0
  76. data/lib/yard/handlers/ruby/legacy/dsl_handler.rb +16 -0
  77. data/lib/yard/handlers/ruby/legacy/method_handler.rb +0 -2
  78. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +1 -1
  79. data/lib/yard/handlers/ruby/legacy/module_function_handler.rb +18 -0
  80. data/lib/yard/handlers/ruby/method_handler.rb +10 -15
  81. data/lib/yard/handlers/ruby/mixin_handler.rb +1 -1
  82. data/lib/yard/handlers/ruby/module_function_handler.rb +26 -0
  83. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -2
  84. data/lib/yard/i18n/pot_generator.rb +281 -0
  85. data/lib/yard/i18n/text.rb +72 -0
  86. data/lib/yard/logging.rb +3 -7
  87. data/lib/yard/options.rb +216 -0
  88. data/lib/yard/parser/c/c_parser.rb +225 -0
  89. data/lib/yard/parser/c/comment_parser.rb +131 -0
  90. data/lib/yard/parser/c/statement.rb +63 -0
  91. data/lib/yard/parser/ruby/ast_node.rb +91 -1
  92. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  93. data/lib/yard/parser/ruby/legacy/statement.rb +7 -2
  94. data/lib/yard/parser/ruby/legacy/statement_list.rb +13 -22
  95. data/lib/yard/parser/ruby/ruby_parser.rb +87 -26
  96. data/lib/yard/parser/source_parser.rb +89 -88
  97. data/lib/yard/rake/yardoc_task.rb +1 -1
  98. data/lib/yard/registry.rb +21 -10
  99. data/lib/yard/registry_store.rb +48 -0
  100. data/lib/yard/serializers/file_system_serializer.rb +18 -20
  101. data/lib/yard/serializers/yardoc_serializer.rb +1 -0
  102. data/lib/yard/server/adapter.rb +2 -2
  103. data/lib/yard/server/commands/base.rb +1 -1
  104. data/lib/yard/server/commands/display_object_command.rb +13 -6
  105. data/lib/yard/server/commands/frames_command.rb +4 -21
  106. data/lib/yard/server/commands/library_command.rb +57 -11
  107. data/lib/yard/server/commands/list_command.rb +10 -34
  108. data/lib/yard/server/commands/search_command.rb +8 -2
  109. data/lib/yard/server/doc_server_helper.rb +34 -0
  110. data/lib/yard/server/rack_adapter.rb +5 -1
  111. data/lib/yard/server/router.rb +4 -10
  112. data/lib/yard/server/static_caching.rb +2 -2
  113. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +2 -2
  114. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +0 -15
  115. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +3 -3
  116. data/lib/yard/server/templates/default/layout/html/script_setup.erb +8 -0
  117. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  118. data/lib/yard/server/templates/doc_server/search/html/setup.rb +1 -1
  119. data/lib/yard/tags/default_factory.rb +31 -4
  120. data/lib/yard/tags/directives.rb +593 -0
  121. data/lib/yard/tags/library.rb +437 -35
  122. data/lib/yard/templates/engine.rb +17 -12
  123. data/lib/yard/templates/helpers/base_helper.rb +8 -2
  124. data/lib/yard/templates/helpers/html_helper.rb +57 -14
  125. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +1 -1
  126. data/lib/yard/templates/helpers/markup_helper.rb +9 -9
  127. data/lib/yard/templates/helpers/text_helper.rb +2 -2
  128. data/lib/yard/templates/template.rb +42 -13
  129. data/lib/yard/templates/template_options.rb +81 -0
  130. data/spec/cli/command_parser_spec.rb +4 -4
  131. data/spec/cli/command_spec.rb +3 -3
  132. data/spec/cli/config_spec.rb +13 -13
  133. data/spec/cli/diff_spec.rb +13 -10
  134. data/spec/cli/gems_spec.rb +12 -12
  135. data/spec/cli/help_spec.rb +2 -2
  136. data/spec/cli/i18n_spec.rb +111 -0
  137. data/spec/cli/server_spec.rb +66 -18
  138. data/spec/cli/stats_spec.rb +15 -15
  139. data/spec/cli/yardoc_spec.rb +124 -97
  140. data/spec/cli/yri_spec.rb +14 -12
  141. data/spec/code_objects/base_spec.rb +104 -46
  142. data/spec/code_objects/class_object_spec.rb +33 -33
  143. data/spec/code_objects/code_object_list_spec.rb +5 -5
  144. data/spec/code_objects/constants_spec.rb +4 -3
  145. data/spec/code_objects/extra_file_object_spec.rb +19 -19
  146. data/spec/code_objects/macro_object_spec.rb +31 -37
  147. data/spec/code_objects/method_object_spec.rb +46 -23
  148. data/spec/code_objects/module_object_spec.rb +16 -16
  149. data/spec/code_objects/namespace_object_spec.rb +6 -6
  150. data/spec/code_objects/proxy_spec.rb +19 -19
  151. data/spec/config_spec.rb +33 -24
  152. data/spec/core_ext/array_spec.rb +1 -1
  153. data/spec/core_ext/file_spec.rb +8 -8
  154. data/spec/core_ext/hash_spec.rb +1 -1
  155. data/spec/core_ext/insertion_spec.rb +3 -3
  156. data/spec/core_ext/module_spec.rb +1 -1
  157. data/spec/core_ext/string_spec.rb +6 -6
  158. data/spec/core_ext/symbol_hash_spec.rb +11 -11
  159. data/spec/docstring_parser_spec.rb +207 -0
  160. data/spec/docstring_spec.rb +33 -146
  161. data/spec/handlers/alias_handler_spec.rb +14 -14
  162. data/spec/handlers/attribute_handler_spec.rb +20 -20
  163. data/spec/handlers/base_spec.rb +16 -16
  164. data/spec/handlers/c/alias_handler_spec.rb +33 -0
  165. data/spec/handlers/c/attribute_handler_spec.rb +40 -0
  166. data/spec/handlers/c/class_handler_spec.rb +64 -0
  167. data/spec/handlers/c/constant_handler_spec.rb +68 -0
  168. data/spec/handlers/c/init_handler_spec.rb +36 -0
  169. data/spec/handlers/c/method_handler_spec.rb +228 -0
  170. data/spec/handlers/c/mixin_handler_spec.rb +27 -0
  171. data/spec/handlers/c/module_handler_spec.rb +38 -0
  172. data/spec/handlers/c/override_comment_handler_spec.rb +43 -0
  173. data/spec/handlers/c/path_handler_spec.rb +35 -0
  174. data/spec/handlers/c/spec_helper.rb +11 -0
  175. data/spec/handlers/c/struct_handler_spec.rb +15 -0
  176. data/spec/handlers/class_condition_handler_spec.rb +10 -10
  177. data/spec/handlers/class_handler_spec.rb +38 -38
  178. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  179. data/spec/handlers/constant_handler_spec.rb +7 -7
  180. data/spec/handlers/{macro_handler_spec.rb → dsl_handler_spec.rb} +72 -53
  181. data/spec/handlers/examples/alias_handler_001.rb.txt +5 -5
  182. data/spec/handlers/examples/class_condition_handler_001.rb.txt +9 -9
  183. data/spec/handlers/examples/class_handler_001.rb.txt +1 -1
  184. data/spec/handlers/examples/dsl_handler_001.rb.txt +110 -0
  185. data/spec/handlers/examples/exception_handler_001.rb.txt +14 -14
  186. data/spec/handlers/examples/method_condition_handler_001.rb.txt +2 -2
  187. data/spec/handlers/examples/method_handler_001.rb.txt +16 -16
  188. data/spec/handlers/examples/mixin_handler_001.rb.txt +8 -4
  189. data/spec/handlers/examples/private_constant_handler_001.rb.txt +1 -1
  190. data/spec/handlers/examples/visibility_handler_001.rb.txt +3 -3
  191. data/spec/handlers/examples/yield_handler_001.rb.txt +13 -14
  192. data/spec/handlers/exception_handler_spec.rb +9 -9
  193. data/spec/handlers/extend_handler_spec.rb +2 -2
  194. data/spec/handlers/legacy_base_spec.rb +34 -34
  195. data/spec/handlers/method_condition_handler_spec.rb +2 -2
  196. data/spec/handlers/method_handler_spec.rb +33 -33
  197. data/spec/handlers/mixin_handler_spec.rb +13 -9
  198. data/spec/handlers/module_function_handler_spec.rb +82 -0
  199. data/spec/handlers/module_handler_spec.rb +6 -6
  200. data/spec/handlers/private_constant_handler_spec.rb +3 -3
  201. data/spec/handlers/processor_spec.rb +5 -5
  202. data/spec/handlers/ruby/base_spec.rb +10 -6
  203. data/spec/handlers/ruby/legacy/base_spec.rb +11 -7
  204. data/spec/handlers/spec_helper.rb +2 -3
  205. data/spec/handlers/visibility_handler_spec.rb +6 -6
  206. data/spec/handlers/yield_handler_spec.rb +8 -8
  207. data/spec/i18n/pot_generator_spec.rb +244 -0
  208. data/spec/i18n/text_spec.rb +69 -0
  209. data/spec/options_spec.rb +160 -0
  210. data/spec/parser/base_spec.rb +3 -3
  211. data/spec/parser/c_parser_spec.rb +31 -257
  212. data/spec/parser/examples/array.c.txt +187 -187
  213. data/spec/parser/examples/extrafile.c.txt +1 -1
  214. data/spec/parser/examples/override.c.txt +1 -1
  215. data/spec/parser/ruby/ast_node_spec.rb +1 -1
  216. data/spec/parser/ruby/legacy/statement_list_spec.rb +24 -24
  217. data/spec/parser/ruby/legacy/token_list_spec.rb +7 -7
  218. data/spec/parser/ruby/ruby_parser_spec.rb +56 -34
  219. data/spec/parser/source_parser_spec.rb +125 -65
  220. data/spec/parser/tag_parsing_spec.rb +4 -4
  221. data/spec/rake/yardoc_task_spec.rb +10 -8
  222. data/spec/registry_spec.rb +65 -36
  223. data/spec/registry_store_spec.rb +90 -40
  224. data/spec/serializers/file_system_serializer_spec.rb +12 -12
  225. data/spec/serializers/yardoc_serializer_spec.rb +2 -2
  226. data/spec/server/adapter_spec.rb +3 -3
  227. data/spec/server/commands/base_spec.rb +8 -8
  228. data/spec/server/commands/library_command_spec.rb +3 -3
  229. data/spec/server/commands/static_file_command_spec.rb +7 -7
  230. data/spec/server/doc_server_helper_spec.rb +1 -1
  231. data/spec/server/doc_server_serializer_spec.rb +6 -6
  232. data/spec/server/rack_adapter_spec.rb +3 -3
  233. data/spec/server/router_spec.rb +19 -19
  234. data/spec/server/static_caching_spec.rb +4 -4
  235. data/spec/spec_helper.rb +7 -7
  236. data/spec/tags/default_factory_spec.rb +24 -16
  237. data/spec/tags/directives_spec.rb +422 -0
  238. data/spec/tags/library_spec.rb +15 -4
  239. data/spec/tags/overload_tag_spec.rb +6 -6
  240. data/spec/tags/ref_tag_list_spec.rb +8 -8
  241. data/spec/templates/class_spec.rb +7 -7
  242. data/spec/templates/constant_spec.rb +7 -7
  243. data/spec/templates/engine_spec.rb +28 -36
  244. data/spec/templates/examples/class001.html +108 -108
  245. data/spec/templates/examples/class002.html +17 -17
  246. data/spec/templates/examples/constant001.txt +1 -1
  247. data/spec/templates/examples/method001.html +45 -45
  248. data/spec/templates/examples/method002.html +25 -25
  249. data/spec/templates/examples/method003.html +60 -60
  250. data/spec/templates/examples/method004.html +7 -7
  251. data/spec/templates/examples/method005.html +28 -28
  252. data/spec/templates/examples/module001.html +321 -321
  253. data/spec/templates/examples/module001.txt +1 -1
  254. data/spec/templates/examples/module002.html +130 -130
  255. data/spec/templates/examples/module003.html +74 -74
  256. data/spec/templates/examples/module004.html +388 -0
  257. data/spec/templates/helpers/base_helper_spec.rb +32 -32
  258. data/spec/templates/helpers/html_helper_spec.rb +87 -68
  259. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +9 -9
  260. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +16 -16
  261. data/spec/templates/helpers/markup_helper_spec.rb +31 -28
  262. data/spec/templates/helpers/method_helper_spec.rb +7 -7
  263. data/spec/templates/helpers/shared_signature_examples.rb +9 -7
  264. data/spec/templates/helpers/text_helper_spec.rb +3 -3
  265. data/spec/templates/method_spec.rb +13 -13
  266. data/spec/templates/module_spec.rb +70 -24
  267. data/spec/templates/onefile_spec.rb +32 -15
  268. data/spec/templates/section_spec.rb +23 -23
  269. data/spec/templates/spec_helper.rb +31 -1
  270. data/spec/templates/tag_spec.rb +5 -5
  271. data/spec/templates/template_spec.rb +54 -46
  272. data/spec/verifier_spec.rb +5 -5
  273. data/templates/default/class/setup.rb +2 -2
  274. data/templates/default/docstring/html/abstract.erb +1 -1
  275. data/templates/default/docstring/html/note.erb +1 -1
  276. data/templates/default/docstring/html/private.erb +1 -1
  277. data/templates/default/docstring/html/todo.erb +1 -1
  278. data/templates/default/docstring/setup.rb +2 -2
  279. data/templates/default/fulldoc/html/css/full_list.css +4 -2
  280. data/templates/default/fulldoc/html/css/style.css +50 -44
  281. data/templates/default/fulldoc/html/frames.erb +21 -6
  282. data/templates/default/fulldoc/html/full_list.erb +5 -3
  283. data/templates/default/fulldoc/html/{full_list_files.erb → full_list_file.erb} +0 -0
  284. data/templates/default/fulldoc/html/js/app.js +29 -26
  285. data/templates/default/fulldoc/html/js/full_list.js +9 -9
  286. data/templates/default/fulldoc/html/js/jquery.js +4 -16
  287. data/templates/default/fulldoc/html/setup.rb +42 -38
  288. data/templates/default/layout/dot/header.erb +1 -1
  289. data/templates/default/layout/html/breadcrumb.erb +6 -6
  290. data/templates/default/layout/html/files.erb +1 -1
  291. data/templates/default/layout/html/footer.erb +1 -1
  292. data/templates/default/layout/html/headers.erb +3 -6
  293. data/templates/default/layout/html/index.erb +1 -1
  294. data/templates/default/layout/html/layout.erb +3 -7
  295. data/templates/default/layout/html/objects.erb +1 -1
  296. data/templates/default/layout/html/script_setup.erb +5 -0
  297. data/templates/default/layout/html/search.erb +4 -1
  298. data/templates/default/layout/html/setup.rb +8 -8
  299. data/templates/default/method_details/html/method_signature.erb +10 -3
  300. data/templates/default/method_details/setup.rb +1 -0
  301. data/templates/default/module/dot/info.erb +1 -1
  302. data/templates/default/module/dot/setup.rb +2 -2
  303. data/templates/default/module/html/attribute_details.erb +1 -1
  304. data/templates/default/module/html/children.erb +1 -1
  305. data/templates/default/module/html/defines.erb +1 -1
  306. data/templates/default/module/html/inherited_methods.erb +5 -4
  307. data/templates/default/module/html/item_summary.erb +15 -5
  308. data/templates/default/module/html/method_details_list.erb +2 -2
  309. data/templates/default/module/setup.rb +25 -12
  310. data/templates/default/module/text/setup.rb +1 -1
  311. data/templates/default/onefile/html/layout.erb +1 -1
  312. data/templates/default/onefile/html/setup.rb +2 -2
  313. data/templates/default/tags/html/example.erb +4 -2
  314. data/templates/default/tags/html/option.erb +1 -1
  315. data/templates/default/tags/html/overload.erb +1 -1
  316. data/templates/default/tags/html/see.erb +1 -1
  317. data/templates/default/tags/html/tag.erb +1 -1
  318. data/templates/default/tags/setup.rb +4 -3
  319. data/templates/guide/fulldoc/html/css/style.css +8 -8
  320. data/templates/guide/fulldoc/html/js/app.js +6 -6
  321. data/templates/guide/fulldoc/html/setup.rb +12 -12
  322. data/templates/guide/layout/html/layout.erb +11 -11
  323. data/templates/guide/layout/html/setup.rb +9 -9
  324. data/templates/guide/method/html/header.erb +2 -2
  325. data/templates/guide/method/html/setup.rb +1 -1
  326. metadata +68 -18
  327. data/bin/yard-graph +0 -4
  328. data/bin/yard-server +0 -4
  329. data/docs/Glossary.md +0 -12
  330. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +0 -39
  331. data/lib/yard/handlers/ruby/macro_handler.rb +0 -40
  332. data/lib/yard/handlers/ruby/macro_handler_methods.rb +0 -131
  333. data/lib/yard/parser/c_parser.rb +0 -497
  334. data/lib/yard/server/templates/default/layout/html/headers.erb +0 -16
  335. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +0 -13
  336. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +0 -3
  337. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +0 -34
  338. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +0 -20
  339. data/spec/handlers/examples/macro_handler_001.rb.txt +0 -83
data/docs/Handlers.md CHANGED
@@ -27,8 +27,8 @@ state about what is being processed. For instance, the processor is what keeps
27
27
  track of the current namespace (the module or class an object is being defined
28
28
  in), scope (class or instance), file and owner. The owner refers to the object
29
29
  that is most directly responsible for the source statement being processed. This
30
- is most often the same as the namespace, except when parsing the body of a method,
31
- where the namespace would be the class/module the method is defined in and the
30
+ is most often the same as the namespace, except when parsing the body of a method,
31
+ where the namespace would be the class/module the method is defined in and the
32
32
  owner would be the method object itself.
33
33
 
34
34
  ## Implementing a Handler
@@ -42,13 +42,13 @@ class method. A very simple handler that handles a module definition would be:
42
42
 
43
43
  class MyModuleHandler < YARD::Handlers::Ruby::Base
44
44
  handles :module
45
-
45
+
46
46
  def process
47
47
  puts "Handling a module named #{statement[0].source}"
48
48
  end
49
49
  end
50
-
51
- For details on what nodes are, and what node types are, see the
50
+
51
+ For details on what nodes are, and what node types are, see the
52
52
  {file:docs/Parser.md parser architecture document}.
53
53
 
54
54
  In this case the node type being handled is the `:module` type. More than one
@@ -66,32 +66,32 @@ call can be handled by declaring the following in a `handles` statement:
66
66
 
67
67
  class MyHandler < YARD::Handlers::Ruby::Base
68
68
  handles method_call(:describe)
69
-
69
+
70
70
  def process
71
71
  # Process the method call
72
72
  end
73
73
  end
74
-
75
- In this case we handle any of the method calls to method name `describe` with
74
+
75
+ In this case we handle any of the method calls to method name `describe` with
76
76
  the following syntaxes:
77
-
77
+
78
78
  describe(something)
79
79
  describe arg1, arg2, arg3
80
80
  describe(something) { perform_a_block }
81
81
  describe "Something" do
82
82
  a_block
83
83
  end
84
-
84
+
85
85
  ### Creating a new Code Object
86
86
 
87
87
  Usually (but not always) handling is performed to create new code objects to add
88
88
  to the registry (for information about code objects, see {file:docs/CodeObjects.md this document}).
89
89
  Code objects should simply be created and added to the existing `namespace`. This
90
- will be enough to add them to the registry. There is also a convenience
90
+ will be enough to add them to the registry. There is also a convenience
91
91
  {YARD::Handlers::Base#register register} method which quickly sets standard attributed
92
92
  on the newly created object, such as the file, line, source and docstring of the
93
93
  object. This method will be seen in the next example.
94
-
94
+
95
95
  ### Handling an Inner Block
96
96
 
97
97
  By default, the parser gives the processor class a list of all the top level
@@ -107,7 +107,7 @@ the following commands:
107
107
 
108
108
  class YARD::Handlers::Ruby::ModuleHandler < YARD::Handlers::Ruby::Base
109
109
  handles :module
110
-
110
+
111
111
  def process
112
112
  modname = statement[0].source
113
113
  mod = register ModuleObject.new(namespace, modname)
@@ -126,27 +126,27 @@ Because the legacy handler uses the legacy parser and therefore a different kind
126
126
  of AST, there are subtle differences in the handler API. Most importantly, the
127
127
  `handles` method usually deals with either lexical tokens or source code as a string
128
128
  or RegExp object. The statement object, similarly, is made up of lexical tokens instead
129
- of semantically parsed nodes (this is described in the {file:docs/Parser.md parser document}).
129
+ of semantically parsed nodes (this is described in the {file:docs/Parser.md parser document}).
130
130
 
131
131
  The module example above can be rewritten as a legacy handler as follows:
132
132
 
133
133
  class YARD::Handlers::Ruby::Legacy::ModuleHandler < YARD::Handlers::Ruby::Legacy::Base
134
134
  handles TkMODULE
135
-
135
+
136
136
  def process
137
137
  modname = statement.tokens.to_s[/^module\s+(#{NAMESPACEMATCH})/, 1]
138
138
  mod = register ModuleObject.new(namespace, modname)
139
139
  parse_block(:namespace => mod)
140
140
  end
141
141
  end
142
-
142
+
143
143
  A few notes on the differences:
144
144
 
145
145
  * We inherit from `Legacy::Base` instead of the standard Ruby Base handler class.
146
146
  * We exchange node type `:module` for `TkMODULE`, which represents the
147
- first token in the statement.
148
- * We perform direct string manipulation to get the module name.
149
- * `parse_block` does not take a list of statements. In the old parser API,
150
- each statement has a `block` attribute which defines the list of
151
- statements within that statement, if any. Therefore, `parse_block` will
147
+ first token in the statement.
148
+ * We perform direct string manipulation to get the module name.
149
+ * `parse_block` does not take a list of statements. In the old parser API,
150
+ each statement has a `block` attribute which defines the list of
151
+ statements within that statement, if any. Therefore, `parse_block` will
152
152
  always parse the `statement.block` if it exists.
data/docs/Overview.md CHANGED
@@ -11,14 +11,14 @@ that tools like RDoc do not do. These components are:
11
11
  * [Data Storage Component](#storage)
12
12
  * [Post Processing & Templating System](#templates)
13
13
 
14
- This separation is a major goal of the project, and means that YARD is not *just*
15
- a tool to generate HTML output. The expectation is that any subset of YARD's
16
- major components may be used, extended or modified independently. YARD may be
17
- used just as a data gathering tool (to parse and audit code), just as a data
18
- source (a webserver containing raw unformatted data about code), or just as a
14
+ This separation is a major goal of the project, and means that YARD is not *just*
15
+ a tool to generate HTML output. The expectation is that any subset of YARD's
16
+ major components may be used, extended or modified independently. YARD may be
17
+ used just as a data gathering tool (to parse and audit code), just as a data
18
+ source (a webserver containing raw unformatted data about code), or just as a
19
19
  conventional HTML documentation generation tool (like RDoc).
20
20
 
21
- The important classes and dependencies of these components are shown in the
21
+ The important classes and dependencies of these components are shown in the
22
22
  following class diagram:
23
23
 
24
24
  ![Overview Class Diagram](images/overview-class-diagram.png)
@@ -37,7 +37,7 @@ tasks during the data gathering process (*note: the tag architecture is not*
37
37
  * {file:docs/Tags.md}
38
38
 
39
39
  The parser component reads source files and converts it into a set of statements
40
- which the handlers then process, creating code objects which in turn create tags
40
+ which the handlers then process, creating code objects which in turn create tags
41
41
  (meta-data) attached to the objects. These objects are all added to the {YARD::Registry},
42
42
  the data store component.
43
43
 
data/docs/Parser.md CHANGED
@@ -7,7 +7,7 @@ that runs before any handling is done on the source. The parser is meant to tran
7
7
  the source into a set of statements that can be understood by the {file:docs/Handlers.md Handlers}
8
8
  that run immediately afterwards.
9
9
 
10
- The important classes are described in the class diagram of the entire parser
10
+ The important classes are described in the class diagram of the entire parser
11
11
  system below:
12
12
 
13
13
  ![Parser Class Diagram](images/parser-class-diagram.png)
@@ -23,7 +23,7 @@ to parsing methods). YARD supports Ruby and C source files, but custom parsers c
23
23
  be implemented and registered for various other languages by subclassing `Parser::Base`
24
24
  and registering the parser with {YARD::Parser::SourceParser.register_parser_type}.
25
25
 
26
- This factory class should always be used when parsing source files rather than
26
+ This factory class should always be used when parsing source files rather than
27
27
  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.
@@ -36,36 +36,36 @@ array of file globs or a single file glob.
36
36
 
37
37
  YARD::Parser::SourceParser.parse('spec_*.rb')
38
38
  YARD::Parser::SourceParser.parse(['spec_*.rb', '*_helper.rb'])
39
-
39
+
40
40
  This is equivalent to the convenience method {YARD.parse}:
41
41
 
42
42
  YARD.parse('lib/**/*.rb')
43
-
43
+
44
44
  In some cases (ie. for testing), it may be more helpful to parse a string of input
45
45
  directly. In such a case, the method {YARD::Parser::SourceParser.parse_string} should be
46
46
  used:
47
47
 
48
48
  YARD::Parser::SourceParser.parse_string("def method(a, b) end")
49
-
49
+
50
50
  You can also provide the parser type explicitly as the second argument:
51
51
 
52
52
  # Parses a string of C
53
53
  YARD::Parser::SourceParser.parse_string("int main() { }", :c)
54
-
55
- Note that these two methods are aliased as {YARD.parse} and {YARD.parse_string} for
54
+
55
+ Note that these two methods are aliased as {YARD.parse} and {YARD.parse_string} for
56
56
  convenience.
57
-
57
+
58
58
  ## Implementing and Registering a Custom Parser
59
59
 
60
60
  To implement a custom parser, subclass {YARD::Parser::Base}. Documentation on which
61
61
  abstract methods should be implemented are documented in that class. After the class
62
62
  is implemented, it is registered with the {YARD::Parser::SourceParser} factory class
63
63
  to be called when a file of the right extension needs to be parsed, or when a user
64
- selects that parser type explicitly. To register your new parser class, call the
64
+ selects that parser type explicitly. To register your new parser class, call the
65
65
  method {YARD::Parser::SourceParser.register_parser_type}:
66
66
 
67
67
  SourceParser.register_parser_type(:my_parser, MyParser, 'my_parser_ext')
68
-
68
+
69
69
  The last argument can be a single extension, a list of extensions (Array), a single Regexp, or a
70
70
  list of Regexps. Do not include the '.' in the extension.
71
71
 
@@ -73,11 +73,11 @@ list of Regexps. Do not include the '.' in the extension.
73
73
  ## The Two Ruby Parser Types
74
74
 
75
75
  When parsing Ruby, the SourceParser can either instantiate the new {YARD::Parser::Ruby::RubyParser}
76
- class or the {YARD::Parser::Ruby::Legacy::StatementList} class. The first of the
77
- two, although faster, more robust and more efficient, is only available for
78
- Ruby 1.9. The legacy parser parser is available in both 1.8.x and 1.9, if
79
- compatibility is required. The choice of parser will affect which handlers
80
- ultimately get used, since new handlers can only use the new parser and the
76
+ class or the {YARD::Parser::Ruby::Legacy::StatementList} class. The first of the
77
+ two, although faster, more robust and more efficient, is only available for
78
+ Ruby 1.9. The legacy parser parser is available in both 1.8.x and 1.9, if
79
+ compatibility is required. The choice of parser will affect which handlers
80
+ ultimately get used, since new handlers can only use the new parser and the
81
81
  same requirement applies to the legacy parser & handlers.
82
82
 
83
83
  ## Switching to Legacy Parser
@@ -89,7 +89,7 @@ only the legacy handlers are implemented, the `SourceParser` class should force
89
89
  the use of the legacy parser by setting the `parser_type` attribute as such:
90
90
 
91
91
  YARD::Parser::SourceParser.parser_type = :ruby18
92
-
92
+
93
93
  The default value is `:ruby`. Note that this cannot be forced the other way around,
94
94
  a parser type of `:ruby` cannot be set under Ruby 1.8.x as the new parser is not
95
95
  supported under 1.8.
@@ -114,12 +114,12 @@ by the `#type` method. The following examples show some of the basic uses of `As
114
114
  node.type #=> :if_mod
115
115
  node[0] #=> s(:int, "1")
116
116
  node[0][0] #=> "1"
117
-
117
+
118
118
  (Note the `s()` syntax is shorthand for `AstNode.new(...)`. `s()` with no type
119
119
  is shorthand for a node of type `:list`)
120
120
 
121
- As shown, not all of the elements are AstNodes in themselves, some are String
122
- objects containing values. A list of only the AstNodes within a node can be
121
+ As shown, not all of the elements are AstNodes in themselves, some are String
122
+ objects containing values. A list of only the AstNodes within a node can be
123
123
  accessed via the {YARD::Parser::Ruby::AstNode#children #children} method. Using
124
124
  the sexp declared above, we can do:
125
125
 
@@ -127,23 +127,23 @@ the sexp declared above, we can do:
127
127
 
128
128
  ### AstNode#source and #line
129
129
 
130
- Every node defines the `#source` method which returns the source code that the
131
- node represents. One of the most common things to do with a node is to grab its
130
+ Every node defines the `#source` method which returns the source code that the
131
+ node represents. One of the most common things to do with a node is to grab its
132
132
  source. The following example shows how this can be done:
133
133
 
134
134
  source = "if 1 == 1 then\n raise Exception\n end"
135
135
  ast = YARD::Parser::Ruby::RubyParser.parse(source).root
136
136
  ast[0].condition.source #=> "1 == 1"
137
137
  ast[0].then_block.source #=> "raise Exception"
138
-
138
+
139
139
  Note that this only works on source parsed from the RubyParser, not sexps
140
140
  declared using the `s()` syntax. This is because no source code is generated
141
141
  or stored by nodes. Instead, only the character ranges are stored, which are
142
142
  then looked up in the original full source string object. For example:
143
143
 
144
144
  # Following the code snippet above
145
- ast[0].then_block.source_range #=> 17..31
146
-
145
+ ast[0].then_block.source_range #=> 17..31
146
+
147
147
  We can also get the line and line ranges in a similar fashion:
148
148
 
149
149
  ast[0].type #=> :if
@@ -159,7 +159,7 @@ to quickly get at a node of a specific type in such a situation:
159
159
  # Get the first identifier in the statement
160
160
  ast = s(s(:int, "1"), s(s(:var_ref, s(:ident, "hello"))))
161
161
  ast.jump(:ident)[0] #=> "hello"
162
-
162
+
163
163
  Multiple types can be searched for at once. If none are found, the original root
164
164
  node is returned so that it may be chained.
165
165
 
@@ -167,11 +167,11 @@ node is returned so that it may be chained.
167
167
 
168
168
  The goal of the legacy parser is much the same as the new parser, but it is far
169
169
  more simplistic. Instead of a full-blown AST, the legacy parser simply groups
170
- together lists of "statements" called a {YARD::Parser::Ruby::Legacy::StatementList}.
170
+ together lists of "statements" called a {YARD::Parser::Ruby::Legacy::StatementList}.
171
171
  These statement lists are made up of {YARD::Parser::Ruby::Legacy::Statement} objects.
172
- A statement is any method call condition, loop, or declaration. Each statement
173
- may or may not have a block. In the case of a condition or loop, the block is
174
- the inner list of statements; in the case of a method call, the block is a do
172
+ A statement is any method call condition, loop, or declaration. Each statement
173
+ may or may not have a block. In the case of a condition or loop, the block is
174
+ the inner list of statements; in the case of a method call, the block is a do
175
175
  block (if provided). The statements themselves are made up of tokens, so instead
176
176
  of being semantic in nature like the new parser, statements are tied directly
177
177
  to the lexical tokens that make them up. To convert a statement into source, you
@@ -185,7 +185,7 @@ but using the legacy parser it is only one statement:
185
185
  stmts = ARD::Parser::Ruby::Legacy::StatementList.new("hello if 1")
186
186
  stmts[0].block #=> nil
187
187
  stmts[0].tokens.to_s #=> "hello if 1"
188
-
188
+
189
189
  In addition, this means that most handling still needs to be done via string
190
190
  manipulation and regular expression matching, making it considerably more
191
191
  difficult to use in edge case scenarios.
data/docs/Tags.md CHANGED
@@ -2,585 +2,281 @@
2
2
 
3
3
  # Tags Overview
4
4
 
5
- Tags represent the metadata that can be added to documentation through the `@tag`
6
- style syntax:
7
-
8
- # @tagname some data
9
- class Foo
10
- end
11
-
12
- The above example adds metadata under the name `tagname` to the Foo class object.
13
-
14
- Tags are the best way to add arbitrary metadata when documenting an object in a
15
- way to access it later without having to parse the entire comment string. The
16
- rest of the document will describe the tag syntax, how to access the tag
17
- metadata and how to extend YARD to support custom tags or override existing tags.
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).
18
61
 
19
62
  ## Tag Syntax
20
63
 
21
- Tags begin with "@tagname" at the start of a comment line. Tags can span multiple
22
- lines if the subsequent lines are indented by more than one space. The following
23
- syntax is valid:
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.
24
68
 
25
- # @tagname This is
26
- # tag data
27
- # but this is not
28
-
29
- In the above example, "@tagname" will have the text *"This is tag data"*.
69
+ ### Multi-line Tags
30
70
 
31
- If a tag's data begins with `(see NAME)` it is considered a "reference tag".
32
- The syntax and semantics of a reference tag are discussed in the section below
33
- titled "[Reference Tags](#reftags)"
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"*:
34
74
 
35
- Although custom tags can be parsed in any way, the built-in tags follow a few
36
- common syntax structures by convention in order to simplify the syntax. The
37
- following syntaxes are available:
75
+ # @tagname This is
76
+ # indented tag data
77
+ # but this is not
38
78
 
39
- ### Freeform Data
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.
40
86
 
41
- This syntax has no special syntax, it is simply a tagname followed by any
42
- data.
87
+ ### Common Tag Syntaxes
43
88
 
44
- @tagname data here
45
-
46
- ### Freeform Data With Title
47
-
48
- Occasionally a freeform tag may reserve the first line for a title (or some
49
- other associative identifier) and treat only the subsequent indented lines as
50
- the tag data. Two examples are the `@example` and `@overload` tags. In the case
51
- of `@example` the first line is a title, and in the case of `@overload` the
52
- first line is the method signature for the overload. Here is an example of both:
53
-
54
- @example Reverse a string
55
- "hello world".reverse
56
-
57
- @overload request(method = :get, url = 'http://example.com')
58
- Performs a request on +url+
59
- @param [Symbol] method the request method
60
- @param [String] url the URL to perform the request on
61
- @return [String] the result body (no headers)
62
-
63
- ### Data With Optional Type Information
64
-
65
- This syntax optionally contains type information to be associated with the
66
- tag. Type information is specified as a freeform list of Ruby types, duck
67
- types or literal values. The following is a valid tag with type information:
68
-
69
- @return [String, #read] a string or object that responds to #read
70
-
71
- ### Data With Name and Optional Type Information
72
-
73
- A special case of the above data with optional type information is the case
74
- of tags like `@param`, where the data is further associated with a key. In
75
- the case of `@param` the key is an argument name in the method. The following
76
- shows how this can be used:
77
-
78
- @param [String] url the URL to perform the request on
79
-
80
- Note that "url" in the above example is the key name. The syntax is of the form:
81
-
82
- @tagname [types] <name> <description>
83
-
84
- As mentioned, types are optional, so the following is also valid:
85
-
86
- @param url the URL to perform the request on
87
-
88
-
89
- <a name="taglist"></a>
90
-
91
- ## List of Available Tags
92
-
93
- YARD supplies the following built-in tags:
94
-
95
- * `@abstract`: Marks a class/module/method as abstract with optional
96
- implementor information.
97
-
98
- @abstract Subclass and override {#run} to implement a custom Threadable class.
99
-
100
- * `@api`: Declares the API that the object belongs to. Does not display in
101
- output, but useful for performing queries (`yardoc --query`). Any text is
102
- allowable in this tag, and there are no predefined values(*).
103
-
104
- @api freeform text
105
-
106
- (*) Note that the special name `@api private` does display a notice in
107
- documentation if it is listed, letting users know that the method is not
108
- to be used.
109
-
110
- * `@attr`: Declares an attribute from the docstring of a class. Meant to be
111
- used on Struct classes only (classes that inherit Struct).
112
-
113
- @attr [Types] attribute_name a full description of the attribute
114
-
115
- * `@attr_reader`: Declares a readonly attribute from the docstring of a class.
116
- Meant to be used on Struct classes only (classes that inherit Struct). See `@attr`.
117
-
118
- @attr_reader [Types] name description of a readonly attribute
119
-
120
- * `@attr_writer`: Declares a writeonly attribute from the docstring of class.
121
- Meant to be used on Struct classes only (classes that inherit Struct). See `@attr`.
122
-
123
- @attr_writer [Types] name description of writeonly attribute
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
-
131
- * `@author`: List the author(s) of a class/method
132
-
133
- @author Full Name
134
-
135
- * `@deprecated`: Marks a method/class as deprecated with an optional
136
- reason.
137
-
138
- @deprecated Describe the reason or provide alt. references here
139
-
140
- * `@example`: Show an example snippet of code for an object. The
141
- first line is an optional title.
142
-
143
- @example Reverse a string
144
- "mystring".reverse #=> "gnirtsym"
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
-
157
- * `@note`: Creates an emphasized note for the users to read about the
158
- object.
159
-
160
- @note This method should only be used in outer space.
161
-
162
- * `@option`: Describe an options hash in a method. The tag takes the
163
- name of the options parameter first, followed by optional types,
164
- the option key name, an optional default value for the key and a
165
- description of the option.
166
-
167
- # @param [Hash] opts the options to create a message with.
168
- # @option opts [String] :subject The subject
169
- # @option opts [String] :from ('nobody') From address
170
- # @option opts [String] :to Recipient email
171
- # @option opts [String] :body ('') The email's body
172
- def send_email(opts = {})
173
- end
174
-
175
- * `@overload`: Describe that your method can be used in various
176
- contexts with various parameters or return types. The first
177
- line should declare the new method signature, and the following
178
- indented tag data will be a new documentation string with its
179
- own tags adding metadata for such an overload.
180
-
181
- # @overload set(key, value)
182
- # Sets a value on key
183
- # @param [Symbol] key describe key param
184
- # @param [Object] value describe value param
185
- # @overload set(value)
186
- # Sets a value on the default key `:foo`
187
- # @param [Object] value describe value param
188
- def set(*args)
189
- end
190
-
191
- * `@param`: Defines method parameters
192
-
193
- @param [optional, types, ...] argname description
194
-
195
- * `@private`: Defines an object as private. This exists for classes,
196
- modules and constants that do not obey Ruby's visibility rules. For
197
- instance, an inner class might be considered "private", though Ruby
198
- would make no such distinction. By declaring the @private tag, the
199
- class can be hidden from documentation by using the `--no-private`
200
- command-line switch to yardoc (see {file:README.md}).
201
-
202
- @private
203
-
204
- * `@raise`: Describes an Exception that a method may throw
205
-
206
- @raise [ExceptionClass] description
207
-
208
- * `@return`: Describes return value of method
209
-
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
216
-
217
- * `@see`: "See Also" references for an object. Accepts URLs or
218
- other code objects with an optional description at the end.
219
-
220
- @see http://example.com Description of URL
221
- @see SomeOtherClass#method
222
-
223
- * `@since`: Lists the version the feature/object was first added
224
-
225
- @since 1.2.4
226
-
227
- * `@todo`: Marks a TODO note in the object being documented
228
-
229
- @todo Add support for Jabberwocky service
230
- There is an open source Jabberwocky library available
231
- at http://somesite.com that can be integrated easily
232
- into the project.
233
-
234
- * `@version`: Lists the version of a class, module or method
235
-
236
- @version 1.0
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
-
243
- * `@yield`: Describes the block. Use types to list the parameter
244
- names the block yields.
245
-
246
- # for block {|a, b, c| ... }
247
- @yield [a, b, c] Description of block
248
-
249
- * `@yieldparam`: Defines parameters yielded by a block
250
-
251
- @yieldparam [optional, types, ...] argname description
252
-
253
- * `@yieldreturn`: Defines return type of a block
254
-
255
- @yieldreturn [optional, types, ...] description
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:
256
92
 
93
+ 1. **Freeform data** &mdash; 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** &mdash; 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. The
101
+ name key is *required*. Note that for extensibility, the name can be placed
102
+ *before* the types list, like: `name [Types] description`. In this case,
103
+ a separating space is not required between the name and types, and you
104
+ can still use any of the other brackets that the type specifier list allows.
105
+ 4. **Freeform data with title** &mdash; freeform data where the first line cannot
106
+ be split into multiple lines. The first line must also always refer to the
107
+ "title" portion, and therefore, if there is no title, the first line must
108
+ be blank. The "title" might occasionally be listed by another name in tag
109
+ documentation, however, you can identify this syntax by the existence of
110
+ a multi-line signature with "Indented block" on the second line.
111
+
112
+ In the tag list below, the term "description" implies freeform data, `[Types]`
113
+ implies a types specifier list, "name" implies a name key, and "title" implies
114
+ the first line is a newline significant field that cannot be split into multiple
115
+ lines.
116
+
117
+ ### Types Specifier List
118
+
119
+ In some cases, a tag will allow for a "types specifier list"; this will be evident
120
+ from the use of the `[Types]` syntax in the tag signature. A types specifier list
121
+ is a comma separated list of types, most often classes or modules, but occasionally
122
+ literals. For example, the following {tag:return} tag lists a set of types returned
123
+ by a method:
124
+
125
+ # Finds an object or list of objects in the db using a query
126
+ # @return [String, Array<String>, nil] the object or objects to
127
+ # find in the database. Can be nil.
128
+ def find(query) finder_code_here end
129
+
130
+ A list of conventions for type names is specified below. Typically, however,
131
+ any Ruby literal or class/module is allowed here. Duck-types (method names
132
+ prefixed with "#") are also allowed.
133
+
134
+ Note that the type specifier list is always an optional field and can be omitted
135
+ when present in a tag signature. This is the reason why it is surrounded by
136
+ brackets. It is also a freeform list, and can contain any list of values, though
137
+ a set of conventions for how to list types is described below.
138
+
139
+ ### Type List Conventions
140
+
141
+ <p class="note">
142
+ A list of examples of common type listings and what they translate into is
143
+ available at <a href="http://yardoc.org/types">http://yardoc.org/types</a>.
144
+ </p>
145
+
146
+ Typically, a type list contains a list of classes or modules that are associated
147
+ with the tag. In some cases, however, certain special values are allowed or required
148
+ to be listed. This section discusses the syntax for specifying Ruby types inside of
149
+ type specifier lists, as well as the other non-Ruby types that are accepted by
150
+ convention in these lists.
151
+
152
+ It's important to realize that the conventions listed here may not always adequately
153
+ describe every type signature, and is not meant to be a complete syntax. This is
154
+ why the types specifier list is freeform and can contain any set of values. The
155
+ conventions defined here are only conventions, and if they do not work for your
156
+ type specifications, you can define your own appropriate conventions.
157
+
158
+ Note that a types specifier list might also be used for non-Type values. In this
159
+ case, the tag documentation will describe what values are allowed within the
160
+ type specifier list.
161
+
162
+ #### Class or Module Types
163
+
164
+ Any Ruby type is allowed as a class or module type. Such a type is simply the name
165
+ of the class or module.
166
+
167
+ Note that one extra type that is accepted by convention is the `Boolean` type,
168
+ which represents both the `TrueClass` and `FalseClass` types. This type does not
169
+ exist in Ruby, however.
170
+
171
+ #### Parametrized Types
172
+
173
+ In addition to basic types (like String or Array), YARD conventions allow for
174
+ a "generics" like syntax to specify container objects or other parametrized types.
175
+ The syntax is `Type<SubType, OtherSubType, ...>`. For instance, an Array might
176
+ contain only String objects, in which case the type specification would be
177
+ `Array<String>`. Multiple parametrized types can be listed, separated by commas.
178
+
179
+ Note that parametrized types are typically not order-dependent, in other words,
180
+ a list of parametrized types can occur in any order inside of a type. An array
181
+ specified as `Array<String, Fixnum>` can contain any amount of Strings or Fixnums,
182
+ in any order. When the order matters, use "order-dependent lists", described below.
183
+
184
+ #### Duck-Types
185
+
186
+ Duck-types are allowed in type specifier lists, and are identified by method
187
+ names beginning with the "#" prefix. Typically, duck-types are recommended
188
+ for {tag:param} tags only, though they can be used in other tags if needed.
189
+ The following example shows a method that takes a parameter of any type
190
+ that responds to the "read" method:
191
+
192
+ # Reads from any I/O object.
193
+ # @param [#read] io the input object to read from
194
+ def read(io) io.read end
195
+
196
+ #### Hashes
197
+
198
+ Hashes can be specified either via the parametrized type discussed above,
199
+ in the form `Hash<KeyType, ValueType>`, or using the hash specific syntax:
200
+ `Hash{KeyTypes=>ValueTypes}`. In the latter case, KeyTypes or ValueTypes can
201
+ also be a list of types separated by commas.
202
+
203
+ #### Order-Dependent Lists
204
+
205
+ An order dependent list is a set of types surrounded by "()" and separated by
206
+ commas. This list must contain exactly those types in exactly the order specified.
207
+ For instance, an Array containing a String, Fixnum and Hash in that order (and
208
+ having exactly those 3 elements) would be listed as: `Array<(String, Fixnum, Hash)>`.
209
+
210
+ #### Literals
211
+
212
+ Some literals are accepted by virtue of being Ruby literals, but also by YARD
213
+ conventions. Here is a non-exhaustive list of certain accepted literal values:
214
+
215
+ * `true`, `false`, `nil` &mdash; used when a method returns these explicit literal
216
+ values. Note that if your method returns both `true` or `false`, you should use
217
+ the `Boolean` conventional type instead.
218
+ * `self` &mdash; has the same meaning as Ruby's "self" keyword in the context of
219
+ parameters or return types. Recommended mostly for {tag:return} tags that are
220
+ chainable.
221
+ * `void` &mdash; indicates that the type for this tag is explicitly undefined.
222
+ Mostly used to specify {tag:return} tags that do not care about their return
223
+ value. Using a `void` return tag is recommended over no type, because it makes
224
+ the documentation more explicit about what the user should expect. YARD will
225
+ also add a note for the user if they have undefined return types, making things
226
+ clear that they should not use the return value of such a method.
257
227
 
258
228
  <a name="reftags"></a>
259
229
 
260
- ## Reference Tags
261
-
262
- Although attempt is made in YARD to leave as many of the syntax details as
263
- possible to the factory provider, there is a special tag syntax for referencing
264
- tags created in other objects so that they can be reused again. This is common
265
- when an object describes a return type or parameters that are passed through to
266
- other methods. In such a case, it is more manageable to use the reference tag
267
- syntax. Consider the following example:
268
-
269
- class User
270
- # @param [String] username the nam of the user to add
271
- # @param [Number] uid the user ID
272
- # @param [Number] gid the group ID
273
- def initialize(username, uid, gid)
274
- end
275
- end
276
-
277
- module UserHelper
278
- # @param (see User#initialize)
279
- def add_user(username, uid, gid)
280
- User.new(username, uid, gid)
281
- end
282
-
283
- # @param username (see User#initialize)
284
- def add_root_user(username)
285
- User.new(username, 0, 0)
286
- end
287
- end
288
-
289
- Because the UserHelper module methods delegate directly to `User.new`, copying
290
- the documentation details would be unmaintainable. In this case, the (see METHODNAME)
291
- syntax is used to reference the tags from the User constructor to the helper methods.
292
- For the first method, all `@param` tags are referenced in one shot, but the second
293
- method only references one of the tags by adding `username` before the reference.
294
-
295
- Reference tags are represented by the {YARD::Tags::RefTag} class and are created
296
- directly during parsing by {YARD::Docstring}.
297
-
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
469
-
470
- ### Accessing Tag Information
471
-
472
- Tag metadata is added when a {YARD::Docstring} is added to a {file:docs/CodeObjects.md code object}
473
- using the {YARD::CodeObjects::Base#docstring=} attribute. In addition to adding
474
- conventional comments, tags are parsed and associated with the object. The easiest
475
- way to access tags on an object is to use the {YARD::CodeObjects::Base#tag} and `#tags`
476
- methods, for example:
477
-
478
- # Using the Foo class object from above
479
- obj.tags(:tagname).first.text #=> "some data"
480
-
481
- Because multiple tags can be stored with the same name, they are stored as a list
482
- of tags. The `#tag` method is an alias for the first item in the list of tags.
483
- Also note that the `#tag`, `#tags` and `#has_tag?` methods are all convenience
484
- methods that delegate to the {YARD::Docstring} object described above.
485
-
486
- ### Adding Custom Tags
487
-
488
- The `@tagname` tag used in the above examples is clearly not part of the tags
489
- that come with YARD. If such a tag would actually be part of documentation under
490
- a default install, YARD would raise a warning that the tag does not exist. It is,
491
- however, trivial to add this tag to be recognized by YARD.
492
-
493
- All tags in YARD are added to the {YARD::Tags::Library tag library} which makes
494
- use of a tag factory class to parse the data inside the tags. To simply add a
495
- tag that stores simple text like our `@tagname` tag above, use:
496
-
497
- YARD::Tags::Library.define_tag("A Sample Tag", :tagname)
498
-
499
- This will now allow YARD to add the metadata from `@tagname` to the docstring.
500
-
501
- ## Tag Factory Architecture
502
-
503
- Recognizing a tag is one part of the process. Parsing the tag contents is the
504
- second step. YARD has a tag architecture that allows developers to add or completely
505
- change the way tags contents can be parsed.
506
-
507
- The separation of registration and tag creation can be seen in the following
508
- class diagram:
509
-
510
- ![Tags Architecture Class Diagram](images/tags-class-diagram.png)
511
-
512
- ### DefaultFactory
513
-
514
- By default, YARD has a few standard syntaxes that can be parsed for tags. These
515
- are all implemented by the {YARD::Tags::DefaultFactory} class. These syntaxes
516
- are:
517
-
518
- * Standard text: no parsing is done, but text is stripped of newlines and
519
- multiple spaces.
520
-
521
- * Raw text: does no parsing at all, no stripping of newlines or spaces. This
522
- is best used for code snippets.
230
+ ### Reference Tags
523
231
 
524
- * Raw text with title: does no parsing on the text but extracts the first line
525
- of the metadata as the "title", useful for tags such as `@example`:
526
-
527
- # @example Inspect an element
528
- # myobj.inspect #=> #<Object:0x123525>
232
+ <p class="note">
233
+ Reference tag syntax applies only to meta-data tags, not directives.
234
+ </p>
529
235
 
530
- * Text with types: parses a list of types at the beginning of the text. Types
531
- are optional. The standard syntax is in the form `[type1, type2, ...]`,
532
- for example:
533
-
534
- # @return [String, Symbol] a description here
535
- # @return description here with no types
536
-
537
- * Text with types and a name: parses a list of types at the beginning of text
538
- followed by a name and extra descriptive text. For example:
539
-
540
- # @param [String] str the string to reverse
541
- def reverse(str) '...' end
236
+ If a tag's data begins with `(see OBJECT)` it is considered a "reference tag".
237
+ A reference tag literally copies the tag data by the given tag name from the
238
+ specified OBJECT. For instance, a method may copy all {tag:param} tags from
239
+ a given object using the reference tag syntax:
542
240
 
543
- As mentioned above, this syntax is implemented by the `DefaultFactory` which can
544
- be swapped out for any factory. In some cases, a developer may want to change
545
- the type declaration syntax to be in the form:
241
+ # @param [String] user the username for the operation
242
+ # @param [String] host the host that this user is associated with
243
+ # @param [Time] time the time that this operation took place
244
+ def clean(user, host, time = Time.now) end
546
245
 
547
- # @tagname name <Types, here> description
548
-
549
- This can be done by simply implementing a new factory that parses the data in
550
- this form.
246
+ # @param (see #clean)
247
+ def activate(user, host, time = Time.now) end
551
248
 
552
- ### Implementing a Factory
249
+ ## Adding Custom Tags
553
250
 
554
- Factories should implement the method `parse_tag` as well as any `parse_tag_SUFFIX`
555
- method where SUFFIX refers to the suffix added when declaring the tag. For example,
556
- a tag can also be declared as follows:
251
+ <p class="note">If a tag is specific to a given project, consider namespacing
252
+ it by naming it in the form <tt>projectname.tagname</tt>, ie.,
253
+ <tt>yard.tag_signature</tt>.</p>
557
254
 
558
- YARD::Tags::Library.define_tag "Parameter", :param, :with_types
559
-
560
- In such a case, the factory will be called with method `parse_tag_with_types`. In
561
- all cases, the method should return a new {YARD::Tags::Tag} object. Generally,
562
- the `parse_tag` methods take 2 or 3 parameters. A simple tag can be implemented
563
- as:
255
+ Custom tags can be added to YARD either via the command-line or programmatically.
256
+ The programmatic method is not discussed in this document, but rather in the
257
+ {file:docs/TagsArch.md} document.
564
258
 
565
- def parse_tag(tag_name, text)
566
- Tag.new(tag_name, text)
567
- end
259
+ To add a custom tag via the command-line or .yardopts file, you can use the
260
+ `--*-tag` options. A few different options are available for the common tag
261
+ syntaxes described above. For example, to add a basic freeform tag, use:
568
262
 
569
- The text parameter contains pre-parsed text with extra spaces and newlines removed.
570
- If required, the method could also be declared with a third parameter containing
571
- unmodified raw text:
263
+ !!!sh
264
+ $ yard doc --tag rest_url:"REST URL"
572
265
 
573
- def parse_tag_with_raw_text(tag_name, text, raw_text)
574
- Tag.new(tag_name, raw_text)
575
- end
266
+ This will register the `@rest_url` tag for use in your documentation and display
267
+ this tag in HTML output wherever it is used with the heading "REST URL".
268
+ Note that the tag title should follow the tag name with a colon (`:`). Other
269
+ tag syntaxes exist, such as the type specifier list freeform tag
270
+ (`--type-tag`), or a named key tag with types (`--type-name-tag`).
576
271
 
577
- Note that this method would be invoked for a tag declared with the `:with_raw_text`
578
- suffix.
272
+ If you want to create a tag but not display it in output (it is only for
273
+ programmatic use), add `--hide-tag tagname` after the definition:
579
274
 
580
- ### Changing the Factory
275
+ !!!sh
276
+ $ yard doc --tag complexity:"McCabe Complexity" --hide-tag complexity
581
277
 
582
- To change the factory, set the {YARD::Tags::Library.default_factory} attribute:
278
+ Note that you might not need a tag title if you are hiding it. The title
279
+ part can be omitted.
583
280
 
584
- YARD::Tags::Library.default_factory = MyFactory
281
+ {yard:include_tags}
585
282
 
586
- This must be done before any parsing is done, or the factory will not be used.