yard 0.2.1 → 0.2.2
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/{LICENSE.txt → LICENSE} +1 -1
- data/README +211 -0
- data/Rakefile +31 -0
- data/benchmarks/builtins_vs_eval.rb +23 -0
- data/benchmarks/erb_vs_erubis.rb +53 -0
- data/benchmarks/generation.rb +37 -0
- data/benchmarks/parsing.rb +33 -0
- data/bin/view_generator +17 -0
- data/bin/yard-graph +4 -0
- data/bin/yardoc +1 -93
- data/bin/yri +12 -3
- data/lib/yard.rb +10 -5
- data/lib/yard/autoload.rb +116 -0
- data/lib/yard/cli/yard_graph.rb +86 -0
- data/lib/yard/cli/yardoc.rb +131 -0
- data/lib/yard/code_objects/base.rb +321 -0
- data/lib/yard/code_objects/class_object.rb +89 -0
- data/lib/yard/code_objects/class_variable_object.rb +4 -0
- data/lib/yard/code_objects/constant_object.rb +4 -0
- data/lib/yard/code_objects/method_object.rb +51 -0
- data/lib/yard/code_objects/module_object.rb +4 -0
- data/lib/yard/code_objects/namespace_object.rb +88 -0
- data/lib/yard/code_objects/proxy.rb +183 -0
- data/lib/yard/code_objects/root_object.rb +8 -0
- data/lib/yard/core_ext/file.rb +26 -0
- data/lib/yard/core_ext/logger.rb +5 -0
- data/lib/yard/core_ext/module.rb +9 -0
- data/lib/yard/core_ext/string.rb +13 -0
- data/lib/yard/core_ext/symbol_hash.rb +24 -0
- data/lib/yard/generators/attributes_generator.rb +22 -0
- data/lib/yard/generators/base.rb +285 -0
- data/lib/yard/generators/class_generator.rb +25 -0
- data/lib/yard/generators/constants_generator.rb +73 -0
- data/lib/yard/generators/constructor_generator.rb +25 -0
- data/lib/yard/generators/deprecated_generator.rb +15 -0
- data/lib/yard/generators/docstring_generator.rb +15 -0
- data/lib/yard/generators/full_doc_generator.rb +59 -0
- data/lib/yard/generators/helpers/base_helper.rb +52 -0
- data/lib/yard/generators/helpers/filter_helper.rb +21 -0
- data/lib/yard/generators/helpers/html_helper.rb +137 -0
- data/lib/yard/generators/helpers/method_helper.rb +27 -0
- data/lib/yard/generators/helpers/uml_helper.rb +16 -0
- data/lib/yard/generators/inheritance_generator.rb +16 -0
- data/lib/yard/generators/method_details_generator.rb +18 -0
- data/lib/yard/generators/method_generator.rb +31 -0
- data/lib/yard/generators/method_listing_generator.rb +105 -0
- data/lib/yard/generators/method_missing_generator.rb +25 -0
- data/lib/yard/generators/method_signature_generator.rb +19 -0
- data/lib/yard/generators/method_summary_generator.rb +21 -0
- data/lib/yard/generators/mixins_generator.rb +15 -0
- data/lib/yard/generators/module_generator.rb +22 -0
- data/lib/yard/generators/quick_doc_generator.rb +31 -0
- data/lib/yard/generators/source_generator.rb +26 -0
- data/lib/yard/generators/tags_generator.rb +50 -0
- data/lib/yard/generators/uml_generator.rb +92 -0
- data/lib/yard/generators/visibility_group_generator.rb +26 -0
- data/lib/yard/handlers/alias_handler.rb +32 -0
- data/lib/yard/handlers/attribute_handler.rb +54 -0
- data/lib/yard/handlers/base.rb +509 -0
- data/lib/yard/handlers/class_handler.rb +44 -0
- data/lib/yard/handlers/class_variable_handler.rb +13 -0
- data/lib/yard/handlers/constant_handler.rb +13 -0
- data/lib/yard/handlers/exception_handler.rb +12 -0
- data/lib/yard/handlers/method_handler.rb +27 -0
- data/lib/yard/handlers/mixin_handler.rb +16 -0
- data/lib/yard/handlers/module_handler.rb +9 -0
- data/lib/yard/handlers/visibility_handler.rb +14 -0
- data/lib/yard/handlers/yield_handler.rb +26 -0
- data/lib/yard/logging.rb +27 -0
- data/lib/yard/parser/ruby_lex.rb +1344 -0
- data/lib/yard/parser/source_parser.rb +109 -0
- data/lib/yard/parser/statement.rb +36 -0
- data/lib/yard/parser/statement_list.rb +167 -0
- data/lib/yard/parser/token_list.rb +58 -0
- data/lib/yard/rake/yardoc_task.rb +30 -0
- data/lib/yard/registry.rb +136 -0
- data/lib/yard/serializers/base.rb +16 -0
- data/lib/yard/serializers/file_system_serializer.rb +48 -0
- data/lib/yard/serializers/process_serializer.rb +14 -0
- data/lib/yard/serializers/stdout_serializer.rb +21 -0
- data/lib/yard/tags/default_factory.rb +98 -0
- data/lib/yard/tags/library.rb +109 -0
- data/lib/yard/tags/merbdoc_factory.rb +47 -0
- data/lib/yard/tags/tag.rb +35 -0
- data/spec/code_objects/base_spec.rb +219 -0
- data/spec/code_objects/class_object_spec.rb +176 -0
- data/spec/code_objects/code_object_list_spec.rb +33 -0
- data/spec/code_objects/constants_spec.rb +79 -0
- data/spec/code_objects/method_object_spec.rb +30 -0
- data/spec/code_objects/module_object_spec.rb +73 -0
- data/spec/code_objects/namespace_object_spec.rb +129 -0
- data/spec/code_objects/proxy_spec.rb +80 -0
- data/spec/code_objects/spec_helper.rb +3 -0
- data/spec/core_ext/file_spec.rb +20 -0
- data/spec/core_ext/string_spec.rb +4 -0
- data/spec/core_ext/symbol_hash_spec.rb +80 -0
- data/spec/generators/base_spec.rb +64 -0
- data/spec/generators/helpers/base_helper_spec.rb +15 -0
- data/spec/generators/helpers/html_helper_spec.rb +56 -0
- data/spec/generators/quick_doc_generator_spec.rb +13 -0
- data/spec/handlers/alias_handler_spec.rb +50 -0
- data/spec/handlers/attribute_handler_spec.rb +78 -0
- data/spec/handlers/base_spec.rb +165 -0
- data/spec/handlers/class_handler_spec.rb +68 -0
- data/spec/handlers/class_variable_handler_spec.rb +9 -0
- data/spec/handlers/constant_handler_spec.rb +13 -0
- data/spec/handlers/examples/alias_handler_001.rb.txt +24 -0
- data/spec/handlers/examples/attribute_handler_001.rb.txt +19 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +39 -0
- data/spec/handlers/examples/class_variable_handler_001.rb.txt +9 -0
- data/spec/handlers/examples/constant_handler_001.rb.txt +10 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +42 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +35 -0
- data/spec/handlers/examples/mixin_handler_001.rb.txt +12 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +16 -0
- data/spec/handlers/examples/visibility_handler_001.rb.txt +20 -0
- data/spec/handlers/examples/yield_handler_001.rb.txt +55 -0
- data/spec/handlers/exception_handler_spec.rb +35 -0
- data/spec/handlers/method_handler_spec.rb +35 -0
- data/spec/handlers/mixin_handler_spec.rb +30 -0
- data/spec/handlers/module_handler_spec.rb +25 -0
- data/spec/handlers/spec_helper.rb +21 -0
- data/spec/handlers/visibility_handler_spec.rb +24 -0
- data/spec/handlers/yield_handler_spec.rb +51 -0
- data/spec/parser/examples/example1.rb.txt +8 -0
- data/spec/parser/examples/tag_handler_001.rb.txt +8 -0
- data/spec/parser/source_parser_spec.rb +43 -0
- data/spec/parser/tag_parsing_spec.rb +18 -0
- data/spec/parser/token_list_spec.rb +35 -0
- data/spec/registry_spec.rb +70 -0
- data/spec/serializers/file_system_serializer_spec.rb +91 -0
- data/spec/serializers/spec_helper.rb +2 -0
- data/spec/spec_helper.rb +77 -0
- data/templates/default/attributes/html/header.erb +35 -0
- data/templates/default/attributes/text/header.erb +10 -0
- data/templates/default/class/html/header.erb +4 -0
- data/templates/default/constants/html/constants.erb +9 -0
- data/templates/default/constants/html/header.erb +3 -0
- data/templates/default/constants/html/included.erb +9 -0
- data/templates/default/constants/html/inherited.erb +9 -0
- data/templates/default/constructor/html/header.erb +10 -0
- data/templates/default/deprecated/html/main.erb +4 -0
- data/templates/default/deprecated/text/main.erb +3 -0
- data/templates/default/docstring/html/main.erb +3 -0
- data/templates/default/docstring/text/main.erb +3 -0
- data/templates/default/fulldoc/html/all_methods.erb +25 -0
- data/templates/default/fulldoc/html/all_namespaces.erb +19 -0
- data/templates/default/fulldoc/html/app.js +18 -0
- data/templates/default/fulldoc/html/header.erb +15 -0
- data/templates/default/fulldoc/html/html_head.erb +3 -0
- data/templates/default/fulldoc/html/index.erb +18 -0
- data/templates/default/fulldoc/html/jquery.js +11 -0
- data/templates/default/fulldoc/html/readme.erb +15 -0
- data/templates/default/fulldoc/html/style.css +65 -0
- data/templates/default/fulldoc/html/syntax_highlight.css +21 -0
- data/templates/default/inheritance/html/header.erb +8 -0
- data/templates/default/inheritance/text/header.erb +3 -0
- data/templates/default/method/html/aliases.erb +6 -0
- data/templates/default/method/html/header.erb +3 -0
- data/templates/default/method/html/title.erb +3 -0
- data/templates/default/methoddetails/html/header.erb +8 -0
- data/templates/default/methoddetails/html/method_header.erb +3 -0
- data/templates/default/methodmissing/html/header.erb +12 -0
- data/templates/default/methodsignature/html/main.erb +8 -0
- data/templates/default/methodsignature/text/main.erb +5 -0
- data/templates/default/methodsummary/html/header.erb +5 -0
- data/templates/default/methodsummary/html/included.erb +9 -0
- data/templates/default/methodsummary/html/inherited.erb +9 -0
- data/templates/default/methodsummary/html/summary.erb +25 -0
- data/templates/default/methodsummary/text/header.erb +5 -0
- 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 +3 -0
- data/templates/default/mixins/html/header.erb +4 -0
- data/templates/default/module/html/header.erb +4 -0
- data/templates/default/quickdoc/html/header.erb +15 -0
- data/templates/default/quickdoc/text/header.erb +12 -0
- data/templates/default/source/html/main.erb +15 -0
- data/templates/default/source/text/main.erb +4 -0
- data/templates/default/tags/html/header.erb +4 -0
- data/templates/default/tags/html/see.erb +13 -0
- data/templates/default/tags/html/tags.erb +20 -0
- data/templates/default/tags/text/header.erb +3 -0
- data/templates/default/tags/text/see.erb +5 -0
- data/templates/default/tags/text/tags.erb +7 -0
- data/templates/default/uml/dot/child.erb +1 -0
- data/templates/default/uml/dot/dependencies.erb +10 -0
- data/templates/default/uml/dot/header.erb +6 -0
- data/templates/default/uml/dot/info.erb +14 -0
- data/templates/default/uml/dot/subgraph.erb +6 -0
- data/templates/default/uml/dot/superclasses.erb +9 -0
- data/templates/default/uml/dot/unknown.erb +3 -0
- data/templates/default/uml/dot/unknown_child.erb +1 -0
- data/templates/default/visibilitygroup/html/header.erb +6 -0
- data/templates/javadoc/attributes/html/header.erb +16 -0
- data/templates/javadoc/class/html/header.erb +4 -0
- data/templates/javadoc/constants/html/constants.erb +9 -0
- data/templates/javadoc/constants/html/header.erb +3 -0
- data/templates/javadoc/constants/html/included.erb +12 -0
- data/templates/javadoc/constants/html/inherited.erb +12 -0
- data/templates/javadoc/constructor/html/header.erb +10 -0
- data/templates/javadoc/deprecated/html/main.erb +0 -0
- data/templates/javadoc/docstring/html/main.erb +6 -0
- data/templates/javadoc/fulldoc/html/all_methods.erb +25 -0
- data/templates/javadoc/fulldoc/html/all_namespaces.erb +19 -0
- data/templates/javadoc/fulldoc/html/app.js +18 -0
- data/templates/javadoc/fulldoc/html/header.erb +15 -0
- data/templates/javadoc/fulldoc/html/html_head.erb +3 -0
- data/templates/javadoc/fulldoc/html/index.erb +18 -0
- data/templates/javadoc/fulldoc/html/jquery.js +11 -0
- data/templates/javadoc/fulldoc/html/readme.erb +15 -0
- data/templates/javadoc/fulldoc/html/style.css +22 -0
- data/templates/javadoc/fulldoc/html/syntax_highlight.css +21 -0
- data/templates/javadoc/inheritance/html/header.erb +6 -0
- data/templates/javadoc/method/html/aliases.erb +6 -0
- data/templates/javadoc/method/html/header.erb +4 -0
- data/templates/javadoc/method/html/title.erb +4 -0
- data/templates/javadoc/methoddetails/html/header.erb +8 -0
- data/templates/javadoc/methoddetails/html/method_header.erb +0 -0
- data/templates/javadoc/methodmissing/html/header.erb +12 -0
- data/templates/javadoc/methodsignature/html/main.erb +8 -0
- data/templates/javadoc/methodsummary/html/header.erb +5 -0
- data/templates/javadoc/methodsummary/html/included.erb +12 -0
- data/templates/javadoc/methodsummary/html/inherited.erb +12 -0
- data/templates/javadoc/methodsummary/html/summary.erb +25 -0
- data/templates/javadoc/mixins/html/header.erb +5 -0
- data/templates/javadoc/module/html/header.erb +4 -0
- data/templates/javadoc/source/html/main.erb +15 -0
- data/templates/javadoc/tags/html/header.erb +5 -0
- data/templates/javadoc/tags/html/see.erb +8 -0
- data/templates/javadoc/tags/html/tags.erb +19 -0
- data/templates/javadoc/visibilitygroup/html/header.erb +5 -0
- metadata +352 -50
- data/README.pdf +0 -0
- data/lib/code_object.rb +0 -337
- data/lib/extra.rb +0 -8
- data/lib/formatter.rb +0 -90
- data/lib/handlers/all_handlers.rb +0 -2
- data/lib/handlers/attribute_handler.rb +0 -51
- data/lib/handlers/class_handler.rb +0 -30
- data/lib/handlers/class_variable_handler.rb +0 -9
- data/lib/handlers/code_object_handler.rb +0 -104
- data/lib/handlers/constant_handler.rb +0 -11
- data/lib/handlers/exception_handler.rb +0 -20
- data/lib/handlers/method_handler.rb +0 -28
- data/lib/handlers/mixin_handler.rb +0 -15
- data/lib/handlers/module_handler.rb +0 -9
- data/lib/handlers/visibility_handler.rb +0 -7
- data/lib/handlers/yield_handler.rb +0 -33
- data/lib/logger.rb +0 -19
- data/lib/namespace.rb +0 -98
- data/lib/quick_doc.rb +0 -104
- data/lib/ruby_lex.rb +0 -1321
- data/lib/source_parser.rb +0 -253
- data/lib/tag_library.rb +0 -175
- data/lib/tag_type.rb +0 -155
- data/templates/default/html/_fulldoc.erb +0 -64
- data/templates/default/html/class.erb +0 -226
- data/templates/default/html/method.erb +0 -20
- data/templates/default/html/module.erb +0 -126
- data/test/fixtures/docstring.txt +0 -23
- data/test/fixtures/docstring2.txt +0 -4
- data/test/test_code_object.rb +0 -66
- data/test/test_namespace.rb +0 -10
@@ -0,0 +1,25 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators
|
3
|
+
class ConstructorGenerator < Base
|
4
|
+
before_generate :has_constructor?
|
5
|
+
|
6
|
+
def sections_for(object)
|
7
|
+
[:header, [G(MethodGenerator)]]
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def has_constructor?
|
13
|
+
constructor_method ? true : false
|
14
|
+
end
|
15
|
+
|
16
|
+
def constructor_method
|
17
|
+
current_object.meths.find {|o| o.name == :initialize && o.scope == :instance }
|
18
|
+
end
|
19
|
+
|
20
|
+
def constructor_method_inherited?
|
21
|
+
constructor_method.namespace != current_object
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators
|
3
|
+
class DeprecatedGenerator < Base
|
4
|
+
before_generate :is_deprecated?
|
5
|
+
|
6
|
+
def sections_for(object) [:main] end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def is_deprecated?(object)
|
11
|
+
object.tag(:deprecated) ? true : false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators
|
3
|
+
class FullDocGenerator < Base
|
4
|
+
before_generate :is_namespace?
|
5
|
+
before_list :generate_assets
|
6
|
+
before_list :generate_index
|
7
|
+
before_list :generate_readme
|
8
|
+
|
9
|
+
def sections_for(object)
|
10
|
+
case object
|
11
|
+
when CodeObjects::ClassObject
|
12
|
+
[:header, [G(ClassGenerator)]]
|
13
|
+
when CodeObjects::ModuleObject
|
14
|
+
[:header, [G(ModuleGenerator)]]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def css_file; 'style.css' end
|
21
|
+
def css_syntax_file; 'syntax_highlight.css' end
|
22
|
+
def js_file; 'jquery.js' end
|
23
|
+
def js_app_file; 'app.js' end
|
24
|
+
|
25
|
+
def readme_file
|
26
|
+
@readme_file ||= [options[:readme]].flatten.compact.find do |readme|
|
27
|
+
File.exists?(readme.to_s)
|
28
|
+
end.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_assets
|
32
|
+
if format == :html && serializer
|
33
|
+
[css_file, css_syntax_file, js_file, js_app_file].each do |filename|
|
34
|
+
template_file = find_template template_path(filename)
|
35
|
+
serializer.serialize(filename, File.read(template_file))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_index
|
42
|
+
if format == :html && serializer
|
43
|
+
serializer.serialize 'index.html', render(:index)
|
44
|
+
serializer.serialize 'all-namespaces.html', render(:all_namespaces)
|
45
|
+
serializer.serialize 'all-methods.html', render(:all_methods)
|
46
|
+
end
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def generate_readme
|
51
|
+
if format == :html && serializer && readme_file
|
52
|
+
@contents = File.read(readme_file)
|
53
|
+
serializer.serialize 'readme.html', render(:readme)
|
54
|
+
end
|
55
|
+
true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module YARD::Generators::Helpers
|
2
|
+
module BaseHelper
|
3
|
+
# This is used a lot by the HtmlHelper and there should
|
4
|
+
# be some helper to "clean up" text for whatever, this is it.
|
5
|
+
def h(text)
|
6
|
+
text
|
7
|
+
end
|
8
|
+
|
9
|
+
def linkify(*args)
|
10
|
+
# The :// character sequence exists in no valid object path but just about every URL scheme.
|
11
|
+
if args.first.is_a?(String) && args.first.include?("://")
|
12
|
+
link_url(*args)
|
13
|
+
else
|
14
|
+
link_object(*args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def link_object(object, title = nil)
|
19
|
+
return title if title
|
20
|
+
|
21
|
+
case object
|
22
|
+
when YARD::CodeObjects::Base, YARD::CodeObjects::Proxy
|
23
|
+
object.path
|
24
|
+
when String, Symbol
|
25
|
+
P(object).path
|
26
|
+
else
|
27
|
+
object
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def link_url(url)
|
32
|
+
url
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_object_name_list(objects)
|
36
|
+
objects.sort_by {|o| o.name.to_s.downcase }.join(", ")
|
37
|
+
end
|
38
|
+
|
39
|
+
def format_types(list, brackets = true)
|
40
|
+
list.empty? ? "" : (brackets ? "[#{list.join(", ")}]" : list.join(", "))
|
41
|
+
end
|
42
|
+
|
43
|
+
def format_object_type(object)
|
44
|
+
case object
|
45
|
+
when YARD::CodeObjects::ClassObject
|
46
|
+
object.is_exception? ? "Exception" : "Class"
|
47
|
+
else
|
48
|
+
object.type.to_s.capitalize
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators::Helpers
|
3
|
+
module FilterHelper
|
4
|
+
def is_method?(object)
|
5
|
+
object.is_a?(CodeObjects::MethodObject)
|
6
|
+
end
|
7
|
+
|
8
|
+
def is_namespace?(object)
|
9
|
+
object.is_a?(CodeObjects::NamespaceObject)
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_class?(object)
|
13
|
+
object.is_a?(CodeObjects::ClassObject)
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_module?(object)
|
17
|
+
object.is_a?(CodeObjects::ModuleObject)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'rdoc/markup/simple_markup'
|
3
|
+
require 'rdoc/markup/simple_markup/to_html'
|
4
|
+
|
5
|
+
module YARD
|
6
|
+
module Generators::Helpers
|
7
|
+
module HtmlHelper
|
8
|
+
SimpleMarkup = SM::SimpleMarkup.new
|
9
|
+
SimpleMarkupHtml = SM::ToHtml.new
|
10
|
+
|
11
|
+
def h(text)
|
12
|
+
CGI.escapeHTML(text.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def urlencode(text)
|
16
|
+
CGI.escape(text.to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def htmlify(text)
|
20
|
+
html = resolve_links SimpleMarkup.convert(text, SimpleMarkupHtml)
|
21
|
+
html = html.gsub(/<pre>(.+?)<\/pre>/m) { '<pre class="code">' + html_syntax_highlight(CGI.unescapeHTML($1)) + '</pre>' }
|
22
|
+
html
|
23
|
+
end
|
24
|
+
|
25
|
+
def resolve_links(text)
|
26
|
+
text.gsub(/(\s)\{(\S+?)(?:\s(.+?))?\}(?=(?:[\s\.,:!;\?][^<>]*)?<\/(?!pre))/) do
|
27
|
+
name = $2
|
28
|
+
title = $3 || $2
|
29
|
+
obj = P(current_object, name)
|
30
|
+
if obj.is_a?(CodeObjects::Proxy)
|
31
|
+
log.warn "In documentation for #{current_object.path}: Cannot resolve link to #{obj.path} from text:"
|
32
|
+
log.warn '...' + text[/(.{0,20}\{#{Regexp.quote name}.*?\}.{0,20})/, 1].gsub(/\n/,"\n\t") + '...'
|
33
|
+
end
|
34
|
+
|
35
|
+
" <tt>" + linkify(obj, title) + "</tt>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def format_object_name_list(objects)
|
40
|
+
objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
|
41
|
+
"<span class='name'>" + linkify(o, o.name) + "</span>"
|
42
|
+
end.join(", ")
|
43
|
+
end
|
44
|
+
|
45
|
+
# Formats a list of types from a tag.
|
46
|
+
#
|
47
|
+
# @param [Array<String>, FalseClass] typelist
|
48
|
+
# the list of types to be formatted.
|
49
|
+
#
|
50
|
+
# @param [Boolean] brackets omits the surrounding
|
51
|
+
# brackets if +brackets+ is set to +false+.
|
52
|
+
#
|
53
|
+
# @return [String] the list of types formatted
|
54
|
+
# as [Type1, Type2, ...] with the types linked
|
55
|
+
# to their respective descriptions.
|
56
|
+
#
|
57
|
+
def format_types(typelist, brackets = true)
|
58
|
+
list = typelist.map do |type|
|
59
|
+
"<tt>" + type.gsub(/(^|[<>])\s*([^<>#]+)\s*(?=[<>]|$)/) {|m| h($1) + linkify($2, $2) } + "</tt>"
|
60
|
+
end
|
61
|
+
list.empty? ? "" : (brackets ? "[#{list.join(", ")}]" : list.join(", "))
|
62
|
+
end
|
63
|
+
|
64
|
+
def link_object(object, otitle = nil, anchor = nil)
|
65
|
+
object = P(current_object, object) if object.is_a?(String)
|
66
|
+
title = h(otitle ? otitle.to_s : object.path)
|
67
|
+
return title unless serializer
|
68
|
+
|
69
|
+
return title if object.is_a?(CodeObjects::Proxy)
|
70
|
+
|
71
|
+
link = url_for(object, anchor)
|
72
|
+
link ? "<a href='#{link}' title='#{title}'>#{title}</a>" : title
|
73
|
+
end
|
74
|
+
|
75
|
+
def anchor_for(object)
|
76
|
+
urlencode case object
|
77
|
+
when CodeObjects::MethodObject
|
78
|
+
"#{object.name}-#{object.scope}_#{object.type}"
|
79
|
+
when CodeObjects::Base
|
80
|
+
"#{object.name}-#{object.type}"
|
81
|
+
when CodeObjects::Proxy
|
82
|
+
object.path
|
83
|
+
else
|
84
|
+
object.to_s
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def url_for(object, anchor = nil, relative = true)
|
89
|
+
link = nil
|
90
|
+
return link unless serializer
|
91
|
+
|
92
|
+
if object.is_a?(CodeObjects::Base) && !object.is_a?(CodeObjects::NamespaceObject)
|
93
|
+
# If the object is not a namespace object make it the anchor.
|
94
|
+
anchor, object = object, object.namespace
|
95
|
+
end
|
96
|
+
|
97
|
+
objpath = serializer.serialized_path(object)
|
98
|
+
return link unless objpath
|
99
|
+
|
100
|
+
if relative
|
101
|
+
fromobj = current_object
|
102
|
+
if current_object.is_a?(CodeObjects::Base) &&
|
103
|
+
!current_object.is_a?(CodeObjects::NamespaceObject)
|
104
|
+
fromobj = fromobj.namespace
|
105
|
+
end
|
106
|
+
|
107
|
+
from = serializer.serialized_path(fromobj)
|
108
|
+
link = File.relative_path(from, objpath)
|
109
|
+
else
|
110
|
+
link = objpath
|
111
|
+
end
|
112
|
+
|
113
|
+
link + (anchor ? '#' + anchor_for(anchor) : '')
|
114
|
+
end
|
115
|
+
|
116
|
+
def html_syntax_highlight(source)
|
117
|
+
tokenlist = Parser::TokenList.new(source)
|
118
|
+
tokenlist.map do |s|
|
119
|
+
prettyclass = s.class.class_name.sub(/^Tk/, '').downcase
|
120
|
+
prettysuper = s.class.superclass.class_name.sub(/^Tk/, '').downcase
|
121
|
+
|
122
|
+
case s
|
123
|
+
when Parser::RubyToken::TkWhitespace, Parser::RubyToken::TkUnknownChar
|
124
|
+
h s.text
|
125
|
+
when Parser::RubyToken::TkId
|
126
|
+
prettyval = h(s.text)
|
127
|
+
"<span class='#{prettyval} #{prettyclass} #{prettysuper}'>#{prettyval}</span>"
|
128
|
+
else
|
129
|
+
"<span class='#{prettyclass} #{prettysuper}'>#{h s.text}</span>"
|
130
|
+
end
|
131
|
+
end.join
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators::Helpers
|
3
|
+
module MethodHelper
|
4
|
+
def format_args(object)
|
5
|
+
if object.signature
|
6
|
+
h object.signature[/#{Regexp.quote object.name.to_s}\s*(.*)/, 1]
|
7
|
+
else
|
8
|
+
h "def #{object.name}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def format_return_types(object)
|
13
|
+
if object.has_tag?(:return) && !object.tag(:return).types.empty?
|
14
|
+
format_types [object.tag(:return).types.first], false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def format_block(object)
|
19
|
+
if object.has_tag?(:yieldparam)
|
20
|
+
h "{|" + object.tags(:yieldparam).map {|t| t.name }.join(", ") + "| ... }"
|
21
|
+
else
|
22
|
+
""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators
|
3
|
+
class InheritanceGenerator < Base
|
4
|
+
before_generate :has_inheritance_tree?
|
5
|
+
|
6
|
+
def sections_for(object) [:header] end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def has_inheritance_tree?(object)
|
11
|
+
return false unless object.is_a?(CodeObjects::ClassObject)
|
12
|
+
object.inheritance_tree.size > 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators
|
3
|
+
class MethodDetailsGenerator < MethodListingGenerator
|
4
|
+
before_generate :is_namespace?
|
5
|
+
before_generate :has_methods?
|
6
|
+
|
7
|
+
def sections_for(object)
|
8
|
+
[
|
9
|
+
:header,
|
10
|
+
[ # with MethodObject
|
11
|
+
:method_header,
|
12
|
+
G(MethodGenerator),
|
13
|
+
]
|
14
|
+
]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module YARD
|
2
|
+
module Generators
|
3
|
+
class MethodGenerator < Base
|
4
|
+
before_generate :is_method?
|
5
|
+
before_section :aliases, :has_aliases?
|
6
|
+
|
7
|
+
def sections_for(object)
|
8
|
+
[
|
9
|
+
:header,
|
10
|
+
[
|
11
|
+
:title,
|
12
|
+
[
|
13
|
+
G(MethodSignatureGenerator),
|
14
|
+
:aliases
|
15
|
+
],
|
16
|
+
G(DeprecatedGenerator),
|
17
|
+
G(DocstringGenerator),
|
18
|
+
G(TagsGenerator),
|
19
|
+
G(SourceGenerator)
|
20
|
+
]
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def has_aliases?(object)
|
27
|
+
!object.aliases.empty?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|