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,15 +1,62 @@
|
|
1
1
|
module YARD
|
2
2
|
module Serializers
|
3
|
+
# The abstract base serializer. Serializers allow templates to be
|
4
|
+
# rendered to various endpoints. For instance, a {FileSystemSerializer}
|
5
|
+
# would allow template contents to be written to the filesystem
|
6
|
+
#
|
7
|
+
# To implement a custom serializer, override the following methods:
|
8
|
+
# * {#serialize}
|
9
|
+
# * {#serialized_path}
|
10
|
+
#
|
11
|
+
# Optionally, a serializer can implement before and after filters:
|
12
|
+
# * {#before_serialize}
|
13
|
+
# * {#after_serialize}
|
14
|
+
#
|
15
|
+
# @abstract Override this class to implement a custom serializer.
|
3
16
|
class Base
|
17
|
+
# All serializer options are saved so they can be passed to other serializers.
|
18
|
+
#
|
19
|
+
# @return [SymbolHash] the serializer options
|
4
20
|
attr_reader :options
|
5
21
|
|
22
|
+
# Creates a new serializer with options
|
23
|
+
#
|
24
|
+
# @param [Hash] opts the options to assign to {#options}
|
6
25
|
def initialize(opts = {})
|
7
26
|
@options = SymbolHash.new(false).update(opts)
|
8
27
|
end
|
9
28
|
|
29
|
+
# Called before serialization.
|
30
|
+
#
|
31
|
+
# @abstract Should run code before serialization. Should return false
|
32
|
+
# if serialization should not occur.
|
33
|
+
# @return [Boolean] whether or not serialization should occur
|
10
34
|
def before_serialize; end
|
11
|
-
|
35
|
+
|
36
|
+
# Called after serialization.
|
37
|
+
#
|
38
|
+
# @abstract Should run code after serialization.
|
39
|
+
# @param [String] data the data that was serialized.
|
40
|
+
# @return [nil]
|
12
41
|
def after_serialize(data); end
|
42
|
+
|
43
|
+
# Serializes an object.
|
44
|
+
#
|
45
|
+
# @abstract This method should implement the logic that serializes
|
46
|
+
# +data+ to the respective endpoint. This method should also call
|
47
|
+
# the before and after callbacks {#before_serialize} and {#after_serialize}
|
48
|
+
# @param [CodeObjects::Base, String] object the object to serialize the
|
49
|
+
# data for. The object can also be a string (for non-object serialization)
|
50
|
+
# @param [String] data the contents that should be serialized
|
51
|
+
def serialize(object, data) end
|
52
|
+
|
53
|
+
# The serialized path of an object
|
54
|
+
#
|
55
|
+
# @abstract This method should return the path of the object on the
|
56
|
+
# endpoint. For instance, for a file serializer, this should return
|
57
|
+
# the filename that represents the object on disk.
|
58
|
+
# @param [CodeObjects::Base] object the object to return a path for
|
59
|
+
# @return [String] the serialized path of an object
|
13
60
|
def serialized_path(object) end
|
14
61
|
end
|
15
62
|
end
|
@@ -3,21 +3,42 @@ require 'fileutils'
|
|
3
3
|
module YARD
|
4
4
|
module Serializers
|
5
5
|
class FileSystemSerializer < Base
|
6
|
-
|
6
|
+
# The base path to write data to.
|
7
|
+
# @return [String] a base path
|
8
|
+
attr_reader :basepath
|
7
9
|
|
10
|
+
# The extension of the filename (defaults to +html+)
|
11
|
+
#
|
12
|
+
# @return [String] the extension of the file. Empty string for no extension.
|
13
|
+
attr_reader :extension
|
14
|
+
|
15
|
+
# Creates a new FileSystemSerializer with options
|
16
|
+
#
|
17
|
+
# @option opts [String] :basepath ('doc') the base path to write data to
|
18
|
+
# @option opts [String] :extension ('html') the extension of the serialized
|
19
|
+
# path filename. If this is set to the empty string, no extension is used.
|
8
20
|
def initialize(opts = {})
|
9
21
|
super
|
10
22
|
@basepath = (options[:basepath] || 'doc').to_s
|
11
23
|
@extension = (options.has_key?(:extension) ? options[:extension] : 'html').to_s
|
12
24
|
end
|
13
25
|
|
26
|
+
# Serializes object with data to its serialized path (prefixed by the {#basepath}).
|
27
|
+
#
|
28
|
+
# @return [String] the written data (for chaining)
|
14
29
|
def serialize(object, data)
|
15
30
|
path = File.join(basepath, *serialized_path(object))
|
16
31
|
FileUtils.mkdir_p File.dirname(path)
|
17
32
|
log.debug "Serializing to #{path}"
|
18
|
-
File.open(path, "
|
33
|
+
File.open(path, "wb") {|f| f.write data }
|
19
34
|
end
|
20
35
|
|
36
|
+
# Implements the serialized path of a code object.
|
37
|
+
#
|
38
|
+
# @param [CodeObjects::Base, String] object the object to get a path for.
|
39
|
+
# The path of a string is the string itself.
|
40
|
+
# @return [String] if object is a String, returns
|
41
|
+
# object, otherwise the path on disk (without the basepath).
|
21
42
|
def serialized_path(object)
|
22
43
|
return object if object.is_a?(String)
|
23
44
|
|
@@ -1,10 +1,20 @@
|
|
1
1
|
module YARD
|
2
2
|
module Serializers
|
3
|
+
# Serializes an object to a process (like less)
|
4
|
+
#
|
5
|
+
# @example Serializing to a pager (less)
|
6
|
+
# serializer = ProcessSerializer.new('less')
|
7
|
+
# serializer.serialize(object, "data!")
|
3
8
|
class ProcessSerializer < Base
|
9
|
+
# Creates a new ProcessSerializer for the shell command +cmd+
|
10
|
+
#
|
11
|
+
# @param [String] cmd the command that will accept data on stdin
|
4
12
|
def initialize(cmd)
|
5
13
|
@cmd = cmd
|
6
14
|
end
|
7
15
|
|
16
|
+
# Overrides serialize behavour and writes data to standard input
|
17
|
+
# of the associated command
|
8
18
|
def serialize(object, data)
|
9
19
|
IO.popen(@cmd, 'w') {|io| io.write(data) }
|
10
20
|
end
|
@@ -1,16 +1,27 @@
|
|
1
1
|
module YARD
|
2
2
|
module Serializers
|
3
|
+
# A serializer that writes data to standard output.
|
3
4
|
class StdoutSerializer < Base
|
5
|
+
# Creates a serializer to print text to stdout
|
6
|
+
#
|
7
|
+
# @param [Fixnum, nil] wrap if wrap is a number, wraps text to +wrap+
|
8
|
+
# columns, otherwise no wrapping is done.
|
4
9
|
def initialize(wrap = nil)
|
5
10
|
@wrap = wrap
|
6
11
|
end
|
7
12
|
|
13
|
+
# Overrides serialize behaviour to write data to standard output
|
8
14
|
def serialize(object, data)
|
9
15
|
print(@wrap ? word_wrap(data, @wrap) : data)
|
10
16
|
end
|
11
17
|
|
12
18
|
private
|
13
19
|
|
20
|
+
# Wraps text to a specific column length
|
21
|
+
#
|
22
|
+
# @param [String] text the text to wrap
|
23
|
+
# @param [Fixnum] length the column length to wrap to
|
24
|
+
# @return [String] the wrapped text
|
14
25
|
def word_wrap(text, length = 80)
|
15
26
|
# See ruby-talk/10655 / Ernest Ellingson
|
16
27
|
text.gsub(/\t/," ").gsub(/.{1,50}(?:\s|\Z)/){($& +
|
data/lib/yard/tags/library.rb
CHANGED
@@ -139,10 +139,13 @@ module YARD
|
|
139
139
|
define_tag "Since", :since
|
140
140
|
define_tag "Version", :version
|
141
141
|
define_tag "API Visibility", :api
|
142
|
-
define_tag "
|
142
|
+
define_tag "Note", :note
|
143
|
+
define_tag "Todo Item", :todo
|
143
144
|
define_tag "Example", :example, :with_raw_title_and_text
|
144
145
|
define_tag "Options Hash", :option, :with_options
|
145
146
|
define_tag "Overloads", :overload, OverloadTag
|
147
|
+
define_tag "Private", :private
|
148
|
+
define_tag "Abstract", :abstract
|
146
149
|
end
|
147
150
|
end
|
148
151
|
end
|
@@ -2,7 +2,6 @@ module YARD
|
|
2
2
|
module Tags
|
3
3
|
class OverloadTag < Tag
|
4
4
|
attr_reader :signature, :parameters, :docstring
|
5
|
-
undef_method :to_s, :inspect
|
6
5
|
|
7
6
|
def initialize(tag_name, text, raw_text)
|
8
7
|
super(tag_name, nil)
|
@@ -19,22 +18,14 @@ module YARD
|
|
19
18
|
docstring.object = value
|
20
19
|
end
|
21
20
|
|
22
|
-
def type
|
23
|
-
object.type
|
24
|
-
end
|
25
|
-
|
26
21
|
def name(prefix = false)
|
27
22
|
object.name(prefix)
|
28
23
|
end
|
29
|
-
|
30
|
-
def inspect
|
31
|
-
"#<yardoc overload #{path}>"
|
32
|
-
end
|
33
24
|
|
34
|
-
def method_missing(
|
35
|
-
object
|
25
|
+
def method_missing(*args, &block)
|
26
|
+
object.send(*args, &block)
|
36
27
|
end
|
37
|
-
|
28
|
+
|
38
29
|
private
|
39
30
|
|
40
31
|
def parse_tag(raw_text)
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module YARD
|
2
|
+
module Templates
|
3
|
+
module Engine
|
4
|
+
class << self
|
5
|
+
# @return [Array<String>] the list of registered template paths
|
6
|
+
attr_accessor :template_paths
|
7
|
+
|
8
|
+
# Registers a new template path in {template_paths}
|
9
|
+
#
|
10
|
+
# @param [String] path a new template path
|
11
|
+
# @return [nil]
|
12
|
+
def register_template_path(path)
|
13
|
+
template_paths.push path
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a template module representing the path. Searches on disk
|
17
|
+
# for the first directory named +path+ (joined by '/') within the
|
18
|
+
# template paths and builds a template module for. All other matching
|
19
|
+
# directories in other template paths will be included in the
|
20
|
+
# generated module as mixins (for overriding).
|
21
|
+
#
|
22
|
+
# @param [Array<String, Symbol>] path a list of path components
|
23
|
+
# @return [Template] the module representing the template
|
24
|
+
def template(*path)
|
25
|
+
from_template = nil
|
26
|
+
from_template = path.shift if path.first.is_a?(Template)
|
27
|
+
path = path.join('/')
|
28
|
+
full_paths = find_template_paths(from_template, path)
|
29
|
+
|
30
|
+
path = File.cleanpath(path).gsub('../', '')
|
31
|
+
raise ArgumentError, "No such template for #{path}" if full_paths.empty?
|
32
|
+
mod = template!(path, full_paths)
|
33
|
+
|
34
|
+
mod
|
35
|
+
end
|
36
|
+
|
37
|
+
# Forces creation of a template at +path+ within a +full_path+.
|
38
|
+
#
|
39
|
+
# @param [String] path the path name of the template
|
40
|
+
# @param [Array<String>] full_paths the full path on disk of the template
|
41
|
+
# @return [Template] the template module representing the +path+
|
42
|
+
def template!(path, full_paths = nil)
|
43
|
+
full_paths ||= [path]
|
44
|
+
full_paths = [full_paths] unless full_paths.is_a?(Array)
|
45
|
+
name = template_module_name(full_paths.first)
|
46
|
+
return const_get(name) rescue NameError
|
47
|
+
|
48
|
+
mod = const_set(name, Module.new)
|
49
|
+
mod.send(:include, Template)
|
50
|
+
mod.send(:initialize, path, full_paths)
|
51
|
+
mod
|
52
|
+
end
|
53
|
+
|
54
|
+
# Renders a template on a {CodeObjects::Base code object} using
|
55
|
+
# a set of default (overridable) options. Either the +:object+
|
56
|
+
# or +:type+ keys must be provided.
|
57
|
+
#
|
58
|
+
# If a +:serializer+ key is provided and +:serialize+ is not set to
|
59
|
+
# false, the rendered contents will be serialized through the {Serializers::Base}
|
60
|
+
# object. See {with_serializer}.
|
61
|
+
#
|
62
|
+
# @example Renders an object with html formatting
|
63
|
+
# Engine.render(:format => :html, :object => obj)
|
64
|
+
# @example Renders without an object
|
65
|
+
# Engine.render(:type => :fulldoc, :otheropts => somevalue)
|
66
|
+
# @param [Hash] options the options hash
|
67
|
+
# @option options [Symbol] :format (:text) the default format
|
68
|
+
# @option options [Symbol] :type (nil) the :object's type.
|
69
|
+
# @option options [Symbol] :template (:default) the default template
|
70
|
+
# @return [String] the rendered template
|
71
|
+
def render(options = {})
|
72
|
+
set_default_options(options)
|
73
|
+
mod = template(options[:template], options[:type], options[:format])
|
74
|
+
|
75
|
+
if options[:serialize] != false
|
76
|
+
with_serializer(options[:object], options[:serializer]) { mod.run(options) }
|
77
|
+
else
|
78
|
+
mod.run(options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Passes a set of objects to the +:fulldoc+ template for full documentation generation.
|
83
|
+
# This is called by {CLI::Yardoc} to most commonly perform HTML
|
84
|
+
# documentation generation.
|
85
|
+
#
|
86
|
+
# @param [Array<CodeObjects::Base>] objects a list of {CodeObjects::Base}
|
87
|
+
# objects to pass to the template
|
88
|
+
# @param [Hash] options (see {render})
|
89
|
+
# @return [nil]
|
90
|
+
def generate(objects, options = {})
|
91
|
+
set_default_options(options)
|
92
|
+
options[:objects] = objects
|
93
|
+
template(options[:template], :fulldoc, options[:format]).run(options)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Serializes the results of a block with a +serializer+ object.
|
97
|
+
#
|
98
|
+
# @param [CodeObjects::Base] object the code object to serialize
|
99
|
+
# @param [Serializers::Base] serializer the serializer object
|
100
|
+
# @yield a block whose result will be serialize
|
101
|
+
# @yieldreturn [String] the contents to serialize
|
102
|
+
# @see Serializers::Base
|
103
|
+
def with_serializer(object, serializer, &block)
|
104
|
+
serializer.before_serialize if serializer
|
105
|
+
output = yield
|
106
|
+
if serializer
|
107
|
+
serializer.serialize(object, output)
|
108
|
+
serializer.after_serialize(output)
|
109
|
+
end
|
110
|
+
output
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
# Sets default options on the options hash
|
116
|
+
#
|
117
|
+
# @param [Hash] options the options hash
|
118
|
+
# @option options [Symbol] :format (:text) the default format
|
119
|
+
# @option options [Symbol] :type (nil) the :object's type, if provided
|
120
|
+
# @option options [Symbol] :template (:default) the default template
|
121
|
+
# @return [nil]
|
122
|
+
def set_default_options(options = {})
|
123
|
+
options[:format] ||= :text
|
124
|
+
options[:type] ||= options[:object].type if options[:object]
|
125
|
+
options[:template] ||= :default
|
126
|
+
end
|
127
|
+
|
128
|
+
# Searches through the registered {template_paths} and returns
|
129
|
+
# all full directories that have the +path+ within them on disk.
|
130
|
+
#
|
131
|
+
# @param [Template] from_template if provided, allows a relative
|
132
|
+
# path to be specified from this template's full path.
|
133
|
+
# @param [String] path the path component to search for in the
|
134
|
+
# {template_paths}
|
135
|
+
# @return [Array<String>] a list of full paths that are existing
|
136
|
+
# candidates for a template module
|
137
|
+
def find_template_paths(from_template, path)
|
138
|
+
paths = template_paths.dup
|
139
|
+
paths = from_template.full_paths + paths if from_template
|
140
|
+
|
141
|
+
paths.inject([]) do |acc, tp|
|
142
|
+
full_path = File.cleanpath(File.join(tp, path))
|
143
|
+
acc.unshift(full_path) if File.directory?(full_path)
|
144
|
+
acc
|
145
|
+
end.uniq
|
146
|
+
end
|
147
|
+
|
148
|
+
# The name of the module that represents a +path+
|
149
|
+
#
|
150
|
+
# @param [String] the path toe generate a module name for
|
151
|
+
# @return [String] the module name
|
152
|
+
def template_module_name(path)
|
153
|
+
'Template_' + path.to_s.gsub(/[^a-z0-9]/i, '_')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
self.template_paths = []
|
158
|
+
end
|
159
|
+
|
160
|
+
Engine.register_template_path(File.join(YARD::ROOT, '..', 'templates'))
|
161
|
+
end
|
162
|
+
end
|
@@ -1,5 +1,12 @@
|
|
1
|
-
module YARD::
|
1
|
+
module YARD::Templates::Helpers
|
2
2
|
module BaseHelper
|
3
|
+
attr_accessor :object, :serializer
|
4
|
+
|
5
|
+
def run_verifier(list)
|
6
|
+
return list unless options[:verifier]
|
7
|
+
list.reject {|item| options[:verifier].call(item).is_a?(FalseClass) }
|
8
|
+
end
|
9
|
+
|
3
10
|
# This is used a lot by the HtmlHelper and there should
|
4
11
|
# be some helper to "clean up" text for whatever, this is it.
|
5
12
|
def h(text)
|
@@ -32,12 +39,8 @@ module YARD::Generators::Helpers
|
|
32
39
|
url
|
33
40
|
end
|
34
41
|
|
35
|
-
def format_object_name_list(objects)
|
36
|
-
objects.sort_by {|o| o.name.to_s.downcase }.join(", ")
|
37
|
-
end
|
38
|
-
|
39
42
|
def format_types(list, brackets = true)
|
40
|
-
list.empty? ? "" : (brackets ? "
|
43
|
+
list.nil? || list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
|
41
44
|
end
|
42
45
|
|
43
46
|
def format_object_type(object)
|
@@ -57,13 +60,11 @@ module YARD::Generators::Helpers
|
|
57
60
|
format_object_type(object) + ": " + object.path
|
58
61
|
end
|
59
62
|
end
|
60
|
-
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
[method]
|
66
|
-
end
|
63
|
+
|
64
|
+
def format_source(value)
|
65
|
+
sp = value.split("\n").last[/^(\s+)/, 1]
|
66
|
+
num = sp ? sp.size : 0
|
67
|
+
value.gsub(/^\s{#{num}}/, '')
|
67
68
|
end
|
68
69
|
end
|
69
70
|
end
|
@@ -0,0 +1,287 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Templates::Helpers
|
5
|
+
module HtmlHelper
|
6
|
+
include MarkupHelper
|
7
|
+
include HtmlSyntaxHighlightHelper
|
8
|
+
|
9
|
+
SimpleMarkupHtml = RDoc::Markup::ToHtml.new rescue SM::ToHtml.new
|
10
|
+
|
11
|
+
# Escapes HTML entities
|
12
|
+
#
|
13
|
+
# @param [String] text the text to escape
|
14
|
+
# @return [String] the HTML with escaped entities
|
15
|
+
def h(text)
|
16
|
+
CGI.escapeHTML(text.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Escapes a URL
|
20
|
+
#
|
21
|
+
# @param [String] text the URL
|
22
|
+
# @return [String] the escaped URL
|
23
|
+
def urlencode(text)
|
24
|
+
CGI.escape(text.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Turns text into HTML using +markup+ style formatting.
|
28
|
+
#
|
29
|
+
# @param [String] text the text to format
|
30
|
+
# @param [Symbol] markup examples are +:markdown+, +:textile+, +:rdoc+.
|
31
|
+
# To add a custom markup type, see {MarkupHelper}
|
32
|
+
# @return [String] the HTML
|
33
|
+
def htmlify(text, markup = options[:markup])
|
34
|
+
return "" unless text
|
35
|
+
return text unless markup
|
36
|
+
load_markup_provider(markup)
|
37
|
+
|
38
|
+
# TODO: other libraries might be more complex
|
39
|
+
case markup
|
40
|
+
when :markdown
|
41
|
+
html = markup_class(markup).new(text).to_html
|
42
|
+
when :textile
|
43
|
+
doc = markup_class(markup).new(text)
|
44
|
+
doc.hard_breaks = false if doc.respond_to?(:hard_breaks=)
|
45
|
+
html = doc.to_html
|
46
|
+
when :rdoc
|
47
|
+
html = fix_typewriter(text)
|
48
|
+
|
49
|
+
begin
|
50
|
+
SimpleMarkupHtml.instance_variable_set("@from_path", url_for(object))
|
51
|
+
html = MarkupHelper::SimpleMarkup.convert(html, SimpleMarkupHtml)
|
52
|
+
end
|
53
|
+
|
54
|
+
html = fix_dash_dash(html)
|
55
|
+
end
|
56
|
+
|
57
|
+
html = resolve_links(html)
|
58
|
+
html = html.gsub(/<pre>(?:\s*<code>)?(.+?)(?:<\/code>\s*)?<\/pre>/m) do
|
59
|
+
str = $1
|
60
|
+
str = html_syntax_highlight(CGI.unescapeHTML(str)) unless options[:no_highlight]
|
61
|
+
%Q{<pre class="code">#{str}</pre>}
|
62
|
+
end
|
63
|
+
html
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [String] HTMLified text as a single line (paragraphs removed)
|
67
|
+
def htmlify_line(*args)
|
68
|
+
htmlify(*args).gsub(/<\/?p>/, '')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Fixes RDoc behaviour with ++ only supporting alphanumeric text.
|
72
|
+
#
|
73
|
+
# @todo Refactor into own SimpleMarkup subclass
|
74
|
+
def fix_typewriter(text)
|
75
|
+
text.gsub(/\+(?! )([^\+]{1,900})(?! )\+/) do
|
76
|
+
'<tt>' + $1.gsub(/(.)/, "\\1\004") + '</tt>'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Don't allow -- to turn into — element. The chances of this being
|
81
|
+
# some --option is far more likely than the typographical meaning.
|
82
|
+
#
|
83
|
+
# @todo Refactor into own SimpleMarkup subclass
|
84
|
+
def fix_dash_dash(text)
|
85
|
+
text.gsub(/—(?=\S)/, '--')
|
86
|
+
end
|
87
|
+
|
88
|
+
# Resolves any text in the form of +{Name}+ to the object specified by
|
89
|
+
# Name. Also supports link titles in the form +{Name title}+.
|
90
|
+
#
|
91
|
+
# @example Linking to an instance method
|
92
|
+
# resolve_links("{MyClass#method}") # => "<a href='...'>MyClass#method</a>"
|
93
|
+
# @example Linking to a class with a title
|
94
|
+
# resolve_links("{A::B::C the C class}") # => "<a href='...'>the c class</a>"
|
95
|
+
# @param [String] text the text to resolve links in
|
96
|
+
# @return [String] HTML with linkified references
|
97
|
+
def resolve_links(text)
|
98
|
+
code_tags = 0
|
99
|
+
text.gsub(/<(\/)?(pre|code|tt)|(\s|>|^)\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/) do |str|
|
100
|
+
tag = $2
|
101
|
+
closed = $1
|
102
|
+
if tag
|
103
|
+
code_tags += (closed ? -1 : 1)
|
104
|
+
next str
|
105
|
+
end
|
106
|
+
next str unless code_tags == 0
|
107
|
+
|
108
|
+
sp, name = $3, $4
|
109
|
+
title = $5 || name
|
110
|
+
|
111
|
+
case name
|
112
|
+
when %r{://}, /^mailto:/
|
113
|
+
sp + link_url(name, title, :target => '_parent')
|
114
|
+
when /^file:(\S+?)(?:#(\S+))?$/
|
115
|
+
sp + link_file($1, title == name ? $1 : title, $2)
|
116
|
+
else
|
117
|
+
if object.is_a?(String)
|
118
|
+
obj = name
|
119
|
+
else
|
120
|
+
obj = Registry.resolve(object, name, true, true)
|
121
|
+
if obj.is_a?(CodeObjects::Proxy)
|
122
|
+
match = text[/(.{0,20}\{.*?#{Regexp.quote name}.*?\}.{0,20})/, 1]
|
123
|
+
log.warn "In file `#{object.file}':#{object.line}: Cannot resolve link to #{obj.path} from text" + (match ? ":" : ".")
|
124
|
+
log.warn '...' + match.gsub(/\n/,"\n\t") + '...' if match
|
125
|
+
end
|
126
|
+
"#{sp}<tt>" + linkify(obj, title) + "</tt>"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def format_object_name_list(objects)
|
133
|
+
objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
|
134
|
+
"<span class='name'>" + linkify(o, o.name) + "</span>"
|
135
|
+
end.join(", ")
|
136
|
+
end
|
137
|
+
|
138
|
+
# Formats a list of types from a tag.
|
139
|
+
#
|
140
|
+
# @param [Array<String>, FalseClass] typelist
|
141
|
+
# the list of types to be formatted.
|
142
|
+
#
|
143
|
+
# @param [Boolean] brackets omits the surrounding
|
144
|
+
# brackets if +brackets+ is set to +false+.
|
145
|
+
#
|
146
|
+
# @return [String] the list of types formatted
|
147
|
+
# as [Type1, Type2, ...] with the types linked
|
148
|
+
# to their respective descriptions.
|
149
|
+
#
|
150
|
+
def format_types(typelist, brackets = true)
|
151
|
+
return unless typelist.is_a?(Array)
|
152
|
+
list = typelist.map do |type|
|
153
|
+
type = type.gsub(/([<>])/) { h($1) }
|
154
|
+
type = type.gsub(/([\w:]+)/) { $1 == "lt" || $1 == "gt" ? $1 : linkify($1, $1) }
|
155
|
+
"<tt>" + type + "</tt>"
|
156
|
+
end
|
157
|
+
list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
|
158
|
+
end
|
159
|
+
|
160
|
+
def link_file(filename, title = nil, anchor = nil)
|
161
|
+
link_url(url_for_file(filename, anchor), title)
|
162
|
+
end
|
163
|
+
|
164
|
+
def link_object(obj, otitle = nil, anchor = nil, relative = true)
|
165
|
+
return otitle if obj.nil?
|
166
|
+
obj = Registry.resolve(object, obj, true, true) if obj.is_a?(String)
|
167
|
+
title = otitle ? otitle.to_s : h(obj.path)
|
168
|
+
title = "Top Level Namespace" if title == "" && obj == Registry.root
|
169
|
+
return title unless serializer
|
170
|
+
|
171
|
+
return title if obj.is_a?(CodeObjects::Proxy)
|
172
|
+
|
173
|
+
link = url_for(obj, anchor, relative)
|
174
|
+
link ? link_url(link, title) : title
|
175
|
+
end
|
176
|
+
|
177
|
+
def link_url(url, title = nil, params = {})
|
178
|
+
params = SymbolHash.new(false).update(
|
179
|
+
:href => url,
|
180
|
+
:title => title || url
|
181
|
+
).update(params)
|
182
|
+
"<a #{tag_attrs(params)}>#{title}</a>"
|
183
|
+
end
|
184
|
+
|
185
|
+
def tag_attrs(opts = {})
|
186
|
+
opts.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
|
187
|
+
end
|
188
|
+
|
189
|
+
def anchor_for(object)
|
190
|
+
case object
|
191
|
+
when CodeObjects::MethodObject
|
192
|
+
"#{object.name}-#{object.scope}_#{object.type}"
|
193
|
+
when CodeObjects::ClassVariableObject
|
194
|
+
"#{object.name.to_s.gsub('@@', '')}-#{object.type}"
|
195
|
+
when CodeObjects::Base
|
196
|
+
"#{object.name}-#{object.type}"
|
197
|
+
when CodeObjects::Proxy
|
198
|
+
object.path
|
199
|
+
else
|
200
|
+
object.to_s
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def url_for(obj, anchor = nil, relative = true)
|
205
|
+
link = nil
|
206
|
+
return link unless serializer
|
207
|
+
|
208
|
+
if obj.is_a?(CodeObjects::Base) && !obj.is_a?(CodeObjects::NamespaceObject)
|
209
|
+
# If the obj is not a namespace obj make it the anchor.
|
210
|
+
anchor, obj = obj, obj.namespace
|
211
|
+
end
|
212
|
+
|
213
|
+
objpath = serializer.serialized_path(obj)
|
214
|
+
return link unless objpath
|
215
|
+
|
216
|
+
if relative
|
217
|
+
fromobj = object
|
218
|
+
if object.is_a?(CodeObjects::Base) &&
|
219
|
+
!object.is_a?(CodeObjects::NamespaceObject)
|
220
|
+
fromobj = fromobj.namespace
|
221
|
+
end
|
222
|
+
|
223
|
+
from = serializer.serialized_path(fromobj)
|
224
|
+
link = File.relative_path(from, objpath)
|
225
|
+
else
|
226
|
+
link = objpath
|
227
|
+
end
|
228
|
+
|
229
|
+
link + (anchor ? '#' + urlencode(anchor_for(anchor)) : '')
|
230
|
+
end
|
231
|
+
|
232
|
+
def url_for_file(filename, anchor = nil)
|
233
|
+
fromobj = object
|
234
|
+
if CodeObjects::Base === fromobj && !fromobj.is_a?(CodeObjects::NamespaceObject)
|
235
|
+
fromobj = fromobj.namespace
|
236
|
+
end
|
237
|
+
from = serializer.serialized_path(fromobj)
|
238
|
+
if filename == options[:readme]
|
239
|
+
filename = 'index'
|
240
|
+
else
|
241
|
+
filename = 'file.' + File.basename(filename).gsub(/\..+$/, '')
|
242
|
+
end
|
243
|
+
link = File.relative_path(from, filename)
|
244
|
+
link + '.html' + (anchor ? '#' + urlencode(anchor) : '')
|
245
|
+
end
|
246
|
+
|
247
|
+
def signature(meth, link = true, show_extras = true)
|
248
|
+
if link
|
249
|
+
type = (meth.tag(:return) && meth.tag(:return).types ? meth.tag(:return).types.first : nil) || "Object"
|
250
|
+
type = h(type)
|
251
|
+
else
|
252
|
+
arr = meth.tag(:return) ? [(meth.tag(:return).types || []).first].compact : []
|
253
|
+
arr << "Object" if arr.empty?
|
254
|
+
type = format_types(arr, false)
|
255
|
+
end
|
256
|
+
|
257
|
+
scope = meth.scope == :class ? "+" : "-"
|
258
|
+
name = meth.name
|
259
|
+
blk = format_block(meth)
|
260
|
+
args = format_args(meth)
|
261
|
+
extras = []
|
262
|
+
extras_text = ''
|
263
|
+
if show_extras
|
264
|
+
if rw = meth.namespace.attributes[meth.scope][meth.name]
|
265
|
+
attname = [rw[:read] ? 'read' : nil, rw[:write] ? 'write' : nil].compact
|
266
|
+
attname = attname.size == 1 ? attname.join('') + 'only' : nil
|
267
|
+
extras << attname if attname
|
268
|
+
end
|
269
|
+
extras << meth.visibility if meth.visibility != :public
|
270
|
+
extras_text = ' <span class="extras">(' + extras.join(", ") + ')</span>' unless extras.empty?
|
271
|
+
end
|
272
|
+
title = "%s (%s) <strong>%s</strong>%s %s" % [scope, type, name, args, blk]
|
273
|
+
if link
|
274
|
+
if meth.is_a?(YARD::CodeObjects::MethodObject)
|
275
|
+
link_title = "#{meth.name(true)} (#{meth.scope} #{meth.type})"
|
276
|
+
else
|
277
|
+
link_title = "#{name} (#{meth.type})"
|
278
|
+
end
|
279
|
+
link_url(url_for(meth), title, :title => link_title) + extras_text
|
280
|
+
else
|
281
|
+
title + extras_text
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|