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
@@ -1,5 +1,7 @@
1
1
  # Helper methods to parse @attr_* tags on a class.
2
2
  #
3
+ # @deprecated The use of +@attr+ tags are deprecated since 0.8.0 in favour of
4
+ # the +@!attribute+ directive. This module should not be relied on.
3
5
  # @since 0.5.6
4
6
  module YARD::Handlers::Ruby::StructHandlerMethods
5
7
  include YARD::CodeObjects
@@ -42,8 +44,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
42
44
  # Gets the return type for the member in a nicely formatted string. Used
43
45
  # to be injected into auto-generated docstrings.
44
46
  #
45
- # @param [ClassObject] klass the class whose tags we're searching
46
- # @param [String] member the name of the struct member whose return type we need
47
+ # @param [Tags::Tag] member_tag the tag object to check for types
47
48
  # @return [String] the user-declared type of the struct member, or [Object] if
48
49
  # the user did not define a type for this member.
49
50
  def return_type_from_tag(member_tag)
@@ -0,0 +1,281 @@
1
+ require "stringio"
2
+
3
+ module YARD
4
+ module I18n
5
+ # The +PotGenerator+ generates POT format string from
6
+ # {CodeObjects::Base} and {CodeObjects::ExtraFileObject}.
7
+ #
8
+ # == POT and PO
9
+ #
10
+ # POT is an acronym for "Portable Object Template". POT is a
11
+ # template file to create PO file. The extension for POT is
12
+ # ".pot". PO file is an acronym for "Portable Object". PO file has
13
+ # many parts of message ID (msgid) that is translation target
14
+ # message and message string (msgstr) that is translated message
15
+ # of message ID. If you want to tranlsate "Hello" in English into
16
+ # "Bonjour" in French, "Hello" is the msgid ID and "Bonjour" is
17
+ # msgstr. The extension for PO is ".po".
18
+ #
19
+ # == How to extract msgids
20
+ #
21
+ # The +PotGenerator+ has two parse methods:
22
+ #
23
+ # * {#parse_objects} for {CodeObjects::Base}
24
+ # * {#parse_files} for {CodeObjects::ExtraFileObject}
25
+ #
26
+ # {#parse_objects} extracts msgids from docstring and tags of
27
+ # {CodeObjects::Base} objects. The docstring of
28
+ # {CodeObjects::Base} object is parsed and a paragraph is
29
+ # extracted as a msgid. Tag name and tag text are extracted as
30
+ # msgids from a tag.
31
+ #
32
+ # {#parse_files} extracts msgids from
33
+ # {CodeObjects::ExtraFileObject} objects. The file content of
34
+ # {CodeObjects::ExtraFileObject} object is parsed and a paragraph
35
+ # is extracted as a msgid.
36
+ #
37
+ # == Usage
38
+ #
39
+ # To create a .pot file by +PotGenerator+, instantiate a
40
+ # +PotGenerator+ with a relative working directory path from a
41
+ # directory path that has created .pot file, parse
42
+ # {CodeObjects::Base} objects and {CodeObjects::ExtraFileObject}
43
+ # objects, generate a POT and write the generated POT to a .pot
44
+ # file. The relative working directory path is ".." when the
45
+ # working directory path is "." and the POT is wrote into
46
+ # "po/yard.pot".
47
+ #
48
+ # @example Generate a .pot file
49
+ # po_file_path = "po/yard.pot"
50
+ # po_file_directory_pathname = Pathname.new(po_file_path).directory)
51
+ # working_directory_pathname = Pathname.new(".")
52
+ # relative_base_path = working_directory_pathname.relative_path_from(po_file_directory_pathname).to_s
53
+ # # relative_base_path -> ".."
54
+ # generator = YARD::I18n::PotGenerator.new(relative_base_path)
55
+ # generator.parse_objects(objects)
56
+ # generator.parse_files(files)
57
+ # pot = generator.generate
58
+ # po_file_directory_pathname.mkpath
59
+ # File.open(po_file_path, "w") do |pot_file|
60
+ # pot_file.print(pot)
61
+ # end
62
+ # @see http://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
63
+ # GNU gettext manual about details of PO file
64
+ class PotGenerator
65
+ # Extracted messages. Key is a translation target message and
66
+ # value is properties of the translation target message. The
67
+ # properties are added to the msgid entry for the translation
68
+ # target message. The properties are +:locations+ and
69
+ # +:comments+.
70
+ #
71
+ # +:locations+ is an array of location. Location is an array of
72
+ # path and line number of the translation target message is
73
+ # appeared. Each location is prepended +:relative_base_path+
74
+ # that is passed on creating a +PotGenerator+ instance.
75
+ #
76
+ # +:comments+ is an array of comment. All comments are added to
77
+ # the msgid entry for the translation target message.
78
+ #
79
+ # @api private
80
+ # @return [Hash{String => Hash{:locations => Array<Array[String, Integer]>, :comments => Array<String>}}]
81
+ attr_reader :messages
82
+
83
+ # Creates a POT generator that uses +relative_base_path+ to
84
+ # generate locations for a msgid.
85
+ #
86
+ # @param [String] relative_base_path a relative working
87
+ # directory path from a directory path that has created .pot
88
+ # file.
89
+ def initialize(relative_base_path)
90
+ @relative_base_path = relative_base_path
91
+ @extracted_objects = {}
92
+ @messages = {}
93
+ end
94
+
95
+ # Parses {CodeObjects::Base} objects and stores extracted msgids
96
+ # into {#messages}
97
+ #
98
+ # @param [Array<CodeObjects::Base>] objects a list of
99
+ # {CodeObjects::Base} to be parsed.
100
+ # @return [void]
101
+ def parse_objects(objects)
102
+ objects.each do |object|
103
+ extract_documents(object)
104
+ end
105
+ end
106
+
107
+ # Parses {CodeObjects::ExtraFileObject} objects and stores
108
+ # extracted msgids into {#messages}.
109
+ #
110
+ # @param [Array<CodeObjects::ExtraFileObject>] files a list
111
+ # of {CodeObjects::ExtraFileObject} objects to be parsed.
112
+ # @return [void]
113
+ def parse_files(files)
114
+ files.each do |file|
115
+ extract_paragraphs(file)
116
+ end
117
+ end
118
+
119
+ # Generates POT from +@messages+.
120
+ #
121
+ # @return [String] POT format string
122
+ def generate
123
+ pot = header
124
+ sorted_messages = @messages.sort_by do |message, options|
125
+ sorted_locations = (options[:locations] || []).sort_by do |location|
126
+ location
127
+ end
128
+ sorted_locations.first || []
129
+ end
130
+ sorted_messages.each do |message, options|
131
+ generate_message(pot, message, options)
132
+ end
133
+ pot
134
+ end
135
+
136
+ private
137
+ def header
138
+ <<-'EOH'
139
+ # SOME DESCRIPTIVE TITLE.
140
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
141
+ # This file is distributed under the same license as the PACKAGE package.
142
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
143
+ #
144
+ #, fuzzy
145
+ msgid ""
146
+ msgstr ""
147
+ "Project-Id-Version: PACKAGE VERSION\n"
148
+ "Report-Msgid-Bugs-To: \n"
149
+ "POT-Creation-Date: 2011-11-20 22:17+0900\n"
150
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
151
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
152
+ "Language-Team: LANGUAGE <LL@li.org>\n"
153
+ "Language: \n"
154
+ "MIME-Version: 1.0\n"
155
+ "Content-Type: text/plain; charset=UTF-8\n"
156
+ "Content-Transfer-Encoding: 8bit\n"
157
+
158
+ EOH
159
+ end
160
+
161
+ def generate_message(pot, message, options)
162
+ options[:comments].compact.uniq.each do |comment|
163
+ pot << "# #{comment}\n" unless comment.empty?
164
+ end
165
+ options[:locations].uniq.each do |path, line|
166
+ pot << "#: #{@relative_base_path}/#{path}:#{line}\n"
167
+ end
168
+ escaped_message = escape_message(message)
169
+ escaped_message = escaped_message.gsub(/\n/, "\\\\n\"\n\"")
170
+ pot << "msgid \"#{escaped_message}\"\n"
171
+ pot << "msgstr \"\"\n"
172
+ pot << "\n"
173
+ pot
174
+ end
175
+
176
+ def escape_message(message)
177
+ message.gsub(/(\\|")/) do
178
+ special_character = $1
179
+ "\\#{special_character}"
180
+ end
181
+ end
182
+
183
+ def add_message(text)
184
+ @messages[text] ||= {:locations => [], :comments => []}
185
+ end
186
+
187
+ def extract_documents(object)
188
+ return if @extracted_objects.has_key?(object)
189
+
190
+ @extracted_objects[object] = true
191
+ case object
192
+ when CodeObjects::NamespaceObject
193
+ object.children.each do |child|
194
+ extract_documents(child)
195
+ end
196
+ end
197
+
198
+ if object.group
199
+ message = add_message(object.group)
200
+ object.files.each do |path, line|
201
+ message[:locations] << [path, line]
202
+ end
203
+ message[:comments] << object.path unless object.path.empty?
204
+ end
205
+
206
+ docstring = object.docstring
207
+ unless docstring.empty?
208
+ text = Text.new(StringIO.new(docstring))
209
+ text.extract_messages do |type, *args|
210
+ case type
211
+ when :paragraph
212
+ paragraph, line_no = *args
213
+ message = add_message(paragraph.rstrip)
214
+ object.files.each do |path, line|
215
+ message[:locations] << [path, (docstring.line || line) + line_no]
216
+ end
217
+ message[:comments] << object.path unless object.path.empty?
218
+ else
219
+ raise "should not reach here: unexpected type: #{type}"
220
+ end
221
+ end
222
+ end
223
+ docstring.tags.each do |tag|
224
+ extract_tag_documents(tag)
225
+ end
226
+ end
227
+
228
+ def extract_tag_documents(tag)
229
+ extract_tag_name(tag)
230
+ extract_tag_text(tag)
231
+ end
232
+
233
+ def extract_tag_name(tag)
234
+ return if tag.name.nil?
235
+ return if tag.name.is_a?(String) and tag.name.empty?
236
+ key = "tag|#{tag.tag_name}|#{tag.name}"
237
+ message = add_message(key)
238
+ tag.object.files.each do |file|
239
+ message[:locations] << file
240
+ end
241
+ tag_label = "@#{tag.tag_name}"
242
+ tag_label << " [#{tag.types.join(', ')}]" if tag.types
243
+ message[:comments] << tag_label
244
+ end
245
+
246
+ def extract_tag_text(tag)
247
+ return if tag.text.nil?
248
+ return if tag.text.empty?
249
+ message = add_message(tag.text)
250
+ tag.object.files.each do |file|
251
+ message[:locations] << file
252
+ end
253
+ tag_label = "@#{tag.tag_name}"
254
+ tag_label << " [#{tag.types.join(', ')}]" if tag.types
255
+ tag_label << " #{tag.name}" if tag.name
256
+ message[:comments] << tag_label
257
+ end
258
+
259
+ def extract_paragraphs(file)
260
+ File.open(file.filename) do |input|
261
+ text = Text.new(input, :have_header => true)
262
+ text.extract_messages do |type, *args|
263
+ case type
264
+ when :attribute
265
+ name, value, line_no = *args
266
+ message = add_message(value)
267
+ message[:locations] << [file.filename, line_no]
268
+ message[:comments] << name
269
+ when :paragraph
270
+ paragraph, line_no = *args
271
+ message = add_message(paragraph.rstrip)
272
+ message[:locations] << [file.filename, line_no]
273
+ else
274
+ raise "should not reach here: unexpected type: #{type}"
275
+ end
276
+ end
277
+ end
278
+ end
279
+ end
280
+ end
281
+ end
@@ -0,0 +1,72 @@
1
+ module YARD
2
+ module I18n
3
+ # Provides some convenient features for translating a text.
4
+ class Text
5
+ # Creates a text object that has translation related features for
6
+ # the input text.
7
+ #
8
+ # @param [#each_line] input a text to be translated.
9
+ # @option options [Boolean] :have_header (false) whether the
10
+ # input text has header or not.
11
+ def initialize(input, options={})
12
+ @input = input
13
+ @options = options
14
+ end
15
+
16
+ # Extracts translation target messages from +@input+.
17
+ #
18
+ # @yield [:attribute, name, value, line_no] the block that
19
+ # recieves extracted an attribute in header. It may called many
20
+ # times.
21
+ # @yieldparam [String] name the name of extracted attribute.
22
+ # @yieldparam [String] value the value of extracted attribute.
23
+ # @yieldparam [Integer] line_no the defined line number of extracted
24
+ # attribute.
25
+ # @yield [:paragraph, text, start_line_no] the block that
26
+ # recieves extracted a paragraph in body. Paragraph is a text
27
+ # block separated by one or more empty lines. Empty line is a
28
+ # line that contains only zero or more whitespaces. It may
29
+ # called many times.
30
+ # @yieldparam [String] text the text of extracted paragraph.
31
+ # @yieldparam [Integer] start_line_no the start line number of
32
+ # extracted paragraph.
33
+ # @return [void]
34
+ def extract_messages
35
+ paragraph = ""
36
+ paragraph_start_line = 0
37
+ line_no = 0
38
+ in_header = @options[:have_header]
39
+
40
+ @input.each_line do |line|
41
+ line_no += 1
42
+ if in_header
43
+ case line
44
+ when /^#!\S+\s*$/
45
+ in_header = false unless line_no == 1
46
+ when /^\s*#\s*@(\S+)\s*(.+?)\s*$/
47
+ name, value = $1, $2
48
+ yield(:attribute, name, value, line_no)
49
+ else
50
+ in_header = false
51
+ next if line.chomp.empty?
52
+ end
53
+ next if in_header
54
+ end
55
+
56
+ case line
57
+ when /^\s*$/
58
+ next if paragraph.empty?
59
+ yield(:paragraph, paragraph.rstrip, paragraph_start_line)
60
+ paragraph = ""
61
+ else
62
+ paragraph_start_line = line_no if paragraph.empty?
63
+ paragraph << line
64
+ end
65
+ end
66
+ unless paragraph.empty?
67
+ yield(:paragraph, paragraph.rstrip, paragraph_start_line)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
data/lib/yard/logging.rb CHANGED
@@ -38,18 +38,14 @@ module YARD
38
38
  error "Stack trace:" +
39
39
  exc.backtrace[0..5].map {|x| "\n\t#{x}" }.join + "\n"
40
40
  end
41
-
41
+
42
42
  # Warns that the Ruby environment does not support continuations. Applies
43
43
  # to JRuby, Rubinius and MacRuby. This warning will only display once
44
44
  # per Ruby process.
45
- #
45
+ #
46
+ # @deprecated Continuations are no longer needed by YARD 0.8.0+.
46
47
  # @return [void]
47
48
  def warn_no_continuations
48
- return if CONTINUATIONS_SUPPORTED
49
- return if $NO_CONTINUATION_WARNING
50
- $NO_CONTINUATION_WARNING = true
51
- warn "JRuby/MacRuby/Rubinius do not implement Kernel#callcc and cannot " +
52
- "load files in order. You must specify the correct order manually."
53
49
  end
54
50
 
55
51
  # Sets the logger level for the duration of the block
@@ -0,0 +1,216 @@
1
+ module YARD
2
+ # Generalized options class for passing around large amounts of options between objects.
3
+ #
4
+ # The options class exists for better visibility and documentability of options being
5
+ # passed through to other objects. Because YARD has parser and template architectures
6
+ # that are heavily reliant on options, it is necessary to make these option keys easily
7
+ # visible and understood by developers. Since the options class is more than just a
8
+ # basic Hash, the subclass can provide aliasing and convenience methods to simplify
9
+ # option property access, and, if needed, support backward-compatibility for deprecated
10
+ # key names.
11
+ #
12
+ # == Hash and OpenStruct-like Access
13
+ #
14
+ # Although the options class allows for Hash-like access (<tt>opts[:key]</tt>), the recommended
15
+ # mechanism for accessing an option key will be via standard method calls on attributes
16
+ #
17
+ # The options class can also act as an open ended key value storage structure (like a
18
+ # Hash or OpenStruct), and allows for setting and getting of unregistered option keys.
19
+ # This methodology is not recommended, however, and is only supported for backward
20
+ # compatibility inside YARD. Whenever possible, developers should define all keys used
21
+ # by an options class.
22
+ #
23
+ # == Declaring Default Values
24
+ #
25
+ # Note that the options class can contain default value definitions for certain options,
26
+ # but to initialize these defaults, {#reset_defaults} must be called manually after
27
+ # initialization; the options object is always created empty until defaults are applied.
28
+ #
29
+ # @abstract Subclasses should define (and document) custom attributes that are expected
30
+ # to be made available as option keys.
31
+ # @example Defining an Options class with custom option keys
32
+ # class TemplateOptions < YARD::Options
33
+ # # @return [Symbol] the output format to generate templates in
34
+ # attr_accessor :format
35
+ #
36
+ # # @return [Symbol] the template to use when generating output
37
+ # attr_accessor :template
38
+ # end
39
+ # @example Initializing default option values
40
+ # class TemplateOptions < YARD::Options
41
+ # def reset_defaults
42
+ # super
43
+ # self.format = :html
44
+ # self.template = :default
45
+ # self.highlight = true
46
+ # # ...
47
+ # end
48
+ # end
49
+ # @example Using +default_attr+ to create default attributes
50
+ # class TemplateOptions < YARD::Options
51
+ # default_attr :format, :html
52
+ # default_attr :template, :default
53
+ # default_attr :highlight, true
54
+ # end
55
+ # @example Deprecating an option while still supporting it
56
+ # class TemplateOptions < YARD::Options
57
+ # # @return [Boolean] if syntax highlighting should be performed on code blocks.
58
+ # # Defaults to true.
59
+ # attr_accessor :highlight
60
+ #
61
+ # # @deprecated Use {#highlight} instead.
62
+ # # @return [Boolean] if no syntax highlighting should be performs on code blocks.
63
+ # # Defaults to false.
64
+ # attr_accessor :no_highlight
65
+ # def no_highlight=(value) @highlight = !value end
66
+ # def no_highlight; !highlight end
67
+ # end
68
+ class Options
69
+ # @!macro [attach] yard.default_attr
70
+ # @!attribute $1
71
+ # Defines an attribute named +key+ and sets a default value for it
72
+ #
73
+ # @example Defining a default option key
74
+ # default_attr :name, 'Default Name'
75
+ # default_attr :time, lambda { Time.now }
76
+ # @param [Symbol] key the option key name
77
+ # @param [Object, Proc] default the default object value. If the default
78
+ # value is a proc, it is executed upon initialization.
79
+ def self.default_attr(key, default)
80
+ (@defaults ||= {})[key] = default
81
+ attr_accessor(key)
82
+ end
83
+
84
+ # Delegates calls with Hash syntax to actual method with key name
85
+ #
86
+ # @example Calling on an option key with Hash syntax
87
+ # options[:format] # equivalent to: options.format
88
+ # @param [Symbol, String] key the option name to access
89
+ # @return the value of the option named +key+
90
+ def [](key) send(key) end
91
+
92
+ # Delegates setter calls with Hash syntax to the attribute setter with the key name
93
+ #
94
+ # @example Setting an option with Hash syntax
95
+ # options[:format] = :html # equivalent to: options.format = :html
96
+ # @param [Symbol, String] key the optin to set
97
+ # @param [Object] value the value to set for the option
98
+ # @return [Object] the value being set
99
+ def []=(key, value) send("#{key}=", value) end
100
+
101
+ # Updates values from an options hash or options object on this object.
102
+ # All keys passed should be key names defined by attributes on the class.
103
+ #
104
+ # @example Updating a set of options on an Options object
105
+ # opts.update(:template => :guide, :type => :fulldoc)
106
+ # @param [Hash, Options] opts
107
+ # @return [self]
108
+ def update(opts)
109
+ opts = opts.to_hash if Options === opts
110
+ opts.each do |key, value|
111
+ self[key] = value
112
+ end
113
+ self
114
+ end
115
+
116
+ # Creates a new options object and sets options hash or object value
117
+ # onto that object.
118
+ #
119
+ # @param [Options, Hash] opts
120
+ # @return [Options] the newly created options object
121
+ # @see #update
122
+ def merge(opts)
123
+ dup.update(opts)
124
+ end
125
+
126
+ # @return [Hash] Converts options object to an options hash. All keys
127
+ # will be symbolized.
128
+ def to_hash
129
+ opts = {}
130
+ instance_variables.each do |ivar|
131
+ name = ivar.to_s.sub(/^@/, '')
132
+ opts[name.to_sym] = send(name)
133
+ end
134
+ opts
135
+ end
136
+
137
+ # Yields over every option key and value
138
+ # @yield [key, value] every option key and value
139
+ # @yieldparam [Symbol] key the option key
140
+ # @yieldparam [Object] value the option value
141
+ # @return [void]
142
+ def each(&block)
143
+ instance_variables.each do |ivar|
144
+ name = ivar.to_s.sub(/^@/, '')
145
+ yield(name.to_sym, send(name))
146
+ end
147
+ end
148
+
149
+ # Inspects the object
150
+ def inspect
151
+ "<#{self.class}: #{to_hash.inspect}>"
152
+ end
153
+
154
+ # @return [Boolean] whether another Options object equals the
155
+ # keys and values of this options object
156
+ def ==(other)
157
+ case other
158
+ when Options; to_hash == other.to_hash
159
+ when Hash; to_hash == other
160
+ else false
161
+ end
162
+ end
163
+
164
+ # Handles setting and accessing of unregistered keys similar
165
+ # to an OpenStruct object.
166
+ #
167
+ # @note It is not recommended to set and access unregistered keys on
168
+ # an Options object. Instead, register the attribute before using it.
169
+ def method_missing(meth, *args, &block)
170
+ if meth.to_s =~ /^(.+)=$/
171
+ log.debug "Attempting to set unregistered key #{$1} on #{self.class}"
172
+ instance_variable_set("@#{$1}", args.first)
173
+ elsif args.size == 0
174
+ log.debug "Attempting to access unregistered key #{meth} on #{self.class}"
175
+ instance_variable_get("@#{meth}")
176
+ else
177
+ super
178
+ end
179
+ end
180
+
181
+ # Resets all values to their defaults.
182
+ #
183
+ # @abstract Subclasses should override this method to perform custom
184
+ # value initialization if not using {default_attr}. Be sure to call
185
+ # +super+ so that default initialization can take place.
186
+ # @return [void]
187
+ def reset_defaults
188
+ names_set = {}
189
+ self.class.ancestors.each do |klass| # look at all ancestors
190
+ defaults = klass.instance_variable_get("@defaults")
191
+ return unless defaults
192
+ defaults.each do |key, value|
193
+ next if names_set[key]
194
+ names_set[key] = true
195
+ self[key] = Proc === value ? value.call : value
196
+ end
197
+ end
198
+ end
199
+
200
+ # Deletes an option value for +key+
201
+ #
202
+ # @param [Symbol, String] key the key to delete a value for
203
+ # @return [Object] the value that was deleted
204
+ def delete(key)
205
+ val = self[key]
206
+ if instance_variable_defined?("@#{key}")
207
+ remove_instance_variable("@#{key}")
208
+ end
209
+ val
210
+ end
211
+
212
+ unless defined? tap() # only for 1.8.6
213
+ def tap(&block) yield(self); self end
214
+ end
215
+ end
216
+ end