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.
- data/.yardopts +1 -0
- data/ChangeLog +723 -0
- data/README.md +16 -6
- data/docs/CodeObjects.md +10 -16
- data/docs/GettingStarted.md +232 -32
- data/docs/Glossary.md +1 -2
- data/docs/Handlers.md +10 -16
- data/docs/Overview.md +14 -13
- data/docs/Parser.md +13 -22
- data/docs/Tags.md +209 -16
- data/docs/Templates.md +237 -26
- data/docs/WhatsNew.md +178 -2
- data/lib/yard.rb +13 -10
- data/lib/yard/autoload.rb +22 -18
- data/lib/yard/cli/command.rb +13 -12
- data/lib/yard/cli/command_parser.rb +20 -19
- data/lib/yard/cli/config.rb +19 -19
- data/lib/yard/cli/diff.rb +46 -21
- data/lib/yard/cli/gems.rb +11 -11
- data/lib/yard/cli/graph.rb +13 -13
- data/lib/yard/cli/help.rb +1 -1
- data/lib/yard/cli/list.rb +22 -0
- data/lib/yard/cli/server.rb +17 -17
- data/lib/yard/cli/stats.rb +32 -32
- data/lib/yard/cli/yardoc.rb +181 -135
- data/lib/yard/cli/yri.rb +29 -29
- data/lib/yard/code_objects/base.rb +101 -101
- data/lib/yard/code_objects/class_object.rb +20 -20
- data/lib/yard/code_objects/constant_object.rb +1 -1
- data/lib/yard/code_objects/extended_method_object.rb +5 -5
- data/lib/yard/code_objects/extra_file_object.rb +89 -0
- data/lib/yard/code_objects/macro_object.rb +215 -0
- data/lib/yard/code_objects/method_object.rb +30 -30
- data/lib/yard/code_objects/module_object.rb +1 -1
- data/lib/yard/code_objects/namespace_object.rb +39 -39
- data/lib/yard/code_objects/proxy.rb +38 -38
- data/lib/yard/code_objects/root_object.rb +1 -1
- data/lib/yard/config.rb +40 -40
- data/lib/yard/core_ext/array.rb +2 -2
- data/lib/yard/core_ext/file.rb +11 -11
- data/lib/yard/core_ext/insertion.rb +10 -10
- data/lib/yard/core_ext/module.rb +2 -2
- data/lib/yard/core_ext/string.rb +2 -2
- data/lib/yard/core_ext/symbol_hash.rb +14 -14
- data/lib/yard/docstring.rb +122 -54
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +216 -127
- data/lib/yard/handlers/processor.rb +65 -27
- data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
- data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
- data/lib/yard/handlers/ruby/base.rb +50 -31
- data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
- data/lib/yard/handlers/ruby/class_handler.rb +10 -10
- data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
- data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
- data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
- data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
- data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
- data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
- data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
- data/lib/yard/handlers/ruby/method_handler.rb +13 -13
- data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
- data/lib/yard/handlers/ruby/module_handler.rb +2 -1
- data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
- data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
- data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
- data/lib/yard/logging.rb +11 -11
- data/lib/yard/parser/base.rb +8 -8
- data/lib/yard/parser/c_parser.rb +42 -33
- data/lib/yard/parser/ruby/ast_node.rb +62 -61
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
- data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
- data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
- data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
- data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
- data/lib/yard/parser/source_parser.rb +271 -46
- data/lib/yard/rake/yardoc_task.rb +18 -17
- data/lib/yard/registry.rb +64 -64
- data/lib/yard/registry_store.rb +34 -34
- data/lib/yard/rubygems/backports.rb +8 -0
- data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
- data/lib/yard/rubygems/backports/MIT.txt +20 -0
- data/lib/yard/rubygems/backports/gem.rb +8 -0
- data/lib/yard/rubygems/backports/source_index.rb +353 -0
- data/lib/yard/rubygems/specification.rb +2 -2
- data/lib/yard/serializers/base.rb +20 -20
- data/lib/yard/serializers/file_system_serializer.rb +28 -24
- data/lib/yard/serializers/process_serializer.rb +3 -3
- data/lib/yard/serializers/stdout_serializer.rb +6 -6
- data/lib/yard/serializers/yardoc_serializer.rb +17 -17
- data/lib/yard/server/adapter.rb +12 -12
- data/lib/yard/server/commands/base.rb +26 -26
- data/lib/yard/server/commands/display_file_command.rb +3 -2
- data/lib/yard/server/commands/display_object_command.rb +5 -5
- data/lib/yard/server/commands/frames_command.rb +1 -1
- data/lib/yard/server/commands/library_command.rb +7 -7
- data/lib/yard/server/commands/library_index_command.rb +2 -2
- data/lib/yard/server/commands/list_command.rb +8 -8
- data/lib/yard/server/commands/search_command.rb +8 -8
- data/lib/yard/server/commands/static_file_command.rb +3 -3
- data/lib/yard/server/doc_server_helper.rb +6 -3
- data/lib/yard/server/doc_server_serializer.rb +1 -1
- data/lib/yard/server/library_version.rb +45 -45
- data/lib/yard/server/rack_adapter.rb +10 -10
- data/lib/yard/server/router.rb +28 -28
- data/lib/yard/server/static_caching.rb +5 -5
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
- data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
- data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
- data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
- data/lib/yard/server/webrick_adapter.rb +2 -2
- data/lib/yard/tags/default_factory.rb +19 -19
- data/lib/yard/tags/default_tag.rb +1 -1
- data/lib/yard/tags/library.rb +68 -63
- data/lib/yard/tags/option_tag.rb +1 -1
- data/lib/yard/tags/overload_tag.rb +9 -9
- data/lib/yard/tags/ref_tag_list.rb +2 -2
- data/lib/yard/tags/tag.rb +7 -7
- data/lib/yard/templates/engine.rb +31 -31
- data/lib/yard/templates/erb_cache.rb +1 -1
- data/lib/yard/templates/helpers/base_helper.rb +46 -32
- data/lib/yard/templates/helpers/filter_helper.rb +2 -2
- data/lib/yard/templates/helpers/html_helper.rb +120 -81
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
- data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
- data/lib/yard/templates/helpers/markup_helper.rb +37 -30
- data/lib/yard/templates/helpers/method_helper.rb +7 -7
- data/lib/yard/templates/helpers/text_helper.rb +7 -7
- data/lib/yard/templates/helpers/uml_helper.rb +3 -3
- data/lib/yard/templates/section.rb +14 -14
- data/lib/yard/templates/template.rb +54 -54
- data/lib/yard/verifier.rb +27 -27
- data/spec/cli/list_spec.rb +8 -0
- data/spec/cli/yardoc_spec.rb +58 -10
- data/spec/code_objects/extra_file_object_spec.rb +132 -0
- data/spec/code_objects/macro_object_spec.rb +154 -0
- data/spec/docstring_spec.rb +90 -0
- data/spec/handlers/base_spec.rb +22 -0
- data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
- data/spec/handlers/macro_handler_spec.rb +140 -0
- data/spec/handlers/method_handler_spec.rb +28 -0
- data/spec/handlers/processor_spec.rb +4 -0
- data/spec/handlers/spec_helper.rb +1 -1
- data/spec/parser/c_parser_spec.rb +47 -16
- data/spec/parser/examples/extrafile.c.txt +8 -0
- data/spec/parser/examples/multifile.c.txt +6 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
- data/spec/parser/source_parser_spec.rb +235 -0
- data/spec/rake/yardoc_task_spec.rb +22 -17
- data/spec/serializers/file_system_serializer_spec.rb +6 -0
- data/spec/server/commands/library_command_spec.rb +39 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/templates/examples/method001.html +6 -6
- data/spec/templates/examples/method002.html +4 -4
- data/spec/templates/examples/method003.html +10 -10
- data/spec/templates/examples/method005.html +2 -2
- data/spec/templates/examples/module001.dot +2 -0
- data/spec/templates/examples/module001.html +76 -37
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/helpers/base_helper_spec.rb +7 -2
- data/spec/templates/helpers/html_helper_spec.rb +49 -5
- data/spec/templates/helpers/markup_helper_spec.rb +9 -8
- data/spec/templates/module_spec.rb +7 -0
- data/spec/templates/onefile_spec.rb +47 -0
- data/templates/default/fulldoc/html/css/style.css +7 -5
- data/templates/default/fulldoc/html/full_list.erb +13 -10
- data/templates/default/fulldoc/html/full_list_files.erb +1 -1
- data/templates/default/fulldoc/html/js/app.js +16 -14
- data/templates/default/fulldoc/html/js/full_list.js +7 -6
- data/templates/default/fulldoc/html/setup.rb +78 -17
- data/templates/default/layout/html/files.erb +1 -1
- data/templates/default/layout/html/headers.erb +11 -7
- data/templates/default/layout/html/search.erb +4 -4
- data/templates/default/layout/html/setup.rb +28 -8
- data/templates/default/module/html/inherited_attributes.erb +17 -0
- data/templates/default/module/setup.rb +1 -1
- data/templates/default/onefile/html/files.erb +2 -2
- data/templates/default/onefile/html/layout.erb +1 -1
- data/templates/default/onefile/html/setup.rb +7 -5
- data/templates/default/tags/html/option.erb +1 -1
- data/templates/default/tags/html/tag.erb +3 -3
- data/templates/guide/class/html/setup.rb +1 -0
- data/templates/guide/docstring/html/setup.rb +1 -0
- data/templates/guide/fulldoc/html/css/style.css +91 -0
- data/templates/guide/fulldoc/html/js/app.js +33 -0
- data/templates/guide/fulldoc/html/setup.rb +54 -0
- data/templates/guide/layout/html/layout.erb +81 -0
- data/templates/guide/layout/html/setup.rb +24 -0
- data/templates/guide/method/html/header.erb +18 -0
- data/templates/guide/method/html/setup.rb +21 -0
- data/templates/guide/module/html/header.erb +7 -0
- data/templates/guide/module/html/method_list.erb +5 -0
- data/templates/guide/module/html/setup.rb +26 -0
- data/templates/guide/tags/html/setup.rb +8 -0
- metadata +40 -7
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
- data/lib/yard/handlers/ruby/process_handler.rb +0 -18
- data/spec/handlers/process_handler_spec.rb +0 -17
@@ -1,9 +1,9 @@
|
|
1
1
|
# Handles class declarations
|
2
2
|
class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
3
3
|
include YARD::Handlers::Ruby::StructHandlerMethods
|
4
|
-
namespace_only
|
5
4
|
handles :class, :sclass
|
6
|
-
|
5
|
+
namespace_only
|
6
|
+
|
7
7
|
process do
|
8
8
|
if statement.type == :class
|
9
9
|
classname = statement[0].source
|
@@ -24,7 +24,7 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
24
24
|
create_attributes(klass, members_from_tags(klass))
|
25
25
|
end
|
26
26
|
parse_block(statement[2], :namespace => klass)
|
27
|
-
|
27
|
+
|
28
28
|
if undocsuper
|
29
29
|
raise YARD::Parser::UndocumentableError, 'superclass (class was added without superclass)'
|
30
30
|
end
|
@@ -56,9 +56,9 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
56
56
|
raise YARD::Parser::UndocumentableError, "class: #{statement.source[0..sig_end]}"
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
private
|
61
|
-
|
61
|
+
|
62
62
|
# Extract the parameters from the Struct.new AST node, returning them as a list
|
63
63
|
# of strings
|
64
64
|
#
|
@@ -69,7 +69,7 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
69
69
|
members.map! {|x| x.source.strip[1..-1]}
|
70
70
|
members
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def create_struct_superclass(superclass, superclass_def)
|
74
74
|
return if superclass == "Struct"
|
75
75
|
the_super = register ClassObject.new(P("Struct"), superclass[8..-1]) do |o|
|
@@ -78,7 +78,7 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
78
78
|
parse_struct_superclass(the_super, superclass_def)
|
79
79
|
the_super
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def struct_superclass_name(superclass)
|
83
83
|
if superclass.call?
|
84
84
|
first = superclass.parameters.first
|
@@ -88,16 +88,16 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
88
88
|
end
|
89
89
|
"Struct"
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def parse_struct_superclass(klass, superclass)
|
93
93
|
return unless superclass.call? && superclass.parameters
|
94
94
|
members = extract_parameters(superclass)
|
95
95
|
create_attributes(klass, members)
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def parse_superclass(superclass)
|
99
99
|
return nil unless superclass
|
100
|
-
|
100
|
+
|
101
101
|
case superclass.type
|
102
102
|
when :var_ref
|
103
103
|
return namespace.path if superclass.first == s(:kw, "self")
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# Handles a class variable (@@variable)
|
2
2
|
class YARD::Handlers::Ruby::ClassVariableHandler < YARD::Handlers::Ruby::Base
|
3
|
-
namespace_only
|
4
3
|
handles :assign
|
5
|
-
|
4
|
+
namespace_only
|
5
|
+
|
6
6
|
process do
|
7
7
|
if statement[0].type == :var_field && statement[0][0].type == :cvar
|
8
8
|
name = statement[0][0][0]
|
9
9
|
value = statement[1].source
|
10
|
-
register ClassVariableObject.new(namespace, name) do |o|
|
10
|
+
register ClassVariableObject.new(namespace, name) do |o|
|
11
11
|
o.source = statement
|
12
12
|
o.value = value
|
13
13
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
# Handles any constant assignment
|
2
2
|
class YARD::Handlers::Ruby::ConstantHandler < YARD::Handlers::Ruby::Base
|
3
3
|
include YARD::Handlers::Ruby::StructHandlerMethods
|
4
|
-
namespace_only
|
5
4
|
handles :assign
|
6
|
-
|
5
|
+
namespace_only
|
6
|
+
|
7
7
|
process do
|
8
|
-
if statement[1].call? && statement[1][0][0] == s(:const, "Struct") &&
|
8
|
+
if statement[1].call? && statement[1][0][0] == s(:const, "Struct") &&
|
9
9
|
statement[1][2] == s(:ident, "new")
|
10
10
|
process_structclass(statement)
|
11
11
|
elsif statement[0].type == :var_field && statement[0][0].type == :const
|
12
12
|
process_constant(statement)
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
private
|
17
|
-
|
17
|
+
|
18
18
|
def process_constant(statement)
|
19
19
|
name = statement[0][0][0]
|
20
20
|
value = statement[1].source
|
21
21
|
register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip }
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def process_structclass(statement)
|
25
25
|
lhs = statement[0][0]
|
26
26
|
if lhs.type == :const
|
@@ -30,7 +30,7 @@ class YARD::Handlers::Ruby::ConstantHandler < YARD::Handlers::Ruby::Base
|
|
30
30
|
raise YARD::Parser::UndocumentableError, "Struct assignment to #{statement[0].source}"
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Extract the parameters from the Struct.new AST node, returning them as a list
|
35
35
|
# of strings
|
36
36
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Handles 'raise' calls inside methods
|
2
2
|
class YARD::Handlers::Ruby::ExceptionHandler < YARD::Handlers::Ruby::Base
|
3
3
|
handles method_call(:raise)
|
4
|
-
|
4
|
+
|
5
5
|
process do
|
6
6
|
return unless owner.is_a?(MethodObject) # Only methods yield
|
7
7
|
return if [:command_call, :call].include? statement.type
|
@@ -9,7 +9,7 @@ class YARD::Handlers::Ruby::ExceptionHandler < YARD::Handlers::Ruby::Base
|
|
9
9
|
|
10
10
|
klass = nil
|
11
11
|
params = statement.parameters(false)
|
12
|
-
if params.size == 1
|
12
|
+
if params.size == 1
|
13
13
|
if params.first.ref? && params.first.first.type != :ident
|
14
14
|
klass = params.first.source
|
15
15
|
elsif params.first.call? && params.first.method_name(true) == :new
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Handles 'extend' call to include modules into the class scope of another
|
2
2
|
# @see MixinHandler
|
3
3
|
class YARD::Handlers::Ruby::ExtendHandler < YARD::Handlers::Ruby::MixinHandler
|
4
|
-
namespace_only
|
5
4
|
handles method_call(:extend)
|
5
|
+
namespace_only
|
6
6
|
|
7
7
|
def scope; :class end
|
8
8
|
|
@@ -1,22 +1,23 @@
|
|
1
1
|
# (see Ruby::AliasHandler)
|
2
2
|
class YARD::Handlers::Ruby::Legacy::AliasHandler < YARD::Handlers::Ruby::Legacy::Base
|
3
3
|
handles /\Aalias(_method)?(\s|\()/
|
4
|
-
|
4
|
+
namespace_only
|
5
|
+
|
5
6
|
process do
|
6
|
-
if TkALIAS === statement.tokens.first
|
7
|
+
if TkALIAS === statement.tokens.first
|
7
8
|
tokens = statement.tokens[2..-1].to_s.split(/\s+/)
|
8
9
|
names = [tokens[0], tokens[1]].map {|t| t.gsub(/^:(['"])?(.+?)\1?$|^(:)(.+)/, '\2') }
|
9
10
|
else
|
10
11
|
names = tokval_list(statement.tokens[2..-1], :attr)
|
11
12
|
end
|
12
13
|
raise YARD::Parser::UndocumentableError, statement.tokens.first.text if names.size != 2
|
13
|
-
|
14
|
+
|
14
15
|
new_meth, old_meth = names[0].to_sym, names[1].to_sym
|
15
16
|
old_obj = namespace.child(:name => old_meth, :scope => scope)
|
16
17
|
new_obj = register MethodObject.new(namespace, new_meth, scope) do |o|
|
17
18
|
o.visibility = visibility
|
18
19
|
o.scope = scope
|
19
|
-
o.add_file(parser.file, statement.tokens.first.line_no)
|
20
|
+
o.add_file(parser.file, statement.tokens.first.line_no, statement.comments)
|
20
21
|
o.docstring = statement.comments
|
21
22
|
end
|
22
23
|
|
@@ -24,11 +25,13 @@ class YARD::Handlers::Ruby::Legacy::AliasHandler < YARD::Handlers::Ruby::Legacy:
|
|
24
25
|
new_obj.signature = old_obj.signature
|
25
26
|
new_obj.source = old_obj.source
|
26
27
|
new_obj.docstring = old_obj.docstring + YARD::Docstring.new(statement.comments)
|
28
|
+
new_obj.docstring.line_range = statement.comments_range
|
29
|
+
new_obj.docstring.hash_flag = statement.comments_hash_flag
|
27
30
|
new_obj.docstring.object = new_obj
|
28
31
|
else
|
29
32
|
new_obj.signature = "def #{new_meth}" # this is all we know.
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
namespace.aliases[new_obj] = old_meth
|
33
36
|
end
|
34
37
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# (see Ruby::AttributeHandler)
|
2
2
|
class YARD::Handlers::Ruby::Legacy::AttributeHandler < YARD::Handlers::Ruby::Legacy::Base
|
3
3
|
handles /\Aattr(?:_(?:reader|writer|accessor))?(?:\s|\()/
|
4
|
-
|
4
|
+
namespace_only
|
5
|
+
|
5
6
|
process do
|
6
7
|
begin
|
7
8
|
attr_type = statement.tokens.first.text.to_sym
|
@@ -10,7 +11,7 @@ class YARD::Handlers::Ruby::Legacy::AttributeHandler < YARD::Handlers::Ruby::Leg
|
|
10
11
|
rescue SyntaxError
|
11
12
|
raise YARD::Parser::UndocumentableError, attr_type
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
# Change read/write based on attr_reader/writer/accessor
|
15
16
|
case attr_type
|
16
17
|
when :attr
|
@@ -25,9 +26,9 @@ class YARD::Handlers::Ruby::Legacy::AttributeHandler < YARD::Handlers::Ruby::Leg
|
|
25
26
|
end
|
26
27
|
|
27
28
|
# Add all attributes
|
28
|
-
symbols.each do |name|
|
29
|
+
symbols.each do |name|
|
29
30
|
namespace.attributes[scope][name] = SymbolHash[:read => nil, :write => nil]
|
30
|
-
|
31
|
+
|
31
32
|
# Show their methods as well
|
32
33
|
{:read => name, :write => "#{name}="}.each do |type, meth|
|
33
34
|
if (type == :read ? read : write)
|
@@ -47,7 +48,7 @@ class YARD::Handlers::Ruby::Legacy::AttributeHandler < YARD::Handlers::Ruby::Leg
|
|
47
48
|
o.docstring = statement.comments.to_s.empty? ? doc : statement.comments
|
48
49
|
o.visibility = visibility
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
# Register the objects explicitly
|
52
53
|
register namespace.attributes[scope][name][type]
|
53
54
|
elsif obj = namespace.children.find {|o| o.name == meth.to_sym && o.scope == scope }
|
@@ -3,12 +3,12 @@ module YARD
|
|
3
3
|
module Ruby::Legacy
|
4
4
|
# This is the base handler for the legacy parser. To implement a legacy
|
5
5
|
# handler, subclass this class.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# @abstract (see Ruby::Base)
|
8
8
|
class Base < Handlers::Base
|
9
9
|
# For tokens like TkDEF, TkCLASS, etc.
|
10
10
|
include YARD::Parser::Ruby::Legacy::RubyToken
|
11
|
-
|
11
|
+
|
12
12
|
# @return [Boolean] whether or not a {Parser::Ruby::Legacy::Statement} object should be handled
|
13
13
|
# by this handler.
|
14
14
|
def self.handles?(stmt)
|
@@ -19,17 +19,17 @@ module YARD
|
|
19
19
|
when Regexp
|
20
20
|
stmt.tokens.to_s =~ a_handler
|
21
21
|
else
|
22
|
-
a_handler == stmt.tokens.first.class
|
22
|
+
a_handler == stmt.tokens.first.class
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
protected
|
28
28
|
|
29
|
-
# Parses a statement's block with a set of state values. If the
|
29
|
+
# Parses a statement's block with a set of state values. If the
|
30
30
|
# statement has no block, nothing happens. A description of state
|
31
31
|
# values can be found at {Handlers::Base#push_state}
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# @param [Hash] opts State options
|
34
34
|
# @option opts (see Handlers::Base#push_state)
|
35
35
|
# @see Handlers::Base#push_state #push_state
|
@@ -42,37 +42,52 @@ module YARD
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def call_params
|
46
|
+
tokens = statement.tokens[1..-1]
|
47
|
+
tokval_list(tokens, :attr, :identifier, TkId).map do |value|
|
48
|
+
value.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def caller_method
|
53
|
+
if statement.tokens.first.is_a?(TkIDENTIFIER)
|
54
|
+
statement.tokens.first.text
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
45
60
|
private
|
46
|
-
|
47
|
-
# The string value of a token. For example, the return value for the symbol :sym
|
48
|
-
# would be :sym. The return value for a string +"foo #{ bar}"+ would be the literal
|
61
|
+
|
62
|
+
# The string value of a token. For example, the return value for the symbol :sym
|
63
|
+
# would be :sym. The return value for a string +"foo #{ bar}"+ would be the literal
|
49
64
|
# +"foo #{ bar}"+ without any interpolation. The return value of the identifier
|
50
65
|
# 'test' would be the same value: 'test'. Here is a list of common types and
|
51
66
|
# their return values:
|
52
|
-
#
|
53
|
-
# @example
|
67
|
+
#
|
68
|
+
# @example
|
54
69
|
# tokval(TokenList.new('"foo"').first) => "foo"
|
55
70
|
# tokval(TokenList.new(':foo').first) => :foo
|
56
71
|
# tokval(TokenList.new('CONSTANT').first, RubyToken::TkId) => "CONSTANT"
|
57
72
|
# tokval(TokenList.new('identifier').first, RubyToken::TkId) => "identifier"
|
58
73
|
# tokval(TokenList.new('3.25').first) => 3.25
|
59
74
|
# tokval(TokenList.new('/xyz/i').first) => /xyz/i
|
60
|
-
#
|
75
|
+
#
|
61
76
|
# @param [Token] token The token of the class
|
62
|
-
#
|
77
|
+
#
|
63
78
|
# @param [Array<Class<Token>>, Symbol] accepted_types
|
64
79
|
# The allowed token types that this token can be. Defaults to [{TkVal}].
|
65
80
|
# A list of types would be, for example, [+TkSTRING+, +TkSYMBOL+], to return
|
66
|
-
# the token's value if it is either of those types. If +TkVal+ is accepted,
|
81
|
+
# the token's value if it is either of those types. If +TkVal+ is accepted,
|
67
82
|
# +TkNode+ is also accepted.
|
68
|
-
#
|
83
|
+
#
|
69
84
|
# Certain symbol keys are allowed to specify multiple types in one fell swoop.
|
70
85
|
# These symbols are:
|
71
86
|
# :string => +TkSTRING+, +TkDSTRING+, +TkDXSTRING+ and +TkXSTRING+
|
72
87
|
# :attr => +TkSYMBOL+ and +TkSTRING+
|
73
88
|
# :identifier => +TkIDENTIFIER, +TkFID+ and +TkGVAR+.
|
74
89
|
# :number => +TkFLOAT+, +TkINTEGER+
|
75
|
-
#
|
90
|
+
#
|
76
91
|
# @return [Object] if the token is one of the accepted types, in its real value form.
|
77
92
|
# It should be noted that identifiers and constants are kept in String form.
|
78
93
|
# @return [nil] if the token is not any of the specified accepted types
|
@@ -99,7 +114,7 @@ module YARD
|
|
99
114
|
return unless accepted_types.any? {|t| t === token }
|
100
115
|
|
101
116
|
case token
|
102
|
-
when TkSTRING, TkDSTRING, TkXSTRING, TkDXSTRING
|
117
|
+
when TkSTRING, TkDSTRING, TkXSTRING, TkDXSTRING
|
103
118
|
token.text[1..-2]
|
104
119
|
when TkSYMBOL
|
105
120
|
token.text[1..-1].to_sym
|
@@ -121,26 +136,26 @@ module YARD
|
|
121
136
|
end
|
122
137
|
end
|
123
138
|
|
124
|
-
# Returns a list of symbols or string values from a statement.
|
125
|
-
# The list must be a valid comma delimited list, and values
|
139
|
+
# Returns a list of symbols or string values from a statement.
|
140
|
+
# The list must be a valid comma delimited list, and values
|
126
141
|
# will only be returned to the end of the list only.
|
127
|
-
#
|
142
|
+
#
|
128
143
|
# Example:
|
129
144
|
# attr_accessor :a, 'b', :c, :d => ['a', 'b', 'c', 'd']
|
130
|
-
# attr_accessor 'a', UNACCEPTED_TYPE, 'c' => ['a', 'c']
|
131
|
-
#
|
145
|
+
# attr_accessor 'a', UNACCEPTED_TYPE, 'c' => ['a', 'c']
|
146
|
+
#
|
132
147
|
# The tokval list of a {Parser::Ruby::Legacy::TokenList} of the above
|
133
148
|
# code would be the {#tokval} value of :a, 'b',
|
134
149
|
# :c and :d.
|
135
|
-
#
|
150
|
+
#
|
136
151
|
# It should also be noted that this function stops immediately at
|
137
152
|
# any ruby keyword encountered:
|
138
153
|
# "attr_accessor :a, :b, :c if x == 5" => ['a', 'b', 'c']
|
139
|
-
#
|
154
|
+
#
|
140
155
|
# @param [TokenList] tokenlist The list of tokens to process.
|
141
156
|
# @param [Array<Class<Token>>] accepted_types passed to {#tokval}
|
142
157
|
# @return [Array<String>] the list of tokvalues in the list.
|
143
|
-
# @return [Array<EMPTY>] if there are no symbols or Strings in the list
|
158
|
+
# @return [Array<EMPTY>] if there are no symbols or Strings in the list
|
144
159
|
# @see #tokval
|
145
160
|
def tokval_list(tokenlist, *accepted_types)
|
146
161
|
return [] unless tokenlist
|
@@ -176,7 +191,7 @@ module YARD
|
|
176
191
|
parencount -= 1
|
177
192
|
end
|
178
193
|
when TkLBRACE, TkLBRACK, TkDO
|
179
|
-
parencount += 1
|
194
|
+
parencount += 1
|
180
195
|
out.last << token.text if tokval != nil
|
181
196
|
when TkRBRACE, TkRBRACK, TkEND
|
182
197
|
out.last << token.text if tokval != nil
|
@@ -186,14 +201,14 @@ module YARD
|
|
186
201
|
|
187
202
|
seen_comma = false unless TkWhitespace === token
|
188
203
|
if parencount == 0
|
189
|
-
next if needcomma
|
204
|
+
next if needcomma
|
190
205
|
next if TkWhitespace === token
|
191
206
|
if tokval != nil
|
192
207
|
out.last << tokval
|
193
208
|
else
|
194
209
|
out.last.clear
|
195
210
|
needcomma = true
|
196
|
-
end
|
211
|
+
end
|
197
212
|
elsif parencond
|
198
213
|
needcomma = true
|
199
214
|
out.last << token.text
|
@@ -3,7 +3,7 @@
|
|
3
3
|
class YARD::Handlers::Ruby::Legacy::ClassConditionHandler < YARD::Handlers::Ruby::Legacy::Base
|
4
4
|
namespace_only
|
5
5
|
handles TkIF, TkELSIF, TkUNLESS
|
6
|
-
|
6
|
+
|
7
7
|
process do
|
8
8
|
condition = parse_condition
|
9
9
|
if condition == nil
|
@@ -16,25 +16,25 @@ class YARD::Handlers::Ruby::Legacy::ClassConditionHandler < YARD::Handlers::Ruby
|
|
16
16
|
parse_else_block
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
protected
|
21
|
-
|
21
|
+
|
22
22
|
# Parses the condition part of the if/unless statement
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# @return [true, false, nil] true if the condition can be definitely
|
25
25
|
# parsed to true, false if not, and nil if the condition cannot be
|
26
26
|
# parsed with certainty (it's dynamic)
|
27
27
|
# @since 0.5.5
|
28
28
|
def parse_condition
|
29
29
|
condition = nil
|
30
|
-
|
30
|
+
|
31
31
|
# Right now we can handle very simple unary conditions like:
|
32
32
|
# if true
|
33
33
|
# if false
|
34
34
|
# if 0
|
35
35
|
# if 100 (not 0)
|
36
36
|
# if defined? SOME_CONSTANT
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# The last case will do a lookup in the registry and then one
|
39
39
|
# in the Ruby world (using eval).
|
40
40
|
case statement.tokens[1..-1].to_s.strip
|
@@ -56,18 +56,18 @@ class YARD::Handlers::Ruby::Legacy::ClassConditionHandler < YARD::Handlers::Ruby
|
|
56
56
|
when "false"
|
57
57
|
condition = false
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
if TkUNLESS === statement.tokens.first
|
61
61
|
condition = !condition if condition != nil
|
62
62
|
end
|
63
63
|
condition
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
# @since 0.5.5
|
67
67
|
def parse_then_block
|
68
68
|
parse_block
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# @since 0.5.5
|
72
72
|
def parse_else_block
|
73
73
|
return unless statement.block
|