yard 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
@@ -1,7 +1,7 @@
1
1
  # Handles a conditional inside a method
2
2
  class YARD::Handlers::Ruby::MethodConditionHandler < YARD::Handlers::Ruby::Base
3
3
  handles :if_mod, :unless_mod
4
-
4
+
5
5
  process do
6
6
  parse_block(statement.then_block, :owner => owner)
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # Handles a method definition
2
2
  class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
3
3
  handles :def, :defs
4
-
4
+
5
5
  process do
6
6
  nobj = namespace
7
7
  mscope = scope
@@ -19,28 +19,28 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
19
19
  args = format_args(statement[1])
20
20
  blk = statement[2]
21
21
  end
22
-
22
+
23
23
  nobj = P(namespace, nobj.value) while nobj.type == :constant
24
- obj = register MethodObject.new(nobj, meth, mscope) do |o|
25
- o.visibility = visibility
24
+ obj = register MethodObject.new(nobj, meth, mscope) do |o|
25
+ o.visibility = visibility
26
26
  o.source = statement.source
27
27
  o.signature = method_signature(meth)
28
28
  o.explicit = true
29
29
  o.parameters = args
30
30
  end
31
-
31
+
32
32
  # delete any aliases referencing old method
33
33
  nobj.aliases.each do |aobj, name|
34
34
  next unless name == obj.name
35
35
  nobj.aliases.delete(aobj)
36
36
  end if nobj.is_a?(NamespaceObject)
37
-
37
+
38
38
  if mscope == :instance && meth == "initialize"
39
39
  unless obj.has_tag?(:return)
