yard 0.2.3.5 → 0.4.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 +12 -10
- data/ChangeLog +5686 -0
- data/{README.markdown → README.md} +65 -11
- data/Rakefile +25 -13
- data/benchmarks/concat_vs_join.rb +12 -0
- data/benchmarks/erb_vs_erubis.rb +14 -14
- data/benchmarks/marshal_vs_dbm.rb +1 -1
- data/benchmarks/pathname_vs_string.rb +50 -0
- data/benchmarks/template_erb.rb +22 -0
- data/benchmarks/template_format.rb +6 -0
- data/benchmarks/template_profile.rb +17 -0
- data/bin/yri +16 -7
- data/docs/{CODE_OBJECTS.markdown → CodeObjects.md} +0 -0
- data/docs/{GETTING_STARTED.markdown → GettingStarted.md} +49 -11
- data/docs/{GLOSSARY.markdown → Glossary.md} +0 -0
- data/docs/{HANDLERS.markdown → Handlers.md} +5 -5
- data/docs/{OVERVIEW.markdown → Overview.md} +9 -13
- data/docs/{PARSER.markdown → Parser.md} +1 -1
- data/docs/{TAGS.markdown → Tags.md} +1 -1
- data/docs/Templates.md +286 -0
- data/docs/{WHATSNEW.markdown → WhatsNew.md} +82 -2
- data/lib/rubygems_plugin.rb +17 -20
- data/lib/yard.rb +47 -1
- data/lib/yard/autoload.rb +38 -47
- data/lib/yard/cli/yard_graph.rb +36 -13
- data/lib/yard/cli/yardoc.rb +74 -12
- data/lib/yard/code_objects/base.rb +182 -14
- data/lib/yard/code_objects/class_object.rb +39 -2
- data/lib/yard/code_objects/class_variable_object.rb +4 -0
- data/lib/yard/code_objects/constant_object.rb +8 -0
- data/lib/yard/code_objects/extended_method_object.rb +14 -0
- data/lib/yard/code_objects/method_object.rb +60 -2
- data/lib/yard/code_objects/module_object.rb +6 -0
- data/lib/yard/code_objects/namespace_object.rb +99 -2
- data/lib/yard/code_objects/proxy.rb +53 -6
- data/lib/yard/code_objects/root_object.rb +2 -0
- data/lib/yard/core_ext/array.rb +61 -0
- data/lib/yard/core_ext/file.rb +21 -4
- data/lib/yard/core_ext/module.rb +11 -1
- data/lib/yard/core_ext/string.rb +13 -2
- data/lib/yard/core_ext/symbol_hash.rb +51 -3
- data/lib/yard/docstring.rb +68 -19
- data/lib/yard/globals.rb +5 -2
- data/lib/yard/handlers/base.rb +13 -3
- data/lib/yard/handlers/processor.rb +64 -2
- data/lib/yard/handlers/ruby/class_handler.rb +1 -1
- data/lib/yard/handlers/ruby/class_variable_handler.rb +5 -1
- data/lib/yard/handlers/ruby/constant_handler.rb +38 -4
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +2 -2
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +6 -3
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +21 -2
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +2 -1
- data/lib/yard/handlers/ruby/method_handler.rb +10 -0
- data/lib/yard/handlers/ruby/yield_handler.rb +2 -1
- data/lib/yard/logging.rb +17 -0
- data/lib/yard/parser/ruby/ast_node.rb +101 -0
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +2 -2
- data/lib/yard/parser/ruby/legacy/statement_list.rb +10 -9
- data/lib/yard/parser/ruby/ruby_parser.rb +32 -3
- data/lib/yard/parser/source_parser.rb +82 -5
- data/lib/yard/rake/yardoc_task.rb +38 -3
- data/lib/yard/registry.rb +112 -2
- data/lib/yard/serializers/base.rb +48 -1
- data/lib/yard/serializers/file_system_serializer.rb +23 -2
- data/lib/yard/serializers/process_serializer.rb +10 -0
- data/lib/yard/serializers/stdout_serializer.rb +11 -0
- data/lib/yard/tags/library.rb +4 -1
- data/lib/yard/tags/overload_tag.rb +3 -12
- data/lib/yard/templates/engine.rb +162 -0
- data/lib/yard/{generators → templates}/helpers/base_helper.rb +14 -13
- data/lib/yard/{generators → templates}/helpers/filter_helper.rb +1 -1
- data/lib/yard/templates/helpers/html_helper.rb +287 -0
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +29 -0
- data/lib/yard/templates/helpers/html_syntax_highlight_helper18.rb +27 -0
- data/lib/yard/{generators → templates}/helpers/markup_helper.rb +15 -11
- data/lib/yard/{generators → templates}/helpers/method_helper.rb +8 -1
- data/lib/yard/templates/helpers/module_helper.rb +15 -0
- data/lib/yard/templates/helpers/text_helper.rb +60 -0
- data/lib/yard/templates/helpers/uml_helper.rb +33 -0
- data/lib/yard/templates/template.rb +355 -0
- data/lib/yard/verifier.rb +110 -0
- data/spec/cli/yardoc_spec.rb +23 -1
- data/spec/code_objects/base_spec.rb +8 -0
- data/spec/code_objects/class_object_spec.rb +166 -156
- data/spec/code_objects/method_object_spec.rb +2 -2
- data/spec/code_objects/module_object_spec.rb +112 -110
- data/spec/code_objects/proxy_spec.rb +9 -0
- data/spec/core_ext/array_spec.rb +33 -0
- data/spec/core_ext/file_spec.rb +40 -12
- data/spec/core_ext/module_spec.rb +15 -0
- data/spec/core_ext/string_spec.rb +10 -2
- data/spec/docstring_spec.rb +157 -135
- data/spec/handlers/class_handler_spec.rb +3 -0
- data/spec/handlers/class_variable_handler_spec.rb +3 -1
- data/spec/handlers/constant_handler_spec.rb +38 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +14 -1
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +1 -0
- data/spec/handlers/examples/constant_handler_001.rb.txt +10 -1
- data/spec/handlers/examples/exception_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +15 -0
- data/spec/handlers/examples/mixin_handler_001.rb.txt +13 -0
- data/spec/handlers/exception_handler_spec.rb +4 -0
- data/spec/handlers/method_handler_spec.rb +22 -0
- data/spec/handlers/mixin_handler_spec.rb +5 -3
- data/spec/handlers/yield_handler_spec.rb +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +16 -0
- data/spec/parser/ruby/legacy/statement_list_spec.rb +36 -0
- data/spec/parser/ruby/ruby_parser_spec.rb +80 -0
- data/spec/parser/source_parser_spec.rb +48 -2
- data/spec/rake/yardoc_task_spec.rb +62 -25
- data/spec/serializers/file_system_serializer_spec.rb +1 -1
- data/spec/templates/class_spec.rb +34 -0
- data/spec/templates/engine_spec.rb +121 -0
- data/spec/templates/examples/class001.html +271 -0
- data/spec/templates/examples/class001.txt +31 -0
- data/spec/templates/examples/method001.html +96 -0
- data/spec/templates/examples/method001.txt +28 -0
- data/spec/templates/examples/method002.html +81 -0
- data/spec/templates/examples/method002.txt +20 -0
- data/spec/templates/examples/method003.html +137 -0
- data/spec/templates/examples/method003.txt +45 -0
- data/spec/templates/examples/module001.dot +31 -0
- data/spec/templates/examples/module001.html +294 -0
- data/spec/templates/examples/module001.txt +33 -0
- data/spec/templates/examples/tag001.txt +82 -0
- data/spec/templates/helpers/base_helper_spec.rb +129 -0
- data/spec/{generators → templates}/helpers/html_helper_spec.rb +73 -16
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +39 -0
- data/spec/{generators → templates}/helpers/markup_helper_spec.rb +6 -7
- data/spec/templates/method_spec.rb +75 -0
- data/spec/templates/module_spec.rb +50 -0
- data/spec/templates/spec_helper.rb +33 -0
- data/spec/templates/tag_spec.rb +39 -0
- data/spec/templates/template_spec.rb +398 -0
- data/spec/verifier_spec.rb +51 -0
- data/spec/yard_spec.rb +46 -0
- data/templates/default/class/dot/setup.rb +6 -0
- data/templates/default/class/dot/superklass.erb +3 -0
- data/templates/default/class/html/constructor_details.erb +8 -0
- data/templates/default/class/html/setup.rb +1 -0
- data/templates/default/class/html/subclasses.erb +4 -0
- data/templates/default/class/setup.rb +29 -0
- data/templates/default/class/text/setup.rb +11 -0
- data/templates/default/class/text/subclasses.erb +5 -0
- data/templates/default/docstring/html/abstract.erb +4 -0
- data/templates/default/docstring/html/deprecated.erb +1 -0
- data/templates/default/docstring/html/index.erb +5 -0
- data/templates/default/docstring/html/note.erb +6 -0
- data/templates/default/docstring/html/text.erb +1 -0
- data/templates/default/docstring/html/todo.erb +6 -0
- data/templates/default/docstring/setup.rb +39 -0
- data/templates/default/docstring/text/abstract.erb +2 -0
- data/templates/default/docstring/text/deprecated.erb +2 -0
- data/templates/default/docstring/text/index.erb +2 -0
- data/templates/default/docstring/text/note.erb +4 -0
- data/templates/default/docstring/text/text.erb +1 -0
- data/templates/default/docstring/text/todo.erb +4 -0
- data/templates/default/fulldoc/html/css/common.css +1 -0
- data/templates/default/fulldoc/html/css/full_list.css +23 -0
- data/templates/default/fulldoc/html/css/style.css +261 -0
- data/templates/default/fulldoc/html/full_list.erb +36 -0
- data/templates/default/fulldoc/html/js/app.js +91 -0
- data/templates/default/fulldoc/html/js/full_list.js +39 -0
- data/templates/default/fulldoc/html/js/jquery.js +19 -0
- data/templates/default/fulldoc/html/setup.rb +86 -0
- data/templates/default/{uml → layout}/dot/header.erb +2 -2
- data/templates/default/layout/dot/setup.rb +14 -0
- data/templates/default/layout/html/breadcrumb.erb +11 -0
- data/templates/default/layout/html/footer.erb +5 -0
- data/templates/default/layout/html/headers.erb +13 -0
- data/templates/default/layout/html/index.erb +49 -0
- data/templates/default/layout/html/layout.erb +20 -0
- data/templates/default/layout/html/search.erb +5 -0
- data/templates/default/layout/html/setup.rb +58 -0
- data/templates/default/method/html/header.erb +14 -3
- data/templates/default/method/setup.rb +3 -0
- data/templates/default/method/text/header.erb +1 -1
- data/templates/default/method_details/html/header.erb +3 -0
- data/templates/default/method_details/html/method_signature.erb +17 -0
- data/templates/default/method_details/html/source.erb +10 -0
- data/templates/default/method_details/setup.rb +8 -0
- data/templates/default/method_details/text/header.erb +10 -0
- data/templates/default/method_details/text/method_signature.erb +12 -0
- data/templates/default/method_details/text/setup.rb +10 -0
- data/templates/default/module/dot/child.erb +1 -0
- data/templates/default/module/dot/dependencies.erb +3 -0
- data/templates/default/{uml/dot/subgraph.erb → module/dot/header.erb} +3 -3
- data/templates/default/{uml → module}/dot/info.erb +4 -4
- data/templates/default/module/dot/setup.rb +14 -0
- data/templates/default/module/html/attribute_details.erb +11 -0
- data/templates/default/module/html/attribute_summary.erb +8 -0
- data/templates/default/module/html/box_info.erb +32 -0
- data/templates/default/module/html/children.erb +8 -0
- data/templates/default/module/html/constant_summary.erb +13 -0
- data/templates/default/module/html/defines.erb +3 -0
- data/templates/default/module/html/header.erb +4 -4
- data/templates/default/module/html/inherited_constants.erb +8 -0
- data/templates/default/module/html/inherited_methods.erb +9 -0
- data/templates/default/module/html/item_summary.erb +20 -0
- data/templates/default/module/html/method_details_list.erb +8 -0
- data/templates/default/module/html/method_summary.erb +8 -0
- data/templates/default/module/html/methodmissing.erb +12 -0
- data/templates/default/module/html/pre_docstring.erb +1 -0
- data/templates/default/module/setup.rb +83 -0
- data/templates/default/module/text/children.erb +10 -0
- data/templates/default/module/text/class_meths_list.erb +8 -0
- data/templates/default/module/text/extends.erb +8 -0
- data/templates/default/module/text/header.erb +7 -0
- data/templates/default/module/text/includes.erb +8 -0
- data/templates/default/module/text/instance_meths_list.erb +8 -0
- data/templates/default/module/text/setup.rb +12 -0
- data/templates/default/root/dot/child.erb +3 -0
- data/templates/default/root/dot/setup.rb +5 -0
- data/templates/default/tags/html/example.erb +5 -16
- data/templates/default/tags/html/index.erb +3 -0
- data/templates/default/tags/html/option.erb +17 -20
- data/templates/default/tags/html/overload.erb +13 -0
- data/templates/default/tags/html/see.erb +5 -10
- data/templates/default/tags/html/tag.erb +20 -0
- data/templates/default/tags/setup.rb +50 -0
- data/templates/default/tags/text/example.erb +8 -10
- data/templates/default/tags/text/index.erb +1 -0
- data/templates/default/tags/text/option.erb +18 -3
- data/templates/default/tags/text/overload.erb +19 -0
- data/templates/default/tags/text/see.erb +8 -2
- data/templates/default/tags/text/tag.erb +13 -0
- metadata +142 -158
- data/bin/view_generator +0 -17
- data/docs/FAQ.markdown +0 -34
- data/docs/GENERATORS.markdown +0 -211
- data/lib/yard/generators/attributes_generator.rb +0 -22
- data/lib/yard/generators/base.rb +0 -305
- data/lib/yard/generators/class_generator.rb +0 -27
- data/lib/yard/generators/constants_generator.rb +0 -74
- data/lib/yard/generators/constructor_generator.rb +0 -25
- data/lib/yard/generators/deprecated_generator.rb +0 -15
- data/lib/yard/generators/docstring_generator.rb +0 -15
- data/lib/yard/generators/full_doc_generator.rb +0 -127
- data/lib/yard/generators/helpers/html_helper.rb +0 -196
- data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +0 -49
- data/lib/yard/generators/helpers/uml_helper.rb +0 -16
- data/lib/yard/generators/inheritance_generator.rb +0 -16
- data/lib/yard/generators/method_details_generator.rb +0 -18
- data/lib/yard/generators/method_generator.rb +0 -43
- data/lib/yard/generators/method_listing_generator.rb +0 -105
- data/lib/yard/generators/method_missing_generator.rb +0 -25
- data/lib/yard/generators/method_signature_generator.rb +0 -19
- data/lib/yard/generators/method_summary_generator.rb +0 -21
- data/lib/yard/generators/mixins_generator.rb +0 -21
- data/lib/yard/generators/module_generator.rb +0 -23
- data/lib/yard/generators/overloads_generator.rb +0 -20
- data/lib/yard/generators/quick_doc_generator.rb +0 -25
- data/lib/yard/generators/root_generator.rb +0 -32
- data/lib/yard/generators/source_generator.rb +0 -11
- data/lib/yard/generators/tags_generator.rb +0 -99
- data/lib/yard/generators/uml_generator.rb +0 -102
- data/lib/yard/generators/visibility_group_generator.rb +0 -26
- data/spec/generators/base_spec.rb +0 -64
- data/spec/generators/full_doc_generator_spec.rb +0 -29
- data/spec/generators/helpers/base_helper_spec.rb +0 -15
- data/spec/generators/quick_doc_generator_spec.rb +0 -13
- data/templates/default/attributes/html/header.erb +0 -47
- data/templates/default/attributes/text/header.erb +0 -10
- data/templates/default/class/html/header.erb +0 -4
- data/templates/default/constants/html/constants.erb +0 -9
- data/templates/default/constants/html/header.erb +0 -3
- data/templates/default/constants/html/included.erb +0 -9
- data/templates/default/constants/html/inherited.erb +0 -9
- data/templates/default/constructor/html/header.erb +0 -10
- data/templates/default/deprecated/html/main.erb +0 -6
- data/templates/default/deprecated/text/main.erb +0 -3
- data/templates/default/docstring/html/main.erb +0 -3
- data/templates/default/docstring/text/main.erb +0 -3
- data/templates/default/fulldoc/html/all_files.erb +0 -19
- data/templates/default/fulldoc/html/all_methods.erb +0 -26
- data/templates/default/fulldoc/html/all_namespaces.erb +0 -22
- data/templates/default/fulldoc/html/app.js +0 -18
- data/templates/default/fulldoc/html/custom.css +0 -1
- data/templates/default/fulldoc/html/file.erb +0 -16
- data/templates/default/fulldoc/html/footer.erb +0 -5
- data/templates/default/fulldoc/html/header.erb +0 -16
- data/templates/default/fulldoc/html/html_head.erb +0 -4
- data/templates/default/fulldoc/html/index.erb +0 -19
- data/templates/default/fulldoc/html/jquery.js +0 -11
- data/templates/default/fulldoc/html/style.css +0 -81
- data/templates/default/fulldoc/html/syntax_highlight.css +0 -24
- data/templates/default/inheritance/html/header.erb +0 -8
- data/templates/default/inheritance/text/header.erb +0 -3
- data/templates/default/method/html/aliases.erb +0 -6
- data/templates/default/method/html/title.erb +0 -3
- data/templates/default/method/text/title.erb +0 -1
- data/templates/default/methoddetails/html/header.erb +0 -8
- data/templates/default/methoddetails/html/method_header.erb +0 -3
- data/templates/default/methodmissing/html/header.erb +0 -12
- data/templates/default/methodsignature/html/main.erb +0 -10
- data/templates/default/methodsignature/text/main.erb +0 -8
- data/templates/default/methodsummary/html/header.erb +0 -5
- data/templates/default/methodsummary/html/included.erb +0 -9
- data/templates/default/methodsummary/html/inherited.erb +0 -9
- data/templates/default/methodsummary/html/summary.erb +0 -29
- data/templates/default/methodsummary/text/header.erb +0 -5
- data/templates/default/methodsummary/text/included.erb +0 -0
- data/templates/default/methodsummary/text/inherited.erb +0 -0
- data/templates/default/methodsummary/text/summary.erb +0 -6
- data/templates/default/mixins/html/header.erb +0 -4
- data/templates/default/overloads/html/header.erb +0 -8
- data/templates/default/overloads/text/header.erb +0 -8
- data/templates/default/quickdoc/html/header.erb +0 -15
- data/templates/default/quickdoc/text/header.erb +0 -12
- data/templates/default/root/html/header.erb +0 -4
- data/templates/default/source/html/main.erb +0 -15
- data/templates/default/source/text/main.erb +0 -4
- data/templates/default/tags/html/header.erb +0 -4
- data/templates/default/tags/html/param.erb +0 -21
- data/templates/default/tags/html/tags.erb +0 -23
- data/templates/default/tags/html/todo.erb +0 -8
- data/templates/default/tags/text/header.erb +0 -3
- data/templates/default/tags/text/param.erb +0 -9
- data/templates/default/tags/text/tags.erb +0 -7
- data/templates/default/uml/dot/child.erb +0 -1
- data/templates/default/uml/dot/dependencies.erb +0 -10
- data/templates/default/uml/dot/superclasses.erb +0 -9
- data/templates/default/uml/dot/unknown.erb +0 -3
- data/templates/default/uml/dot/unknown_child.erb +0 -1
- data/templates/default/visibilitygroup/html/header.erb +0 -6
- data/templates/javadoc/attributes/html/header.erb +0 -16
- data/templates/javadoc/class/html/header.erb +0 -4
- data/templates/javadoc/constants/html/constants.erb +0 -9
- data/templates/javadoc/constants/html/header.erb +0 -3
- data/templates/javadoc/constants/html/included.erb +0 -12
- data/templates/javadoc/constants/html/inherited.erb +0 -12
- data/templates/javadoc/constructor/html/header.erb +0 -10
- data/templates/javadoc/deprecated/html/main.erb +0 -0
- data/templates/javadoc/docstring/html/main.erb +0 -6
- data/templates/javadoc/fulldoc/html/all_methods.erb +0 -25
- data/templates/javadoc/fulldoc/html/all_namespaces.erb +0 -19
- data/templates/javadoc/fulldoc/html/app.js +0 -18
- data/templates/javadoc/fulldoc/html/header.erb +0 -15
- data/templates/javadoc/fulldoc/html/html_head.erb +0 -3
- data/templates/javadoc/fulldoc/html/index.erb +0 -18
- data/templates/javadoc/fulldoc/html/jquery.js +0 -11
- data/templates/javadoc/fulldoc/html/readme.erb +0 -15
- data/templates/javadoc/fulldoc/html/style.css +0 -22
- data/templates/javadoc/fulldoc/html/syntax_highlight.css +0 -21
- data/templates/javadoc/inheritance/html/header.erb +0 -6
- data/templates/javadoc/method/html/aliases.erb +0 -6
- data/templates/javadoc/method/html/header.erb +0 -4
- data/templates/javadoc/method/html/title.erb +0 -4
- data/templates/javadoc/methoddetails/html/header.erb +0 -8
- data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
- data/templates/javadoc/methodmissing/html/header.erb +0 -12
- data/templates/javadoc/methodsignature/html/main.erb +0 -8
- data/templates/javadoc/methodsummary/html/header.erb +0 -5
- data/templates/javadoc/methodsummary/html/included.erb +0 -12
- data/templates/javadoc/methodsummary/html/inherited.erb +0 -12
- data/templates/javadoc/methodsummary/html/summary.erb +0 -25
- data/templates/javadoc/mixins/html/header.erb +0 -5
- data/templates/javadoc/module/html/header.erb +0 -4
- data/templates/javadoc/source/html/main.erb +0 -15
- data/templates/javadoc/tags/html/header.erb +0 -5
- data/templates/javadoc/tags/html/see.erb +0 -8
- data/templates/javadoc/tags/html/tags.erb +0 -19
- data/templates/javadoc/visibilitygroup/html/header.erb +0 -5
@@ -1,4 +1,5 @@
|
|
1
1
|
class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
2
|
+
namespace_only
|
2
3
|
handles :class, :sclass
|
3
4
|
|
4
5
|
def process
|
@@ -8,7 +9,6 @@ class YARD::Handlers::Ruby::ClassHandler < YARD::Handlers::Ruby::Base
|
|
8
9
|
undocsuper = statement[1] && superclass.nil?
|
9
10
|
|
10
11
|
klass = register ClassObject.new(namespace, classname) do |o|
|
11
|
-
o.docstring = statement.comments
|
12
12
|
o.superclass = superclass if superclass
|
13
13
|
o.superclass.type = :class if o.superclass.is_a?(Proxy)
|
14
14
|
end
|
@@ -5,7 +5,11 @@ class YARD::Handlers::Ruby::ClassVariableHandler < YARD::Handlers::Ruby::Base
|
|
5
5
|
def process
|
6
6
|
if statement[0].type == :var_field && statement[0][0].type == :cvar
|
7
7
|
name = statement[0][0][0]
|
8
|
-
|
8
|
+
value = statement[1].source
|
9
|
+
register ClassVariableObject.new(namespace, name) do |o|
|
10
|
+
o.source = statement
|
11
|
+
o.value = value
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
@@ -3,10 +3,44 @@ class YARD::Handlers::Ruby::ConstantHandler < YARD::Handlers::Ruby::Base
|
|
3
3
|
handles :assign
|
4
4
|
|
5
5
|
def process
|
6
|
-
if statement[
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
if statement[1].call? && statement[1][0][0] == s(:const, "Struct") &&
|
7
|
+
statement[1][2] == s(:ident, "new")
|
8
|
+
process_structclass(statement)
|
9
|
+
elsif statement[0].type == :var_field && statement[0][0].type == :const
|
10
|
+
process_constant(statement)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def process_constant(statement)
|
17
|
+
name = statement[0][0][0]
|
18
|
+
value = statement[1].source
|
19
|
+
register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip }
|
20
|
+
end
|
21
|
+
|
22
|
+
def process_structclass(statement)
|
23
|
+
lhs = statement[0][0]
|
24
|
+
if lhs.type == :const
|
25
|
+
klass = register ClassObject.new(namespace, lhs[0])
|
26
|
+
klass.superclass = P(:Struct)
|
27
|
+
parse_attributes(klass, statement[1].parameters)
|
28
|
+
else
|
29
|
+
raise YARD::Parser::UndocumentableError, "Struct assignment to #{statement[0].source}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_attributes(klass, attributes)
|
34
|
+
return unless attributes
|
35
|
+
|
36
|
+
scope = :instance
|
37
|
+
attributes.each do |node|
|
38
|
+
next if !node.respond_to?(:type) || node.type != :symbol_literal
|
39
|
+
name = node.jump(:ident).source
|
40
|
+
klass.attributes[scope][name] = SymbolHash[:read => nil, :write => nil]
|
41
|
+
{read: name, write: "#{name}="}.each do |type, meth|
|
42
|
+
klass.attributes[scope][name][type] = MethodObject.new(klass, meth, scope)
|
43
|
+
end
|
10
44
|
end
|
11
45
|
end
|
12
46
|
end
|
@@ -49,7 +49,7 @@ module YARD
|
|
49
49
|
#
|
50
50
|
# @param [Array<Class<Token>>, Symbol] accepted_types
|
51
51
|
# The allowed token types that this token can be. Defaults to [{TkVal}].
|
52
|
-
# A list of types would be, for example, [
|
52
|
+
# A list of types would be, for example, [+TkSTRING+, +TkSYMBOL+], to return
|
53
53
|
# the token's value if it is either of those types. If +TkVal+ is accepted,
|
54
54
|
# +TkNode+ is also accepted.
|
55
55
|
#
|
@@ -116,7 +116,7 @@ module YARD
|
|
116
116
|
# attr_accessor :a, 'b', :c, :d => ['a', 'b', 'c', 'd']
|
117
117
|
# attr_accessor 'a', UNACCEPTED_TYPE, 'c' => ['a', 'c']
|
118
118
|
#
|
119
|
-
# The tokval list of a {TokenList} of the above
|
119
|
+
# The tokval list of a {Parser::Ruby::Legacy::TokenList} of the above
|
120
120
|
# code would be the {#tokval} value of :a, 'b',
|
121
121
|
# :c and :d.
|
122
122
|
#
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class YARD::Handlers::Ruby::Legacy::ClassVariableHandler < YARD::Handlers::Ruby::Legacy::Base
|
2
|
-
HANDLER_MATCH = /\A@@\
|
2
|
+
HANDLER_MATCH = /\A@@\w+\s*=\s*/m
|
3
3
|
handles HANDLER_MATCH
|
4
4
|
|
5
5
|
def process
|
@@ -7,7 +7,10 @@ class YARD::Handlers::Ruby::Legacy::ClassVariableHandler < YARD::Handlers::Ruby:
|
|
7
7
|
# they're not "static" when executed from a method
|
8
8
|
return unless owner.is_a? NamespaceObject
|
9
9
|
|
10
|
-
name, value = *statement.tokens.to_s.
|
11
|
-
register ClassVariableObject.new(namespace, name)
|
10
|
+
name, value = *statement.tokens.to_s.split(/\s*=\s*/, 2)
|
11
|
+
register ClassVariableObject.new(namespace, name) do |o|
|
12
|
+
o.source = statement
|
13
|
+
o.value = value.strip
|
14
|
+
end
|
12
15
|
end
|
13
16
|
end
|
@@ -7,7 +7,26 @@ class YARD::Handlers::Ruby::Legacy::ConstantHandler < YARD::Handlers::Ruby::Lega
|
|
7
7
|
# they're not "static" when executed from a method
|
8
8
|
return unless owner.is_a? NamespaceObject
|
9
9
|
|
10
|
-
name, value = *statement.tokens.to_s.
|
11
|
-
|
10
|
+
name, value = *statement.tokens.to_s.split(/\s*=\s*/, 2)
|
11
|
+
if value =~ /\A\s*Struct.new(?:\s*\(?|\b)/
|
12
|
+
process_structclass(name, $')
|
13
|
+
else
|
14
|
+
register ConstantObject.new(namespace, name) {|o| o.source = statement; o.value = value.strip }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def process_structclass(classname, parameters)
|
21
|
+
scope = :instance
|
22
|
+
klass = register ClassObject.new(namespace, classname)
|
23
|
+
klass.superclass = P(:Struct)
|
24
|
+
|
25
|
+
tokval_list(YARD::Parser::Ruby::Legacy::TokenList.new(parameters), TkSYMBOL).each do |name|
|
26
|
+
klass.attributes[scope][name] = SymbolHash[:read => nil, :write => nil]
|
27
|
+
{:read => name, :write => "#{name}="}.each do |type, meth|
|
28
|
+
klass.attributes[scope][name][type] = MethodObject.new(klass, meth, scope)
|
29
|
+
end
|
30
|
+
end
|
12
31
|
end
|
13
32
|
end
|
@@ -26,6 +26,16 @@ class YARD::Handlers::Ruby::Legacy::MethodHandler < YARD::Handlers::Ruby::Legacy
|
|
26
26
|
o.explicit = true
|
27
27
|
o.parameters = args
|
28
28
|
end
|
29
|
+
if mscope == :instance && meth == "initialize"
|
30
|
+
unless obj.has_tag?(:return)
|
31
|
+
obj.docstring.add_tag(YARD::Tags::Tag.new(:return,
|
32
|
+
"a new instance of +#{namespace.name}+", namespace.name.to_s))
|
33
|
+
end
|
34
|
+
elsif mscope == :class && obj.docstring.blank? && %w(inherited included
|
35
|
+
extended method_added method_removed method_undefined).include?(meth)
|
36
|
+
obj.docstring.add_tag(YARD::Tags::Tag.new(:private, nil))
|
37
|
+
end
|
38
|
+
|
29
39
|
parse_block(:owner => obj) # mainly for yield/exceptions
|
30
40
|
end
|
31
41
|
end
|
@@ -7,7 +7,6 @@ class YARD::Handlers::Ruby::Legacy::YieldHandler < YARD::Handlers::Ruby::Legacy:
|
|
7
7
|
return if owner.has_tag? :yieldparam # Same thing.
|
8
8
|
|
9
9
|
yieldtag = YARD::Tags::Tag.new(:yield, "", [])
|
10
|
-
owner.docstring.add_tag(yieldtag)
|
11
10
|
tokval_list(statement.tokens[2..-1], Token).each do |item|
|
12
11
|
item = item.inspect unless item.is_a?(String)
|
13
12
|
if item == "self"
|
@@ -22,5 +21,7 @@ class YARD::Handlers::Ruby::Legacy::YieldHandler < YARD::Handlers::Ruby::Legacy:
|
|
22
21
|
yieldtag.types << item
|
23
22
|
end
|
24
23
|
end
|
24
|
+
|
25
|
+
owner.docstring.add_tag(yieldtag) unless yieldtag.types.empty?
|
25
26
|
end
|
26
27
|
end
|
@@ -22,6 +22,16 @@ class YARD::Handlers::Ruby::MethodHandler < YARD::Handlers::Ruby::Base
|
|
22
22
|
o.signature = method_signature(meth)
|
23
23
|
o.explicit = true
|
24
24
|
o.parameters = args
|
25
|
+
|
26
|
+
end
|
27
|
+
if mscope == :instance && meth == "initialize"
|
28
|
+
unless obj.has_tag?(:return)
|
29
|
+
obj.docstring.add_tag(YARD::Tags::Tag.new(:return,
|
30
|
+
"a new instance of +#{namespace.name}+", namespace.name.to_s))
|
31
|
+
end
|
32
|
+
elsif mscope == :class && obj.docstring.blank? && %w(inherited included
|
33
|
+
extended method_added method_removed method_undefined).include?(meth)
|
34
|
+
obj.docstring.add_tag(YARD::Tags::Tag.new(:private, nil))
|
25
35
|
end
|
26
36
|
|
27
37
|
parse_block(blk, :owner => obj) # mainly for yield/exceptions
|
@@ -7,7 +7,6 @@ class YARD::Handlers::Ruby::YieldHandler < YARD::Handlers::Ruby::Base
|
|
7
7
|
return if owner.has_tag? :yieldparam # Same thing.
|
8
8
|
|
9
9
|
yieldtag = YARD::Tags::Tag.new(:yield, "", [])
|
10
|
-
owner.docstring.add_tag(yieldtag)
|
11
10
|
|
12
11
|
if statement.type == :yield
|
13
12
|
statement.jump(:list).children.each do |item|
|
@@ -24,5 +23,7 @@ class YARD::Handlers::Ruby::YieldHandler < YARD::Handlers::Ruby::Base
|
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
26
|
+
|
27
|
+
owner.docstring.add_tag(yieldtag) unless yieldtag.types.empty?
|
27
28
|
end
|
28
29
|
end
|
data/lib/yard/logging.rb
CHANGED
@@ -1,28 +1,45 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
3
|
module YARD
|
4
|
+
# Handles console logging for info, warnings and errors.
|
5
|
+
# Uses the stdlib Logger class in Ruby for all the backend logic.
|
4
6
|
class Logger < ::Logger
|
7
|
+
# The logger instance
|
8
|
+
# @return [Logger] the logger instance
|
5
9
|
def self.instance(pipe = STDERR)
|
6
10
|
@logger ||= new(pipe)
|
7
11
|
end
|
8
12
|
|
13
|
+
# Creates a new logger
|
9
14
|
def initialize(*args)
|
10
15
|
super
|
11
16
|
self.level = INFO
|
12
17
|
self.formatter = method(:format_log)
|
13
18
|
end
|
14
19
|
|
20
|
+
# Changes the debug level to DEBUG if $DEBUG is set
|
21
|
+
# and writes a debugging message.
|
15
22
|
def debug(*args)
|
16
23
|
self.level = DEBUG if $DEBUG
|
17
24
|
super
|
18
25
|
end
|
19
26
|
|
27
|
+
# Sets the logger level for the duration of the block
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# log.enter_level(Logger::ERROR) do
|
31
|
+
# YARD.parse_string "def x; end"
|
32
|
+
# end
|
33
|
+
# @param [Fixnum] new_level the logger level for the duration of the block.
|
34
|
+
# values can be found in Ruby's Logger class.
|
35
|
+
# @yield the block with the logger temporarily set to +new_level+
|
20
36
|
def enter_level(new_level = level, &block)
|
21
37
|
old_level, self.level = level, new_level
|
22
38
|
yield
|
23
39
|
self.level = old_level
|
24
40
|
end
|
25
41
|
|
42
|
+
# Log format (from Logger implementation)
|
26
43
|
def format_log(sev, time, prog, msg)
|
27
44
|
"[#{sev.downcase}]: #{msg}\n"
|
28
45
|
end
|
@@ -1,12 +1,42 @@
|
|
1
1
|
module YARD
|
2
2
|
module Parser
|
3
3
|
module Ruby
|
4
|
+
# Builds and s-expression by creating {AstNode} objects with
|
5
|
+
# the type provided by the first argument.
|
6
|
+
#
|
7
|
+
# @example An implicit list of keywords
|
8
|
+
# ast = s(s(:kw, "if"), s(:kw, "else"))
|
9
|
+
# ast.type # => :list
|
10
|
+
# @example A method call
|
11
|
+
# s(:command, s(:var_ref, "mymethod"))
|
12
|
+
#
|
13
|
+
# @overload s(*nodes, opts = {})
|
14
|
+
# @param [Array<AstNode>] nodes a list of nodes.
|
15
|
+
# @param [Hash] opts any extra options (docstring, file, source) to
|
16
|
+
# set on the object
|
17
|
+
# @return [AstNode] an implicit node where node.type == +:list+
|
18
|
+
# @overload s(type, *children, opts = {})
|
19
|
+
# @param [Symbol] type the node type
|
20
|
+
# @param [Array<AstNode>] children any child nodes inside this one
|
21
|
+
# @param [Hash] opts any extra options to set on the object
|
22
|
+
# @return [AstNode] a node of type +type+.
|
23
|
+
# @see AstNode#initialize
|
4
24
|
def s(*args)
|
5
25
|
type = Symbol === args.first ? args.shift : :list
|
6
26
|
opts = Hash === args.last ? args.pop : {}
|
7
27
|
AstNode.node_class_for(type).new(type, args, opts)
|
8
28
|
end
|
9
29
|
|
30
|
+
# An AST node is characterized by a type and a list of children. It
|
31
|
+
# is most easily represented by the s-expression {#s} such as:
|
32
|
+
# # AST for "if true; 5 end":
|
33
|
+
# s(s(:if, s(:var_ref, s(:kw, "true")), s(s(:int, "5")), nil))
|
34
|
+
#
|
35
|
+
# The node type is not considered part of the list, only its children.
|
36
|
+
# So +ast[0]+ does not refer to the type, but rather the first child
|
37
|
+
# (or object). Items that are not +AstNode+ objects can be part of the
|
38
|
+
# list, like Strings or Symbols representing names. To return only
|
39
|
+
# the AstNode children of the node, use {#children}.
|
10
40
|
class AstNode < Array
|
11
41
|
attr_accessor :type, :parent, :docstring, :file, :full_source, :source
|
12
42
|
attr_accessor :source_range, :line_range, :docstring_range
|
@@ -14,6 +44,8 @@ module YARD
|
|
14
44
|
alias comments_range docstring_range
|
15
45
|
alias to_s source
|
16
46
|
|
47
|
+
# List of all known keywords
|
48
|
+
# @return [Hash]
|
17
49
|
KEYWORDS = { class: true, alias: true, lambda: true, do_block: true,
|
18
50
|
def: true, defs: true, begin: true, rescue: true, rescue_mod: true,
|
19
51
|
if: true, if_mod: true, else: true, elsif: true, case: true,
|
@@ -22,6 +54,11 @@ module YARD
|
|
22
54
|
while: true, while_mod: true, yield: true, yield0: true, zsuper: true,
|
23
55
|
unless: true, unless_mod: true, for: true, super: true, return0: true }
|
24
56
|
|
57
|
+
# Finds the node subclass that should be instantiated for a specific
|
58
|
+
# node type
|
59
|
+
#
|
60
|
+
# @param [Symbol] type the node type to find a subclass for
|
61
|
+
# @return [Class] a subclass of AstNode to instantiate the node with.
|
25
62
|
def self.node_class_for(type)
|
26
63
|
case type
|
27
64
|
when :params
|
@@ -37,6 +74,19 @@ module YARD
|
|
37
74
|
end
|
38
75
|
end
|
39
76
|
|
77
|
+
# Creates a new AST node
|
78
|
+
#
|
79
|
+
# @param [Symbol] type the type of node being created
|
80
|
+
# @param [Array<AstNode>] arr the child nodes
|
81
|
+
# @param [Hash] opts any extra line options
|
82
|
+
# @option opts [Fixnum] :line (nil) the line the node starts on in source
|
83
|
+
# @option opts [String] :char (nil) the character number the node starts on
|
84
|
+
# in source
|
85
|
+
# @option opts [Fixnum] :listline (nil) a special key like :line but for
|
86
|
+
# list nodes
|
87
|
+
# @option opts [Fixnum] :listchar (nil) a special key like :char but for
|
88
|
+
# list nodes
|
89
|
+
# @option opts [Boolean] :token (nil) whether the node represents a token
|
40
90
|
def initialize(type, arr, opts = {})
|
41
91
|
super(arr)
|
42
92
|
self.type = type
|
@@ -47,85 +97,127 @@ module YARD
|
|
47
97
|
@token = true if opts[:token]
|
48
98
|
end
|
49
99
|
|
100
|
+
# @return [Boolean] whether the node is equal to another by checking
|
101
|
+
# the list and type
|
50
102
|
def ==(ast)
|
51
103
|
super && type == ast.type
|
52
104
|
end
|
53
105
|
|
106
|
+
# @return [String] the first line of source the node represents
|
54
107
|
def show
|
55
108
|
"\t#{line}: #{first_line}"
|
56
109
|
end
|
57
110
|
|
111
|
+
# @return [Range] the character range in {#full_source} represented
|
112
|
+
# by the node
|
58
113
|
def source_range
|
59
114
|
reset_line_info unless @source_range
|
60
115
|
@source_range
|
61
116
|
end
|
62
117
|
|
118
|
+
# @return [Range] the line range in {#full_source} represented
|
119
|
+
# by the node
|
63
120
|
def line_range
|
64
121
|
reset_line_info unless @line_range
|
65
122
|
@line_range
|
66
123
|
end
|
67
124
|
|
125
|
+
# @return [Boolean] whether the node has a {#line_range} set
|
68
126
|
def has_line?
|
69
127
|
@line_range ? true : false
|
70
128
|
end
|
71
129
|
|
130
|
+
# @return [Fixnum] the starting line number of the node
|
72
131
|
def line
|
73
132
|
line_range && line_range.first
|
74
133
|
end
|
75
134
|
|
135
|
+
# @return [String] the first line of source represented by the node.
|
76
136
|
def first_line
|
77
137
|
full_source.split(/\r?\n/)[line - 1].strip
|
78
138
|
end
|
79
139
|
|
140
|
+
# Searches through the node and all descendents and returns the
|
141
|
+
# first node with a type matching any of +node_types+, otherwise
|
142
|
+
# returns the original node (self).
|
143
|
+
#
|
144
|
+
# @example Returns the first method definition in a block of code
|
145
|
+
# ast = YARD.parse_string("if true; def x; end end").ast
|
146
|
+
# ast.jump(:def)
|
147
|
+
# # => s(:def, s(:ident, "x"), s(:params, nil, nil, nil, nil,
|
148
|
+
# # nil), s(s(:void_stmt, )))
|
149
|
+
# @example Returns first 'def' or 'class' statement
|
150
|
+
# ast = YARD.parse_string("class X; def y; end end")
|
151
|
+
# ast.jump(:def, :class).first
|
152
|
+
# # =>
|
153
|
+
# @example If the node types are not present in the AST
|
154
|
+
# ast = YARD.parse("def x; end")
|
155
|
+
# ast.jump(:def)
|
156
|
+
#
|
157
|
+
# @param [Array<Symbol>] node_types a set of node types to match
|
158
|
+
# @return [AstNode] the matching node, if one was found
|
159
|
+
# @return [self] if no node was found
|
80
160
|
def jump(*node_types)
|
81
161
|
traverse {|child| return(child) if node_types.include?(child.type) }
|
82
162
|
self
|
83
163
|
end
|
84
164
|
|
165
|
+
# @return [Array<AstNode>] the {AstNode} children inside the node
|
85
166
|
def children
|
86
167
|
@children ||= select {|e| AstNode === e }
|
87
168
|
end
|
88
169
|
|
170
|
+
# @return [Boolean] whether the node is a token
|
89
171
|
def token?
|
90
172
|
@token
|
91
173
|
end
|
92
174
|
|
175
|
+
# @return [Boolean] whether the node is a reference (variable,
|
176
|
+
# constant name)
|
93
177
|
def ref?
|
94
178
|
false
|
95
179
|
end
|
96
180
|
|
181
|
+
# @return [Boolean] whether the node is a literal value
|
97
182
|
def literal?
|
98
183
|
@literal ||= type =~ /_literal$/ ? true : false
|
99
184
|
end
|
100
185
|
|
186
|
+
# @return [Boolean] whether the node is a keyword
|
101
187
|
def kw?
|
102
188
|
@kw ||= KEYWORDS.has_key?(type)
|
103
189
|
end
|
104
190
|
|
191
|
+
# @return [Boolean] whether the node is a method call
|
105
192
|
def call?
|
106
193
|
false
|
107
194
|
end
|
108
195
|
|
196
|
+
# @return [Boolean] whether the node is a if/elsif/else condition
|
109
197
|
def condition?
|
110
198
|
false
|
111
199
|
end
|
112
200
|
|
201
|
+
# @return [String] the filename the node was parsed from
|
113
202
|
def file
|
114
203
|
return parent.file if parent
|
115
204
|
@file
|
116
205
|
end
|
117
206
|
|
207
|
+
# @return [String] the full source that the node was parsed from
|
118
208
|
def full_source
|
119
209
|
return parent.full_source if parent
|
120
210
|
return @full_source if @full_source
|
121
211
|
return IO.read(@file) if file && File.exist?(file)
|
122
212
|
end
|
123
213
|
|
214
|
+
# @return [String] the parse of {#full_source} that the node represents
|
124
215
|
def source
|
125
216
|
return parent.full_source[source_range] if parent
|
126
217
|
full_source
|
127
218
|
end
|
128
219
|
|
220
|
+
# @return [nil] pretty prints the node
|
129
221
|
def pretty_print(q)
|
130
222
|
objs = [*self.dup, :__last__]
|
131
223
|
objs.unshift(type) if type && type != :list
|
@@ -159,11 +251,17 @@ module YARD
|
|
159
251
|
end
|
160
252
|
end
|
161
253
|
|
254
|
+
# @return [String] inspects the object
|
162
255
|
def inspect
|
163
256
|
typeinfo = type && type != :list ? ':' + type.to_s + ', ' : ''
|
164
257
|
's(' + typeinfo + map(&:inspect).join(", ") + ')'
|
165
258
|
end
|
166
259
|
|
260
|
+
# Traverses the object and yields each node (including descendents) in order.
|
261
|
+
#
|
262
|
+
# @yield each descendent node in order
|
263
|
+
# @yieldparam [AstNode] self, or a child/descendent node
|
264
|
+
# @return [nil]
|
167
265
|
def traverse
|
168
266
|
nodes = [self]
|
169
267
|
nodes.each.with_index do |node, index|
|
@@ -174,6 +272,8 @@ module YARD
|
|
174
272
|
|
175
273
|
private
|
176
274
|
|
275
|
+
# Resets line information
|
276
|
+
# @return [nil]
|
177
277
|
def reset_line_info
|
178
278
|
if size == 0
|
179
279
|
self.line_range = @fallback_line
|
@@ -227,6 +327,7 @@ module YARD
|
|
227
327
|
|
228
328
|
def parameters(include_block_param = true)
|
229
329
|
params = self[1 + index_adjust]
|
330
|
+
return nil unless params
|
230
331
|
params = call_has_paren? ? params.first : params
|
231
332
|
include_block_param ? params : params[0...-1]
|
232
333
|
end
|