yard 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of yard might be problematic. Click here for more details.
- data/LICENSE +1 -1
- data/README.markdown +200 -0
- data/Rakefile +6 -1
- data/benchmarks/format_args.rb +46 -0
- data/benchmarks/parsing.rb +13 -1
- data/benchmarks/rdoc_vs_yardoc.rb +10 -0
- data/benchmarks/ripper_parser.rb +12 -0
- data/docs/CODE_OBJECTS.markdown +121 -0
- data/docs/FAQ.markdown +34 -0
- data/docs/GENERATORS.markdown +211 -0
- data/docs/GETTING_STARTED.markdown +263 -0
- data/docs/GLOSSARY.markdown +13 -0
- data/docs/HANDLERS.markdown +158 -0
- data/docs/OVERVIEW.markdown +64 -0
- data/docs/PARSER.markdown +180 -0
- data/docs/TAGS.markdown +181 -0
- data/docs/WHATSNEW.markdown +96 -0
- data/docs/images/code-objects-class-diagram.png +0 -0
- data/docs/images/handlers-class-diagram.png +0 -0
- data/docs/images/overview-class-diagram.png +0 -0
- data/docs/images/parser-class-diagram.png +0 -0
- data/docs/images/tags-class-diagram.png +0 -0
- data/lib/yard.rb +4 -1
- data/lib/yard/autoload.rb +79 -31
- data/lib/yard/cli/yard_graph.rb +8 -2
- data/lib/yard/cli/yardoc.rb +61 -8
- data/lib/yard/code_objects/base.rb +78 -135
- data/lib/yard/code_objects/class_object.rb +9 -8
- data/lib/yard/code_objects/constant_object.rb +1 -0
- data/lib/yard/code_objects/extended_method_object.rb +9 -0
- data/lib/yard/code_objects/method_object.rb +18 -5
- data/lib/yard/code_objects/module_object.rb +8 -1
- data/lib/yard/code_objects/namespace_object.rb +25 -16
- data/lib/yard/code_objects/proxy.rb +22 -22
- data/lib/yard/core_ext/file.rb +1 -1
- data/lib/yard/core_ext/string.rb +0 -4
- data/lib/yard/core_ext/symbol_hash.rb +3 -2
- data/lib/yard/docstring.rb +180 -0
- data/lib/yard/generators/base.rb +33 -13
- data/lib/yard/generators/class_generator.rb +4 -2
- data/lib/yard/generators/constants_generator.rb +3 -2
- data/lib/yard/generators/full_doc_generator.rb +76 -9
- data/lib/yard/generators/helpers/base_helper.rb +18 -1
- data/lib/yard/generators/helpers/filter_helper.rb +2 -2
- data/lib/yard/generators/helpers/html_helper.rb +94 -39
- data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
- data/lib/yard/generators/helpers/markup_helper.rb +86 -0
- data/lib/yard/generators/helpers/method_helper.rb +23 -7
- data/lib/yard/generators/method_generator.rb +15 -3
- data/lib/yard/generators/method_listing_generator.rb +3 -3
- data/lib/yard/generators/mixins_generator.rb +8 -2
- data/lib/yard/generators/module_generator.rb +3 -2
- data/lib/yard/generators/overloads_generator.rb +20 -0
- data/lib/yard/generators/quick_doc_generator.rb +3 -9
- data/lib/yard/generators/root_generator.rb +32 -0
- data/lib/yard/generators/source_generator.rb +2 -17
- data/lib/yard/generators/tags_generator.rb +34 -6
- data/lib/yard/generators/uml_generator.rb +16 -6
- data/lib/yard/handlers/base.rb +88 -253
- data/lib/yard/handlers/processor.rb +72 -0
- data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
- data/lib/yard/handlers/ruby/base.rb +72 -0
- data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
- data/lib/yard/handlers/ruby/class_handler.rb +74 -0
- data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
- data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
- data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
- data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
- data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
- data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
- data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
- data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
- data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
- data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
- data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
- data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
- data/lib/yard/handlers/ruby/method_handler.rb +48 -0
- data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
- data/lib/yard/handlers/ruby/module_handler.rb +9 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
- data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
- data/lib/yard/parser/ruby/ast_node.rb +263 -0
- data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
- data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
- data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
- data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
- data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
- data/lib/yard/parser/source_parser.rb +76 -45
- data/lib/yard/rake/yardoc_task.rb +6 -1
- data/lib/yard/registry.rb +45 -19
- data/lib/yard/serializers/file_system_serializer.rb +8 -3
- data/lib/yard/tags/default_factory.rb +70 -10
- data/lib/yard/tags/default_tag.rb +12 -0
- data/lib/yard/tags/library.rb +65 -26
- data/lib/yard/tags/option_tag.rb +12 -0
- data/lib/yard/tags/overload_tag.rb +62 -0
- data/lib/yard/tags/ref_tag.rb +7 -0
- data/lib/yard/tags/ref_tag_list.rb +27 -0
- data/lib/yard/tags/tag.rb +1 -0
- data/lib/yard/tags/tag_format_error.rb +6 -0
- data/spec/cli/yardoc_spec.rb +43 -0
- data/spec/code_objects/base_spec.rb +56 -68
- data/spec/code_objects/class_object_spec.rb +18 -6
- data/spec/code_objects/constants_spec.rb +2 -0
- data/spec/code_objects/method_object_spec.rb +33 -5
- data/spec/code_objects/module_object_spec.rb +66 -8
- data/spec/code_objects/namespace_object_spec.rb +37 -17
- data/spec/code_objects/proxy_spec.rb +13 -2
- data/spec/core_ext/string_spec.rb +14 -2
- data/spec/core_ext/symbol_hash_spec.rb +9 -3
- data/spec/docstring_spec.rb +139 -0
- data/spec/generators/full_doc_generator_spec.rb +29 -0
- data/spec/generators/helpers/html_helper_spec.rb +74 -0
- data/spec/generators/helpers/markup_helper_spec.rb +95 -0
- data/spec/handlers/alias_handler_spec.rb +16 -3
- data/spec/handlers/attribute_handler_spec.rb +1 -1
- data/spec/handlers/base_spec.rb +15 -141
- data/spec/handlers/class_condition_handler_spec.rb +49 -0
- data/spec/handlers/class_handler_spec.rb +44 -3
- data/spec/handlers/class_variable_handler_spec.rb +1 -1
- data/spec/handlers/constant_handler_spec.rb +1 -1
- data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
- data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
- data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
- data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
- data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
- data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
- data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
- data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
- data/spec/handlers/exception_handler_spec.rb +2 -2
- data/spec/handlers/extend_handler_spec.rb +15 -0
- data/spec/handlers/legacy_base_spec.rb +128 -0
- data/spec/handlers/method_condition_handler_spec.rb +14 -0
- data/spec/handlers/method_handler_spec.rb +38 -5
- data/spec/handlers/mixin_handler_spec.rb +15 -7
- data/spec/handlers/module_handler_spec.rb +5 -1
- data/spec/handlers/processor_spec.rb +19 -0
- data/spec/handlers/ruby/base_spec.rb +90 -0
- data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
- data/spec/handlers/spec_helper.rb +22 -16
- data/spec/handlers/visibility_handler_spec.rb +4 -4
- data/spec/handlers/yield_handler_spec.rb +1 -1
- data/spec/parser/ruby/ast_node_spec.rb +15 -0
- data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
- data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
- data/spec/parser/source_parser_spec.rb +0 -15
- data/spec/rake/yardoc_task_spec.rb +48 -0
- data/spec/registry_spec.rb +28 -2
- data/spec/serializers/file_system_serializer_spec.rb +7 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/tags/default_factory_spec.rb +135 -0
- data/spec/tags/default_tag_spec.rb +11 -0
- data/spec/tags/overload_tag_spec.rb +35 -0
- data/spec/tags/ref_tag_list_spec.rb +53 -0
- data/templates/default/attributes/html/header.erb +17 -5
- data/templates/default/attributes/text/header.erb +1 -1
- data/templates/default/fulldoc/html/all_files.erb +19 -0
- data/templates/default/fulldoc/html/all_methods.erb +8 -7
- data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
- data/templates/default/fulldoc/html/app.js +1 -1
- data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
- data/templates/default/fulldoc/html/header.erb +1 -1
- data/templates/default/fulldoc/html/index.erb +4 -3
- data/templates/default/fulldoc/html/style.css +13 -3
- data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
- data/templates/default/method/text/header.erb +1 -0
- data/templates/default/method/text/title.erb +1 -0
- data/templates/default/methodsignature/html/main.erb +10 -8
- data/templates/default/methodsignature/text/main.erb +4 -1
- data/templates/default/methodsummary/html/summary.erb +8 -4
- data/templates/default/methodsummary/text/summary.erb +4 -1
- data/templates/default/mixins/html/header.erb +3 -3
- data/templates/default/overloads/html/header.erb +8 -0
- data/templates/default/overloads/text/header.erb +8 -0
- data/templates/default/root/html/header.erb +4 -0
- data/templates/default/tags/html/example.erb +20 -0
- data/templates/default/tags/html/option.erb +27 -0
- data/templates/default/tags/html/param.erb +21 -0
- data/templates/default/tags/html/tags.erb +4 -1
- data/templates/default/tags/html/todo.erb +8 -0
- data/templates/default/tags/text/example.erb +14 -0
- data/templates/default/tags/text/header.erb +3 -3
- data/templates/default/tags/text/option.erb +5 -0
- data/templates/default/tags/text/param.erb +9 -0
- data/templates/default/uml/dot/dependencies.erb +1 -1
- data/templates/default/uml/dot/info.erb +1 -1
- data/templates/default/uml/dot/superclasses.erb +2 -2
- data/templates/javadoc/methodsummary/html/summary.erb +2 -2
- data/templates/javadoc/mixins/html/header.erb +3 -3
- metadata +108 -139
- data/README +0 -211
- data/lib/yard/handlers/method_handler.rb +0 -27
- data/lib/yard/handlers/mixin_handler.rb +0 -16
- data/lib/yard/parser/statement_list.rb +0 -167
- data/lib/yard/tags/merbdoc_factory.rb +0 -47
data/lib/yard/tags/library.rb
CHANGED
@@ -5,31 +5,42 @@ module YARD
|
|
5
5
|
# a new meta tag, you can do it in one of two ways.
|
6
6
|
#
|
7
7
|
# == Method #1
|
8
|
-
#
|
9
|
-
# Example:
|
10
|
-
# def mytag_tag(text)
|
11
|
-
# Tag.parse_tag("mytag", text)
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# This will allow you to use @mytag TEXT to add meta data to classes through
|
15
|
-
# the docstring. {Tag} has a few convenience factory methods to create
|
16
|
-
#
|
17
|
-
# == Method #2
|
18
|
-
# Use {Library::define_tag!} to define a new tag by passing the tag name
|
8
|
+
# Use {Library.define_tag} to define a new tag by passing the tag name
|
19
9
|
# and the factory method to use when creating the tag. These definitions will
|
20
|
-
# be auto expanded into ruby code similar to what is shown in method #
|
21
|
-
# do not provide a factory method to use, it will default to {
|
10
|
+
# be auto expanded into ruby code similar to what is shown in method #2. If you
|
11
|
+
# do not provide a factory method to use, it will default to {DefaultFactory#parse_tag}
|
22
12
|
# Example:
|
23
13
|
# define_tag :param, :with_types_and_name
|
24
14
|
# define_tag :author
|
25
15
|
#
|
26
16
|
# The first line will expand to the code:
|
27
|
-
# def param_tag(text)
|
17
|
+
# def param_tag(text) tag_factory.parse_tag_with_types_and_name(text) end
|
28
18
|
#
|
29
19
|
# The second line will expand to:
|
30
|
-
# def author_tag(text)
|
20
|
+
# def author_tag(text) tag_factory.parse_tag(text) end
|
21
|
+
#
|
22
|
+
# Note that +tag_factory+ is the factory object used to parse tags. This value
|
23
|
+
# defaults to the {DefaultFactory} class and can be set by changing {Library.default_factory}.
|
31
24
|
#
|
32
|
-
#
|
25
|
+
# == Method #2
|
26
|
+
# Write your own +tagname_tag+ method that takes the raw text as a parameter.
|
27
|
+
# Example:
|
28
|
+
# def mytag_tag(text)
|
29
|
+
# # parse your tag contents here
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# This will allow you to use @mytag TEXT to add meta data to classes through
|
33
|
+
# the docstring. You can use the {Library#factory} object to help parse standard
|
34
|
+
# tag syntax.
|
35
|
+
#
|
36
|
+
# == Adding/Changing the Tag Syntax
|
37
|
+
# If you have specialized tag parsing needs you can substitute the {#factory}
|
38
|
+
# object with your own by setting {Library.default_factory= Library.default_factory}
|
39
|
+
# to a new class with its own parsing methods before running YARD. This is useful
|
40
|
+
# if you want to change the syntax of existing tags (@see, @since, etc.)
|
41
|
+
#
|
42
|
+
# @see DefaultFactory
|
43
|
+
# @see Library.define_tag
|
33
44
|
class Library
|
34
45
|
class << self
|
35
46
|
attr_reader :labels
|
@@ -39,6 +50,19 @@ module YARD
|
|
39
50
|
@default_factory ||= DefaultFactory.new
|
40
51
|
end
|
41
52
|
|
53
|
+
# Replace the factory object responsible for parsing tags by setting
|
54
|
+
# this to an object (or class) that responds to +parse_TAGNAME+ methods
|
55
|
+
# where +TAGNAME+ is the name of the tag.
|
56
|
+
#
|
57
|
+
# You should set this value before performing any source parsing with
|
58
|
+
# YARD, otherwise your factory class will not be used.
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# YARD::Tags::Library.default_factory = MyFactory
|
62
|
+
#
|
63
|
+
# @param [Class, Object] factory the factory that parses all tags
|
64
|
+
#
|
65
|
+
# @see DefaultFactory
|
42
66
|
def default_factory=(factory)
|
43
67
|
@default_factory = factory.is_a?(Class) ? factory.new : factory
|
44
68
|
end
|
@@ -54,16 +78,25 @@ module YARD
|
|
54
78
|
|
55
79
|
##
|
56
80
|
# Convenience method to define a new tag using one of {Tag}'s factory methods, or the
|
57
|
-
# regular {
|
81
|
+
# regular {DefaultFactory#parse_tag} factory method if none is supplied.
|
58
82
|
#
|
59
83
|
# @param [#to_s] tag the tag name to create
|
60
|
-
# @param meth the {Tag} factory method to call when
|
84
|
+
# @param [#to_s, Class<Tag>] meth the {Tag} factory method to call when
|
85
|
+
# creating the tag or the name of the class to directly create a tag for
|
61
86
|
def define_tag(label, tag, meth = "")
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
87
|
+
if meth.is_a?(Class) && Tag > meth
|
88
|
+
class_eval <<-eof, __FILE__, __LINE__
|
89
|
+
def #{tag}_tag(text, raw_text)
|
90
|
+
#{meth}.new(#{tag.inspect}, text, raw_text)
|
91
|
+
end
|
92
|
+
eof
|
93
|
+
else
|
94
|
+
class_eval <<-eof, __FILE__, __LINE__
|
95
|
+
def #{tag}_tag(text, raw_text)
|
96
|
+
send_to_factory(#{tag.inspect}, #{meth.inspect}, text, raw_text)
|
97
|
+
end
|
98
|
+
eof
|
99
|
+
end
|
67
100
|
|
68
101
|
@labels ||= SymbolHash.new(false)
|
69
102
|
@labels.update(tag => label)
|
@@ -86,12 +119,16 @@ module YARD
|
|
86
119
|
|
87
120
|
public
|
88
121
|
|
122
|
+
# A factory class to handle parsing of tags, defaults to {default_factory}
|
123
|
+
attr_accessor :factory
|
124
|
+
|
89
125
|
def initialize(factory = Library.default_factory)
|
90
|
-
|
126
|
+
self.factory = factory
|
91
127
|
end
|
92
128
|
|
93
129
|
define_tag "Parameters", :param, :with_types_and_name
|
94
130
|
define_tag "Yield Parameters", :yieldparam, :with_types_and_name
|
131
|
+
define_tag "Yield Returns", :yieldreturn, :with_types
|
95
132
|
define_tag "Yields", :yield, :with_types
|
96
133
|
define_tag "Default Value", :default, :with_name
|
97
134
|
define_tag "Returns", :return, :with_types
|
@@ -102,8 +139,10 @@ module YARD
|
|
102
139
|
define_tag "Since", :since
|
103
140
|
define_tag "Version", :version
|
104
141
|
define_tag "API Visibility", :api
|
105
|
-
define_tag "Todo Item", :todo
|
142
|
+
define_tag "Todo Item", :todo, :with_raw_title_and_text
|
106
143
|
define_tag "Example", :example, :with_raw_title_and_text
|
144
|
+
define_tag "Options Hash", :option, :with_options
|
145
|
+
define_tag "Overloads", :overload, OverloadTag
|
107
146
|
end
|
108
147
|
end
|
109
|
-
end
|
148
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module YARD
|
2
|
+
module Tags
|
3
|
+
class OverloadTag < Tag
|
4
|
+
attr_reader :signature, :parameters, :docstring
|
5
|
+
|
6
|
+
def initialize(tag_name, text, raw_text)
|
7
|
+
super(tag_name, nil)
|
8
|
+
parse_tag(raw_text)
|
9
|
+
parse_signature
|
10
|
+
end
|
11
|
+
|
12
|
+
def tag(name) docstring.tag(name) end
|
13
|
+
def tags(name = nil) docstring.tags(name) end
|
14
|
+
def has_tag?(name) docstring.has_tag?(name) end
|
15
|
+
|
16
|
+
def object=(value)
|
17
|
+
super(value)
|
18
|
+
docstring.object = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def type
|
22
|
+
object.type
|
23
|
+
end
|
24
|
+
|
25
|
+
def name(prefix = false)
|
26
|
+
object.name(prefix)
|
27
|
+
end
|
28
|
+
|
29
|
+
def inspect
|
30
|
+
"#<yardoc overload #{path}>"
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(sym, *args, &block)
|
34
|
+
object ? object.send(sym, *args, &block) : super
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def parse_tag(raw_text)
|
40
|
+
@signature, text = raw_text.split(/\r?\n/, 2)
|
41
|
+
text ||= ""
|
42
|
+
@signature.strip!
|
43
|
+
numspaces = text[/\A(\s*)/, 1].length
|
44
|
+
text.gsub!(/^[ \t]{#{numspaces}}/, '').strip!
|
45
|
+
@docstring = Docstring.new(text, nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_signature
|
49
|
+
if signature =~ /^(?:def)?\s*(#{CodeObjects::METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/m
|
50
|
+
meth, args = $1, $2
|
51
|
+
meth.gsub!(/\s+/,'')
|
52
|
+
# FIXME refactor this code to not make use of the Handlers::Base class (tokval_list should be moved)
|
53
|
+
toks = YARD::Parser::Ruby::Legacy::TokenList.new(args)
|
54
|
+
args = YARD::Handlers::Ruby::Legacy::Base.new(nil, nil).send(:tokval_list, toks, :all)
|
55
|
+
args.map! {|a| k, v = *a.split('=', 2); [k.strip.to_sym, (v ? v.strip : nil)] } if args
|
56
|
+
@name = meth.to_sym
|
57
|
+
@parameters = args
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module YARD
|
2
|
+
module Tags
|
3
|
+
class RefTagList
|
4
|
+
attr_accessor :owner, :tag_name, :name
|
5
|
+
|
6
|
+
def initialize(tag_name, owner, name = nil)
|
7
|
+
@owner = CodeObjects::Proxy === owner ? owner : P(owner)
|
8
|
+
@tag_name = tag_name.to_s
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def tags
|
13
|
+
if owner.is_a?(CodeObjects::Base)
|
14
|
+
o = owner.tags(tag_name)
|
15
|
+
o = o.select {|t| t.name.to_s == name.to_s } if name
|
16
|
+
o.each do |t|
|
17
|
+
t.extend(RefTag)
|
18
|
+
t.owner = owner
|
19
|
+
end
|
20
|
+
o
|
21
|
+
else
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/yard/tags/tag.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class YARD::CLI::Yardoc; public :optparse end
|
4
|
+
|
5
|
+
describe YARD::CLI::Yardoc do
|
6
|
+
before do
|
7
|
+
@yardoc = YARD::CLI::Yardoc.new
|
8
|
+
@yardoc.stub!(:generate).and_return(false)
|
9
|
+
Registry.instance.stub!(:load)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should select a markup provider when --markup-provider or -mp is set" do
|
13
|
+
@yardoc.optparse("-M", "test")
|
14
|
+
@yardoc.options[:markup_provider].should == :test
|
15
|
+
@yardoc.optparse("--markup-provider", "test2")
|
16
|
+
@yardoc.options[:markup_provider].should == :test2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should search for and use yardopts file specified by #options_file" do
|
20
|
+
IO.should_receive(:read).with("test").and_return("-o \n\nMYPATH\nFILE1 FILE2")
|
21
|
+
@yardoc.stub!(:support_rdoc_document_file!).and_return([])
|
22
|
+
@yardoc.options_file = "test"
|
23
|
+
@yardoc.run
|
24
|
+
@yardoc.options[:serializer].options[:basepath].should == :MYPATH
|
25
|
+
@yardoc.files.should == ["FILE1", "FILE2"]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should allow opts specified in command line to override yardopts file" do
|
29
|
+
IO.should_receive(:read).with(".yardopts").and_return("-o NOTMYPATH")
|
30
|
+
@yardoc.stub!(:support_rdoc_document_file!).and_return([])
|
31
|
+
@yardoc.run("-o", "MYPATH", "FILE")
|
32
|
+
@yardoc.options[:serializer].options[:basepath].should == :MYPATH
|
33
|
+
@yardoc.files.should == ["FILE"]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should load the RDoc .document file if found" do
|
37
|
+
IO.should_receive(:read).with(".yardopts").and_return("-o NOTMYPATH")
|
38
|
+
@yardoc.stub!(:support_rdoc_document_file!).and_return(["FILE2", "FILE3"])
|
39
|
+
@yardoc.run("-o", "MYPATH", "FILE1")
|
40
|
+
@yardoc.options[:serializer].options[:basepath].should == :MYPATH
|
41
|
+
@yardoc.files.should == ["FILE1", "FILE2", "FILE3"]
|
42
|
+
end
|
43
|
+
end
|
@@ -5,7 +5,7 @@ describe YARD::CodeObjects::Base do
|
|
5
5
|
|
6
6
|
it "should return a unique instance of any registered object" do
|
7
7
|
obj = ClassObject.new(:root, :Me)
|
8
|
-
obj2 =
|
8
|
+
obj2 = ClassObject.new(:root, :Me)
|
9
9
|
obj.object_id.should == obj2.object_id
|
10
10
|
|
11
11
|
obj3 = ModuleObject.new(obj, :Too)
|
@@ -15,6 +15,13 @@ describe YARD::CodeObjects::Base do
|
|
15
15
|
obj5 = CodeObjects::Base.new(obj3, :hello)
|
16
16
|
obj4.object_id.should_not == obj5.object_id
|
17
17
|
end
|
18
|
+
|
19
|
+
it "should create a new object if cached object is not of the same class" do
|
20
|
+
ConstantObject.new(:root, "MYMODULE").should be_instance_of(ConstantObject)
|
21
|
+
ModuleObject.new(:root, "MYMODULE").should be_instance_of(ModuleObject)
|
22
|
+
ClassObject.new(:root, "MYMODULE").should be_instance_of(ClassObject)
|
23
|
+
YARD::Registry.at("MYMODULE").should be_instance_of(ClassObject)
|
24
|
+
end
|
18
25
|
|
19
26
|
it "should recall the block if #new is called on an existing object" do
|
20
27
|
o1 = ClassObject.new(:root, :Me) do |o|
|
@@ -30,50 +37,12 @@ describe YARD::CodeObjects::Base do
|
|
30
37
|
o2.docstring.should == "NOT_DOCSTRING"
|
31
38
|
end
|
32
39
|
|
33
|
-
it "should
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
it "should return the first sentence with #short_docstring" do
|
39
|
-
o = ClassObject.new(nil, :Me)
|
40
|
-
o.docstring = "DOCSTRING. Another sentence"
|
41
|
-
o.short_docstring.should == "DOCSTRING."
|
40
|
+
it "should convert string into Docstring when #docstring= is set" do
|
41
|
+
o = ClassObject.new(:root, :Me)
|
42
|
+
o.docstring = "DOCSTRING"
|
43
|
+
o.docstring.should be_instance_of(Docstring)
|
42
44
|
end
|
43
45
|
|
44
|
-
it "should return the first paragraph with #short_docstring" do
|
45
|
-
o = ClassObject.new(nil, :Me)
|
46
|
-
o.docstring = "DOCSTRING, and other stuff\n\nAnother sentence."
|
47
|
-
o.short_docstring.should == "DOCSTRING, and other stuff."
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should return proper short_docstring when docstring is changed" do
|
51
|
-
o = ClassObject.new(:root, :Me)
|
52
|
-
o.docstring = "DOCSTRING, and other stuff\n\nAnother sentence."
|
53
|
-
o.short_docstring.should == "DOCSTRING, and other stuff."
|
54
|
-
o.docstring = "DOCSTRING."
|
55
|
-
o.short_docstring.should == "DOCSTRING."
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should not double the ending period in short_docstring" do
|
59
|
-
o = ClassObject.new(nil, :Me)
|
60
|
-
o.docstring = "Returns a list of tags specified by +name+ or all tags if +name+ is not specified.\n\nTest"
|
61
|
-
o.short_docstring.should == "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
|
62
|
-
|
63
|
-
Parser::SourceParser.parse_string <<-eof
|
64
|
-
##
|
65
|
-
# Returns a list of tags specified by +name+ or all tags if +name+ is not specified.
|
66
|
-
#
|
67
|
-
# @param name the tag name to return data for, or nil for all tags
|
68
|
-
# @return [Array<Tags::Tag>] the list of tags by the specified tag name
|
69
|
-
def tags(name = nil)
|
70
|
-
return @tags if name.nil?
|
71
|
-
@tags.select {|tag| tag.tag_name.to_s == name.to_s }
|
72
|
-
end
|
73
|
-
eof
|
74
|
-
P('#tags').short_docstring.should == "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
|
75
|
-
end
|
76
|
-
|
77
46
|
it "should allow complex name and convert that to namespace" do
|
78
47
|
obj = CodeObjects::Base.new(nil, "A::B")
|
79
48
|
obj.namespace.path.should == "A"
|
@@ -97,7 +66,6 @@ describe YARD::CodeObjects::Base do
|
|
97
66
|
obj.namespace.should == Registry.root
|
98
67
|
end
|
99
68
|
|
100
|
-
|
101
69
|
it "should not allow any other types as namespace" do
|
102
70
|
lambda { CodeObjects::Base.new("ROOT!", :Me) }.should raise_error(ArgumentError)
|
103
71
|
end
|
@@ -137,30 +105,6 @@ describe YARD::CodeObjects::Base do
|
|
137
105
|
obj.children.should include(obj2)
|
138
106
|
end
|
139
107
|
|
140
|
-
it "should parse comments into tags" do
|
141
|
-
obj = CodeObjects::Base.new(nil, :Object)
|
142
|
-
comments = <<-eof
|
143
|
-
@param name Hello world
|
144
|
-
how are you?
|
145
|
-
@param name2
|
146
|
-
this is a new line
|
147
|
-
@param name3 and this
|
148
|
-
is a new paragraph:
|
149
|
-
|
150
|
-
right here.
|
151
|
-
eof
|
152
|
-
obj.send(:parse_comments, comments)
|
153
|
-
obj.tags("param").each do |tag|
|
154
|
-
if tag.name == "name"
|
155
|
-
tag.text.should == "Hello world how are you?"
|
156
|
-
elsif tag.name == "name2"
|
157
|
-
tag.text.should == "this is a new line"
|
158
|
-
elsif tag.name == "name3"
|
159
|
-
tag.text.should == "and this is a new paragraph:\n\nright here."
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
108
|
it "should properly re-indent source starting from 0 indentation" do
|
165
109
|
obj = CodeObjects::Base.new(nil, :test)
|
166
110
|
obj.source = <<-eof
|
@@ -216,4 +160,48 @@ describe YARD::CodeObjects::Base do
|
|
216
160
|
Parser::SourceParser.parse_string "def x; 2 end"
|
217
161
|
Registry.at('#x').source.should == "def x; 2 end"
|
218
162
|
end
|
163
|
+
|
164
|
+
it "should set file and line information" do
|
165
|
+
Parser::SourceParser.parse_string <<-eof
|
166
|
+
class X; end
|
167
|
+
eof
|
168
|
+
Registry.at(:X).file.should == '(stdin)'
|
169
|
+
Registry.at(:X).line.should == 1
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should maintain all file associations when objects are defined multiple times in one file" do
|
173
|
+
Parser::SourceParser.parse_string <<-eof
|
174
|
+
class X; end
|
175
|
+
class X; end
|
176
|
+
class X; end
|
177
|
+
eof
|
178
|
+
|
179
|
+
Registry.at(:X).file.should == '(stdin)'
|
180
|
+
Registry.at(:X).line.should == 1
|
181
|
+
Registry.at(:X).files.should == [['(stdin)', 1], ['(stdin)', 2], ['(stdin)', 3]]
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should maintain all file associations when objects are defined multiple times in multiple files" do
|
185
|
+
3.times do |i|
|
186
|
+
IO.stub!(:read).and_return("class X; end")
|
187
|
+
Parser::SourceParser.new.parse("file#{i+1}.rb")
|
188
|
+
end
|
189
|
+
|
190
|
+
Registry.at(:X).file.should == 'file1.rb'
|
191
|
+
Registry.at(:X).line.should == 1
|
192
|
+
Registry.at(:X).files.should == [['file1.rb', 1], ['file2.rb', 1], ['file3.rb', 1]]
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should prioritize the definition with a docstring when returning #file" do
|
196
|
+
Parser::SourceParser.parse_string <<-eof
|
197
|
+
class X; end
|
198
|
+
class X; end
|
199
|
+
# docstring
|
200
|
+
class X; end
|
201
|
+
eof
|
202
|
+
|
203
|
+
Registry.at(:X).file.should == '(stdin)'
|
204
|
+
Registry.at(:X).line.should == 4
|
205
|
+
Registry.at(:X).files.should == [['(stdin)', 4], ['(stdin)', 1], ['(stdin)', 2]]
|
206
|
+
end
|
219
207
|
end
|