40
- obj.docstring.add_tag(YARD::Tags::Tag.new(:return,
40
+ obj.docstring.add_tag(YARD::Tags::Tag.new(:return,
41
41
  "a new instance of #{namespace.name}", namespace.name.to_s))
42
42
  end
43
- elsif mscope == :class && obj.docstring.blank? && %w(inherited included
43
+ elsif mscope == :class && obj.docstring.blank? && %w(inherited included
44
44
  extended method_added method_removed method_undefined).include?(meth)
45
45
  obj.docstring.add_tag(YARD::Tags::Tag.new(:private, nil))
46
46
  elsif meth.to_s =~ /\?$/
@@ -50,7 +50,7 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
50
50
  obj.docstring.add_tag(YARD::Tags::Tag.new(:return, "", "Boolean"))
51
51
  end
52
52
  end
53
-
53
+
54
54
  if obj.has_tag?(:option)
55
55
  # create the options parameter if its missing
56
56
  obj.tags(:option).each do |option|
@@ -61,7 +61,7 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
61
61
  end
62
62
  end
63
63
  end
64
-
64
+
65
65
  if info = obj.attr_info
66
66
  if meth.to_s =~ /=$/ # writer
67
67
  info[:write] = obj if info[:read]
@@ -69,10 +69,10 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
69
69
  info[:read] = obj if info[:write]
70
70
  end
71
71
  end
72
-
72
+
73
73
  parse_block(blk, :owner => obj) # mainly for yield/exceptions
74
74
  end
75
-
75
+
76
76
  def format_args(args)
77
77
  args = args.jump(:params)
78
78
  params = []
@@ -83,7 +83,7 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
83
83
  params << ["&" + args.block_param.source, nil] if args.block_param
84
84
  params
85
85
  end
86
-
86
+
87
87
  def method_signature(method_name)
88
88
  if statement[1]
89
89
  "def #{method_name}(#{statement[1].jump(:params).source})"
@@ -1,8 +1,8 @@
1
1
  # Handles the 'include' statement to mixin a module in the instance scope
2
2
  class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
3
- namespace_only
4
3
  handles method_call(:include)
5
-
4
+ namespace_only
5
+
6
6
  process do
7
7
  errors = []
8
8
  statement.parameters(false).each do |mixin|
@@ -23,14 +23,14 @@ class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
23
23
  def process_mixin(mixin)
24
24
  raise YARD::Parser::UndocumentableError unless mixin.ref?
25
25
  raise YARD::Parser::UndocumentableError if mixin.first.type == :ident
26
-
26
+
27
27
  case obj = Proxy.new(namespace, mixin.source)
28
28
  when Proxy
29
29
  obj.type = :module
30
30
  when ConstantObject # If a constant is included, use its value as the real object
31
31
  obj = Proxy.new(namespace, obj.value)
32
32
  end
33
-
33
+
34
34
  namespace.mixins(scope).unshift(obj) unless namespace.mixins(scope).include?(obj)
35
35
  end
36
36
  end
@@ -1,7 +1,8 @@
1
1
  # Handles the declaration of a module
2
2
  class YARD::Handlers::Ruby::ModuleHandler < YARD::Handlers::Ruby::Base
3
3
  handles :module
4
-
4
+ namespace_only
5
+
5
6
  process do
6
7
  modname = statement[0].source
7
8
  mod = register ModuleObject.new(namespace, modname)
@@ -1,8 +1,8 @@
1
1
  # Sets visibility of a constant (class, module, const)
2
2
  class YARD::Handlers::Ruby::PrivateConstantHandler < YARD::Handlers::Ruby::Base
3
- namespace_only
4
3
  handles method_call(:private_constant)
5
-
4
+ namespace_only
5
+
6
6
  process do
7
7
  errors = []
8
8
  statement.parameters.each do |param|
@@ -18,9 +18,9 @@ class YARD::Handlers::Ruby::PrivateConstantHandler < YARD::Handlers::Ruby::Base
18
18
  raise UndocumentableError, "private constant#{msg} for #{namespace.path}"
19
19
  end
20
20
  end
21
-
21
+
22
22
  private
23
-
23
+
24
24
  def privatize_constant(node)
25
25
  if node.literal? || (node.type == :var_ref && node[0].type == :const)
26
26
  node = node.jump(:tstring_content, :const)
@@ -1,9 +1,9 @@
1
1
  # Helper methods to parse @attr_* tags on a class.
2
- #
2
+ #
3
3
  # @since 0.5.6
4
4
  module YARD::Handlers::Ruby::StructHandlerMethods
5
5
  include YARD::CodeObjects
6
-
6
+
7
7
  # Extracts the user's defined @member tag for a given class and its member. Returns
8
8
  # nil if the user did not define a @member tag for this struct entry.
9
9
  #
@@ -17,14 +17,14 @@ module YARD::Handlers::Ruby::StructHandlerMethods
17
17
  end
18
18
 
19
19
  # Retrieves all members defined in @attr* tags
20
- #
20
+ #
21
21
  # @param [ClassObject] klass the class with the attributes
22
22
  # @return [Array<String>] the list of members defined as attributes on the class
23
23
  def members_from_tags(klass)
24
24
  tags = klass.tags(:attr) + klass.tags(:attr_reader) + klass.tags(:attr_writer)
25
25
  tags.map {|t| t.name }.uniq
26
26
  end
27
-
27
+
28
28
  # Determines whether to create an attribute method based on the class's
29
29
  # tags.
30
30
  #
@@ -38,7 +38,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
38
38
  return !member_tag_for_member(klass, member, :write) if type == :read
39
39
  return !member_tag_for_member(klass, member, :read)
40
40
  end
41
-
41
+
42
42
  # Gets the return type for the member in a nicely formatted string. Used
43
43
  # to be injected into auto-generated docstrings.
44
44
  #
@@ -49,7 +49,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
49
49
  def return_type_from_tag(member_tag)
50
50
  (member_tag && member_tag.types) ? member_tag.types : "Object"
51
51
  end
52
-
52
+
53
53
  # Creates the auto-generated docstring for the getter method of a struct's
54
54
  # member. This is used so the generated documentation will look just like that
55
55
  # of an attribute defined using attr_accessor.
@@ -64,7 +64,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
64
64
  new_method.docstring.replace(getter_doc_text)
65
65
  new_method.docstring.add_tag YARD::Tags::Tag.new(:return, "the current value of #{member}", return_type)
66
66
  end
67
-
67
+
68
68
  # Creates the auto-generated docstring for the setter method of a struct's
69
69
  # member. This is used so the generated documentation will look just like that
70
70
  # of an attribute defined using attr_accessor.
@@ -80,7 +80,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
80
80
  new_method.docstring.add_tag YARD::Tags::Tag.new(:param, "the value to set the attribute #{member} to.", return_type, "value")
81
81
  new_method.docstring.add_tag YARD::Tags::Tag.new(:return, "the newly set value", return_type)
82
82
  end
83
-
83
+
84
84
  # Creates and registers a class object with the given name and superclass name.
85
85
  # Returns it for further use.
86
86
  #
@@ -93,7 +93,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
93
93
  o.superclass.type = :class if o.superclass.is_a?(Proxy)
94
94
  end
95
95
  end
96
-
96
+
97
97
  # Creates the setter (writer) method and attaches it to the class as an attribute.
98
98
  # Also sets up the docstring to prettify the documentation output.
99
99
  #
@@ -110,7 +110,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
110
110
  add_writer_tags(klass, new_meth, member)
111
111
  klass.attributes[:instance][member][:write] = new_meth
112
112
  end
113
-
113
+
114
114
  # Creates the getter (reader) method and attaches it to the class as an attribute.
115
115
  # Also sets up the docstring to prettify the documentation output.
116
116
  #
@@ -124,7 +124,7 @@ module YARD::Handlers::Ruby::StructHandlerMethods
124
124
  add_reader_tags(klass, new_meth, member)
125
125
  klass.attributes[:instance][member][:read] = new_meth
126
126
  end
127
-
127
+
128
128
  # Creates the given member methods and attaches them to the given ClassObject.
129
129
  #
130
130
  # @param [ClassObject] klass the class to generate attributes for
@@ -4,7 +4,7 @@ class YARD::Handlers::Ruby::VisibilityHandler < YARD::Handlers::Ruby::Base
4
4
  handles method_call(:protected)
5
5
  handles method_call(:public)
6
6
  namespace_only
7
-
7
+
8
8
  process do
9
9
  return if (ident = statement.jump(:ident)) == statement
10
10
  case statement.type
@@ -1,30 +1,30 @@
1
1
  # Handles 'yield' calls
2
2
  class YARD::Handlers::Ruby::YieldHandler < YARD::Handlers::Ruby::Base
3
3
  handles :yield, :yield0
4
-
4
+
5
5
  process do
6
6
  return unless owner.is_a?(MethodObject) # Only methods yield
7
7
  return if owner.has_tag? :yield # Don't override yield tags
8
8
  return if owner.has_tag? :yieldparam # Same thing.
9
9
 
10
10
  yieldtag = YARD::Tags::Tag.new(:yield, "", [])
11
-
11
+
12
12
  if statement.type == :yield
13
13
  statement.jump(:list).children.each do |item|
14
14
  if item == s(:var_ref, s(:kw, "self"))
15
15
  yieldtag.types << '_self'
16
- owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
16
+ owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
17
17
  "the object that the method was called on", owner.namespace.path, '_self')
18
18
  elsif item == s(:zsuper)
19
19
  yieldtag.types << '_super'
20
- owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
20
+ owner.docstring.add_tag YARD::Tags::Tag.new(:yieldparam,
21
21
  "the result of the method from the superclass", nil, '_super')
22
22
  else
23
23
  yieldtag.types << item.source
24
24
  end
25
25
  end
26
26
  end
27
-
27
+
28
28
  owner.docstring.add_tag(yieldtag) unless yieldtag.types.empty?
29
29
  end
30
30
  end
data/lib/yard/logging.rb CHANGED
@@ -6,13 +6,13 @@ module YARD
6
6
  class Logger < ::Logger
7
7
  attr_writer :show_backtraces
8
8
  def show_backtraces; @show_backtraces || level == DEBUG end
9
-
9
+
10
10
  # The logger instance
11
11
  # @return [Logger] the logger instance
12
12
  def self.instance(pipe = STDERR)
13
13
  @logger ||= new(pipe)
14
14
  end
15
-
15
+
16
16
  # Creates a new logger
17
17
  def initialize(*args)
18
18
  super
@@ -20,27 +20,27 @@ module YARD
20
20
  self.level = WARN
21
21
  self.formatter = method(:format_log)
22
22
  end
23
-
23
+
24
24
  # Changes the debug level to DEBUG if $DEBUG is set
25
25
  # and writes a debugging message.
26
26
  def debug(*args)
27
27
  self.level = DEBUG if $DEBUG
28
28
  super
29
29
  end
30
-
30
+
31
31
  # Prints the backtrace +exc+ to the logger as error data.
32
- #
32
+ #
33
33
  # @param [Array<String>] exc the backtrace list
34
34
  # @return [void]
35
35
  def backtrace(exc)
36
36
  return unless show_backtraces
37
37
  error "#{exc.class.class_name}: #{exc.message}"
38
- error "Stack trace:" +
38
+ error "Stack trace:" +
39
39
  exc.backtrace[0..5].map {|x| "\n\t#{x}" }.join + "\n"
40
40
  end
41
-
41
+
42
42
  # Sets the logger level for the duration of the block
43
- #
43
+ #
44
44
  # @example
45
45
  # log.enter_level(Logger::ERROR) do
46
46
  # YARD.parse_string "def x; end"
@@ -48,14 +48,14 @@ module YARD
48
48
  # @param [Fixnum] new_level the logger level for the duration of the block.
49
49
  # values can be found in Ruby's Logger class.
50
50
  # @yield the block with the logger temporarily set to +new_level+
51
- def enter_level(new_level = level, &block)
51
+ def enter_level(new_level = level, &block)
52
52
  old_level, self.level = level, new_level
53
53
  yield
54
54
  self.level = old_level
55
55
  end
56
-
56
+
57
57
  private
58
-
58
+
59
59
  # Log format (from Logger implementation). Used by Logger internally
60
60
  def format_log(sev, time, prog, msg)
61
61
  "[#{sev.downcase}]: #{msg}\n"
@@ -1,12 +1,12 @@
1
1
  module YARD
2
2
  module Parser
3
3
  # Represents the abstract base parser class that parses source code in
4
- # a specific way. A parser should implement {#parse}, {#tokenize} and
4
+ # a specific way. A parser should implement {#parse}, {#tokenize} and
5
5
  # {#enumerator}.
6
- #
6
+ #
7
7
  # == Registering a Custom Parser
8
8
  # To register a parser, see {SourceParser.register_parser_type}
9
- #
9
+ #
10
10
  # @abstract
11
11
  # @see #parse
12
12
  # @see #tokenize
@@ -17,7 +17,7 @@ module YARD
17
17
  def self.parse(source, filename = nil)
18
18
  new(source, filename).parse
19
19
  end
20
-
20
+
21
21
  # This default constructor does nothing. The subclass is responsible for
22
22
  # storing the source contents and filename if they are required.
23
23
  # @param [String] source the source contents
@@ -25,25 +25,25 @@ module YARD
25
25
  def initialize(source, filename)
26
26
  raise NotImplementedError, "invalid parser implementation"
27
27
  end
28
-
28
+
29
29
  # This method should be implemented to parse the source and return itself.
30
30
  # @abstract
31
31
  # @return [Base] this method should return itself
32
32
  def parse
33
33
  raise NotImplementedError, "#{self.class} must implement #parse"
34
34
  end
35
-
35
+
36
36
  # This method should be implemented to tokenize given source
37
37
  # @abstract
38
38
  # @return [Array] a list/tree of lexical tokens
39
39
  def tokenize
40
40
  raise NotImplementedError, "#{self.class} does not support tokenization"
41
41
  end
42
-
42
+
43
43
  # This method should be implemented to return a list of semantic tokens
44
44
  # representing the source code to be post-processed. Otherwise the method
45
45
  # should return nil.
46
- #
46
+ #
47
47
  # @abstract
48
48
  # @return [Array] a list of semantic tokens representing the source code
49
49
  # to be post-processed
@@ -10,7 +10,7 @@ module YARD
10
10
  @namespaces = {}
11
11
  @content = clean_source(source)
12
12
  end
13
-
13
+
14
14
  def parse
15
15
  parse_modules
16
16
  parse_classes
@@ -18,19 +18,19 @@ module YARD
18
18
  parse_constants
19
19
  parse_includes
20
20
  end
21
-
21
+
22
22
  # @since 0.5.6
23
23
  def tokenize
24
24
  raise NotImplementedError, "no tokenization support for C/C++ files"
25
25
  end
26
-
26
+
27
27
  private
28
-
28
+
29
29
  # @since 0.5.3
30
30
  def remove_var_prefix(var)
31
31
  var.gsub(/^rb_[mc]|^[a-z_]+/, '')
32
32
  end
33
-
33
+
34
34
  def ensure_loaded!(object, max_retries = 1)
35
35
  return if object.is_a?(CodeObjects::RootObject)
36
36
  unless CONTINUATIONS_SUPPORTED
@@ -41,11 +41,11 @@ module YARD
41
41
  end
42
42
  raise NamespaceMissingError, object
43
43
  end
44
-
44
+
45
45
  retries = 0
46
46
  context = callcc {|c| c }
47
- retries += 1
48
-
47
+ retries += 1
48
+
49
49
  if object.is_a?(CodeObjects::Proxy)
50
50
  if retries <= max_retries
51
51
  log.debug "Missing object #{object} in file `#{@file}', moving it to the back of the line."
@@ -60,7 +60,7 @@ module YARD
60
60
  ensure_loaded!(namespace)
61
61
  obj = CodeObjects::ModuleObject.new(namespace, mod_name)
62
62
  obj.add_file(@file)
63
- find_namespace_docstring(obj)
63
+ find_namespace_docstring(obj)
64
64
  @namespaces[var_name] = obj
65
65
  end
66
66
 
@@ -71,17 +71,16 @@ module YARD
71
71
  obj = CodeObjects::ClassObject.new(namespace, class_name)
72
72
  obj.superclass = @namespaces[parent] || remove_var_prefix(parent) if parent
73
73
  obj.add_file(@file)
74
- find_namespace_docstring(obj)
74
+ find_namespace_docstring(obj)
75
75
  @namespaces[var_name] = obj
76
76
  end
77
-
78
- # @todo Handle +source_file+
77
+
79
78
  def handle_method(scope, var_name, name, func_name, source_file = nil)
80
79
  case scope
81
80
  when "singleton_method", "module_function"; scope = :class
82
81
  else; scope = :instance
83
82
  end
84
-
83
+
85
84
  namespace = @namespaces[var_name] || P(remove_var_prefix(var_name))
86
85
  ensure_loaded!(namespace)
87
86
  obj = CodeObjects::MethodObject.new(namespace, name, scope)
@@ -89,9 +88,19 @@ module YARD
89
88
  obj.parameters = []
90
89
  obj.docstring.add_tag(YARD::Tags::Tag.new(:return, '', 'Boolean')) if name =~ /\?$/
91
90
  obj.source_type = :c
92
- find_method_body(obj, func_name)
91
+
92
+ content = nil
93
+ begin
94
+ content = File.read(source_file) if source_file
95
+ rescue Errno::ENOENT
96
+ path = "#{namespace}#{scope == :instance ? '#' : '.'}#{name}"
97
+ log.warn "Missing source file `#{source_file}' when parsing #{path}"
98
+ ensure
99
+ content ||= @content
100
+ end
101
+ find_method_body(obj, func_name, content)
93
102
  end
94
-
103
+
95
104
  def handle_constants(type, var_name, const_name, definition)
96
105
  namespace = @namespaces[var_name]
97
106
  obj = CodeObjects::ConstantObject.new(namespace, const_name)
@@ -118,7 +127,7 @@ module YARD
118
127
 
119
128
  obj.docstring = comment
120
129
  end
121
-
130
+
122
131
  def find_namespace_docstring(object)
123
132
  comment = nil
124
133
  if @content =~ %r{((?>/\*.*?\*/\s+))
@@ -129,7 +138,7 @@ module YARD
129
138
  end
130
139
  object.docstring = parse_comments(object, comment) if comment
131
140
  end
132
-
141
+
133
142
  def find_constant_docstring(object, type, const_name)
134
143
  comment = if @content =~ %r{((?>^\s*/\*.*?\*/\s+))
135
144
  rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi
@@ -141,7 +150,7 @@ module YARD
141
150
  end
142
151
  object.docstring = parse_comments(object, comment) if comment
143
152
  end
144
-
153
+
145
154
  def find_method_body(object, func_name, content = @content)
146
155
  case content
147
156
  when %r"((?>/\*.*?\*/\s*))(?:(?:static|SWIGINTERN)\s+)?(?:intern\s+)?VALUE\s+#{func_name}
@@ -188,7 +197,7 @@ module YARD
188
197
  nil
189
198
  end
190
199
  end
191
-
200
+
192
201
  def parse_comments(object, comments)
193
202
  spaces = nil
194
203
  comments = remove_private_comments(comments)
@@ -207,7 +216,7 @@ module YARD
207
216
  comments = parse_callseq(object, comments)
208
217
  comments.join("\n")
209
218
  end
210
-
219
+
211
220
  def parse_callseq(object, comments)
212
221
  return comments unless comments[0] =~ /\Acall-seq:\s*(\S.+)?/
213
222
  if $1
@@ -247,10 +256,10 @@ module YARD
247
256
  overloads << " @yield [#{blkparams}]" if blk
248
257
  overloads << " @return [#{types.join(', ')}]" unless types.empty?
249
258
  end
250
-
259
+
251
260
  comments + [""] + overloads
252
261
  end
253
-
262
+
254
263
  def parse_types(object, types)
255
264
  if types =~ /true or false/
256
265
  ["Boolean"]
@@ -288,7 +297,7 @@ module YARD
288
297
  end.compact
289
298
  end
290
299
  end
291
-
300
+
292
301
  def parse_modules
293
302
  @content.scan(/(\w+)\s* = \s*rb_define_module\s*
294
303
  \(\s*"(\w+)"\s*\)/mx) do |var_name, class_name|
@@ -303,7 +312,7 @@ module YARD
303
312
  handle_module(var_name, class_name, in_module)
304
313
  end
305
314
  end
306
-
315
+
307
316
  def parse_classes
308
317
  # The '.' lets us handle SWIG-generated files
309
318
  @content.scan(/([\w\.]+)\s* = \s*(?:rb_define_class|boot_defclass)\s*
@@ -323,7 +332,7 @@ module YARD
323
332
  handle_class(var_name, class_name, parent, in_module)
324
333
  end
325
334
  end
326
-
335
+
327
336
  def parse_methods
328
337
  @content.scan(%r{rb_define_
329
338
  (
@@ -357,7 +366,7 @@ module YARD
357
366
  handle_method("method", "rb_mKernel", name, func_name, source_file)
358
367
  end
359
368
  end
360
-
369
+
361
370
  def parse_includes
362
371
  @content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |klass, mod|
363
372
  if klass = @namespaces[klass]
@@ -366,7 +375,7 @@ module YARD
366
375
  end
367
376
  end
368
377
  end
369
-
378
+
370
379
  def parse_constants
371
380
  @content.scan(%r{\Wrb_define_
372
381
  (
@@ -384,20 +393,20 @@ module YARD
384
393
  handle_constants(type, var_name, const_name, definition)
385
394
  end
386
395
  end
387
-
396
+
388
397
  private
389
-
398
+
390
399
  def clean_source(source)
391
400
  source = handle_ifdefs_in(source)
392
401
  source = handle_tab_width(source)
393
402
  source = remove_commented_out_lines(source)
394
403
  source
395
404
  end
396
-
405
+
397
406
  def handle_ifdefs_in(body)
398
407
  body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m, '\1')
399
408
  end
400
-
409
+
401
410
  def handle_tab_width(body)
402
411
  if /\t/ =~ body
403
412
  tab_width = 4
@@ -409,11 +418,11 @@ module YARD
409
418
  body
410
419
  end
411
420
  end
412
-
421
+
413
422
  def remove_commented_out_lines(body)
414
423
  body.gsub(%r{//.*rb_define_}, '//')
415
424
  end
416
-
425
+
417
426
  def remove_private_comments(comment)
418
427
  comment = comment.gsub(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
419
428
  comment = comment.sub(/\/?\*--\n.*/m, '')