yard 0.5.8 → 0.6.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 +2 -0
- data/ChangeLog +1064 -0
- data/README.md +103 -42
- data/Rakefile +3 -2
- data/benchmarks/parsing.rb +2 -1
- data/bin/yard +4 -0
- data/bin/yard-graph +1 -1
- data/bin/yard-server +4 -0
- data/docs/GettingStarted.md +8 -8
- data/docs/Handlers.md +5 -5
- data/docs/Overview.md +5 -5
- data/docs/Parser.md +1 -1
- data/docs/Tags.md +1 -1
- data/docs/Templates.md +27 -6
- data/docs/WhatsNew.md +222 -2
- data/lib/rubygems_plugin.rb +1 -0
- data/lib/yard.rb +7 -1
- data/lib/yard/autoload.rb +46 -6
- data/lib/yard/cli/{base.rb → command.rb} +20 -6
- data/lib/yard/cli/command_parser.rb +87 -0
- data/lib/yard/cli/diff.rb +176 -0
- data/lib/yard/cli/gems.rb +74 -0
- data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
- data/lib/yard/cli/help.rb +18 -0
- data/lib/yard/cli/server.rb +137 -0
- data/lib/yard/cli/stats.rb +210 -0
- data/lib/yard/cli/yardoc.rb +315 -116
- data/lib/yard/cli/yri.rb +45 -4
- data/lib/yard/code_objects/base.rb +73 -30
- data/lib/yard/code_objects/class_object.rb +9 -1
- data/lib/yard/code_objects/method_object.rb +11 -0
- data/lib/yard/code_objects/namespace_object.rb +8 -2
- data/lib/yard/code_objects/proxy.rb +2 -2
- data/lib/yard/core_ext/array.rb +3 -49
- data/lib/yard/core_ext/file.rb +7 -0
- data/lib/yard/core_ext/insertion.rb +60 -0
- data/lib/yard/docstring.rb +34 -7
- data/lib/yard/globals.rb +2 -2
- data/lib/yard/handlers/base.rb +101 -20
- data/lib/yard/handlers/processor.rb +23 -7
- data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
- data/lib/yard/handlers/ruby/base.rb +71 -2
- data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
- data/lib/yard/handlers/ruby/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
- data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
- data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
- data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
- data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
- data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
- data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
- data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
- data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
- data/lib/yard/handlers/ruby/method_handler.rb +5 -1
- data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
- data/lib/yard/handlers/ruby/module_handler.rb +1 -0
- data/lib/yard/handlers/ruby/process_handler.rb +7 -1
- data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
- data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
- data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
- data/lib/yard/logging.rb +7 -1
- data/lib/yard/parser/base.rb +1 -0
- data/lib/yard/parser/c_parser.rb +2 -0
- data/lib/yard/parser/ruby/ast_node.rb +82 -63
- data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
- data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
- data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
- data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
- data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
- data/lib/yard/parser/source_parser.rb +6 -1
- data/lib/yard/registry.rb +284 -278
- data/lib/yard/registry_store.rb +4 -2
- data/lib/yard/serializers/base.rb +30 -13
- data/lib/yard/serializers/file_system_serializer.rb +10 -1
- data/lib/yard/server/adapter.rb +51 -0
- data/lib/yard/server/commands/base.rb +98 -0
- data/lib/yard/server/commands/display_file_command.rb +20 -0
- data/lib/yard/server/commands/display_object_command.rb +50 -0
- data/lib/yard/server/commands/frames_command.rb +31 -0
- data/lib/yard/server/commands/library_command.rb +83 -0
- data/lib/yard/server/commands/library_index_command.rb +23 -0
- data/lib/yard/server/commands/list_command.rb +44 -0
- data/lib/yard/server/commands/search_command.rb +67 -0
- data/lib/yard/server/commands/static_file_command.rb +45 -0
- data/lib/yard/server/doc_server_helper.rb +22 -0
- data/lib/yard/server/doc_server_serializer.rb +29 -0
- data/lib/yard/server/library_version.rb +86 -0
- data/lib/yard/server/rack_adapter.rb +38 -0
- data/lib/yard/server/router.rb +110 -0
- data/lib/yard/server/static_caching.rb +16 -0
- data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
- data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
- data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
- data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
- data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
- data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
- data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
- data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
- data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
- data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
- data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
- data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
- data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
- data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
- data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
- data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
- data/lib/yard/server/webrick_adapter.rb +38 -0
- data/lib/yard/tags/default_factory.rb +0 -5
- data/lib/yard/tags/library.rb +61 -22
- data/lib/yard/tags/tag.rb +26 -4
- data/lib/yard/templates/engine.rb +12 -1
- data/lib/yard/templates/erb_cache.rb +2 -1
- data/lib/yard/templates/helpers/base_helper.rb +96 -3
- data/lib/yard/templates/helpers/filter_helper.rb +5 -0
- data/lib/yard/templates/helpers/html_helper.rb +204 -94
- data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
- data/lib/yard/templates/helpers/markup_helper.rb +58 -3
- data/lib/yard/templates/helpers/method_helper.rb +7 -0
- data/lib/yard/templates/helpers/module_helper.rb +5 -0
- data/lib/yard/templates/helpers/text_helper.rb +10 -1
- data/lib/yard/templates/helpers/uml_helper.rb +13 -0
- data/lib/yard/templates/section.rb +106 -0
- data/lib/yard/templates/template.rb +20 -19
- data/lib/yard/verifier.rb +21 -2
- data/spec/cli/command_parser_spec.rb +43 -0
- data/spec/cli/diff_spec.rb +170 -0
- data/spec/cli/help_spec.rb +22 -0
- data/spec/cli/server_spec.rb +140 -0
- data/spec/cli/stats_spec.rb +75 -0
- data/spec/cli/yardoc_spec.rb +438 -182
- data/spec/cli/yri_spec.rb +13 -1
- data/spec/code_objects/base_spec.rb +51 -6
- data/spec/code_objects/class_object_spec.rb +15 -1
- data/spec/code_objects/method_object_spec.rb +29 -0
- data/spec/code_objects/namespace_object_spec.rb +150 -129
- data/spec/core_ext/array_spec.rb +4 -23
- data/spec/core_ext/insertion_spec.rb +37 -0
- data/spec/docstring_spec.rb +63 -0
- data/spec/handlers/attribute_handler_spec.rb +4 -0
- data/spec/handlers/base_spec.rb +98 -26
- data/spec/handlers/class_handler_spec.rb +5 -1
- data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
- data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
- data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
- data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
- data/spec/handlers/method_handler_spec.rb +5 -0
- data/spec/handlers/module_handler_spec.rb +4 -0
- data/spec/handlers/visibility_handler_spec.rb +6 -0
- data/spec/parser/source_parser_spec.rb +24 -0
- data/spec/registry_spec.rb +44 -8
- data/spec/server/adapter_spec.rb +38 -0
- data/spec/server/commands/base_spec.rb +87 -0
- data/spec/server/commands/static_file_command_spec.rb +67 -0
- data/spec/server/doc_server_serializer_spec.rb +58 -0
- data/spec/server/router_spec.rb +115 -0
- data/spec/server/spec_helper.rb +17 -0
- data/spec/server/static_caching_spec.rb +39 -0
- data/spec/server/webrick_servlet_spec.rb +20 -0
- data/spec/templates/constant_spec.rb +40 -0
- data/spec/templates/engine_spec.rb +9 -5
- data/spec/templates/examples/class002.html +1 -3
- data/spec/templates/examples/constant001.txt +25 -0
- data/spec/templates/examples/constant002.txt +7 -0
- data/spec/templates/examples/constant003.txt +11 -0
- data/spec/templates/examples/module001.txt +1 -1
- data/spec/templates/examples/module002.html +319 -0
- data/spec/templates/helpers/base_helper_spec.rb +2 -2
- data/spec/templates/helpers/html_helper_spec.rb +93 -3
- data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
- data/spec/templates/helpers/markup_helper_spec.rb +94 -67
- data/spec/templates/helpers/shared_signature_examples.rb +9 -0
- data/spec/templates/helpers/text_helper_spec.rb +12 -0
- data/spec/templates/module_spec.rb +21 -4
- data/spec/templates/section_spec.rb +146 -0
- data/spec/templates/template_spec.rb +9 -20
- data/templates/default/class/setup.rb +5 -5
- data/templates/default/constant/text/header.erb +11 -0
- data/templates/default/constant/text/setup.rb +3 -0
- data/templates/default/fulldoc/html/css/style.css +29 -3
- data/templates/default/fulldoc/html/js/app.js +67 -1
- data/templates/default/fulldoc/html/js/full_list.js +3 -8
- data/templates/default/fulldoc/html/js/jquery.js +150 -15
- data/templates/default/fulldoc/html/setup.rb +9 -0
- data/templates/default/layout/html/footer.erb +1 -1
- data/templates/default/layout/html/setup.rb +7 -25
- data/templates/default/method_details/html/source.erb +1 -1
- data/templates/default/module/html/attribute_summary.erb +2 -2
- data/templates/default/module/html/method_summary.erb +2 -2
- data/templates/default/module/setup.rb +27 -4
- data/templates/default/onefile/html/files.erb +5 -0
- data/templates/default/onefile/html/layout.erb +22 -0
- data/templates/default/onefile/html/readme.erb +3 -0
- data/templates/default/onefile/html/setup.rb +40 -0
- data/templates/default/root/html/setup.rb +1 -0
- data/templates/default/tags/setup.rb +26 -33
- metadata +80 -10
@@ -1,6 +1,8 @@
|
|
1
1
|
module YARD
|
2
2
|
module Templates::Helpers
|
3
|
+
# Helper methods for method objects.
|
3
4
|
module MethodHelper
|
5
|
+
# @return [String] formatted arguments for a method
|
4
6
|
def format_args(object)
|
5
7
|
return if object.parameters.nil?
|
6
8
|
params = object.parameters
|
@@ -19,12 +21,14 @@ module YARD
|
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
# @return [String] formatted and linked return types for a method
|
22
25
|
def format_return_types(object)
|
23
26
|
return unless object.has_tag?(:return) && object.tag(:return).types
|
24
27
|
return if object.tag(:return).types.empty?
|
25
28
|
format_types [object.tag(:return).types.first], false
|
26
29
|
end
|
27
30
|
|
31
|
+
# @return [String] formatted block if one exists
|
28
32
|
def format_block(object)
|
29
33
|
if object.has_tag?(:yield) && object.tag(:yield).types
|
30
34
|
params = object.tag(:yield).types
|
@@ -39,12 +43,14 @@ module YARD
|
|
39
43
|
params ? h("{|" + params.join(", ") + "| ... }") : ""
|
40
44
|
end
|
41
45
|
|
46
|
+
# @return [String] formats line numbers for source code of an object
|
42
47
|
def format_lines(object)
|
43
48
|
return "" if object.source.nil? || object.line.nil?
|
44
49
|
i = -1
|
45
50
|
object.source.split(/\n/).map { object.line + (i += 1) }.join("\n")
|
46
51
|
end
|
47
52
|
|
53
|
+
# @return [String] formats source of an object
|
48
54
|
def format_code(object, show_lines = false)
|
49
55
|
i = -1
|
50
56
|
lines = object.source.split(/\n/)
|
@@ -55,6 +61,7 @@ module YARD
|
|
55
61
|
end.join("\n")
|
56
62
|
end
|
57
63
|
|
64
|
+
# @return [String] formats source code of a constant value
|
58
65
|
def format_constant(value)
|
59
66
|
sp = value.split("\n").last[/^(\s+)/, 1]
|
60
67
|
num = sp ? sp.size : 0
|
@@ -1,7 +1,12 @@
|
|
1
1
|
module YARD
|
2
2
|
module Templates
|
3
3
|
module Helpers
|
4
|
+
# Helper methods for managing module objects.
|
4
5
|
module ModuleHelper
|
6
|
+
# Prunes the method listing by running the verifier and removing attributes/aliases
|
7
|
+
# @param [Array<CodeObjects::Base>] list a list of methods
|
8
|
+
# @param [Boolean] hide_attributes whether to prune attribute methods from the list
|
9
|
+
# @return [Array<CodeObjects::Base>] a pruned list of methods
|
5
10
|
def prune_method_listing(list, hide_attributes = true)
|
6
11
|
list = run_verifier(list)
|
7
12
|
list = list.reject {|o| o.is_alias? unless CodeObjects::Proxy === o.namespace }
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module YARD
|
2
2
|
module Templates
|
3
3
|
module Helpers
|
4
|
+
# Helper methods for text template formats.
|
4
5
|
module TextHelper
|
6
|
+
# @return [String] escapes text
|
5
7
|
def h(text)
|
6
8
|
out = ""
|
7
9
|
text = text.split(/\n/)
|
@@ -16,26 +18,33 @@ module YARD
|
|
16
18
|
out
|
17
19
|
end
|
18
20
|
|
21
|
+
# @return [String] wraps text at +col+ columns.
|
19
22
|
def wrap(text, col = 72)
|
20
23
|
text.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3\n")
|
21
24
|
end
|
22
25
|
|
26
|
+
# @return [String] indents +text+ by +len+ characters.
|
23
27
|
def indent(text, len = 4)
|
24
28
|
text.gsub(/^/, ' ' * len)
|
25
29
|
end
|
26
30
|
|
31
|
+
# @return [String] aligns a title to the right
|
27
32
|
def title_align_right(text, col = 72)
|
28
33
|
align_right(text, '-', col)
|
29
34
|
end
|
30
35
|
|
36
|
+
# @return [String] aligns text to the right
|
31
37
|
def align_right(text, spacer = ' ', col = 72)
|
38
|
+
text = text[0, col - 4] + '...' if (col - 1 - text.length) < 0
|
32
39
|
spacer * (col - 1 - text.length) + " " + text
|
33
40
|
end
|
34
41
|
|
42
|
+
# @return [String] returns a horizontal rule for output
|
35
43
|
def hr(col = 72, sep = "-")
|
36
44
|
sep * col
|
37
45
|
end
|
38
46
|
|
47
|
+
# @return [String] the formatted signature for a method
|
39
48
|
def signature(meth)
|
40
49
|
# use first overload tag if it has a return type and method itself does not
|
41
50
|
if !meth.tag(:return) && meth.tag(:overload) && meth.tag(:overload).tag(:return)
|
@@ -44,7 +53,7 @@ module YARD
|
|
44
53
|
|
45
54
|
type = options[:default_return] || ""
|
46
55
|
if meth.tag(:return) && meth.tag(:return).types
|
47
|
-
types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten
|
56
|
+
types = meth.tags(:return).map {|t| t.types ? t.types : [] }.flatten.uniq
|
48
57
|
first = types.first
|
49
58
|
if types.size == 2 && types.last == 'nil'
|
50
59
|
type = first + '?'
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module YARD
|
2
2
|
module Templates::Helpers
|
3
|
+
# Helpers for UML template format
|
3
4
|
module UMLHelper
|
5
|
+
# Official UML visibility prefix syntax for an object given its visibility
|
6
|
+
# @param [CodeObjects::Base] object the object to retrieve visibility for
|
7
|
+
# @return [String] the UML visibility prefix
|
4
8
|
def uml_visibility(object)
|
5
9
|
case object.visibility
|
6
10
|
when :public; '+'
|
@@ -9,14 +13,23 @@ module YARD
|
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
16
|
+
# Formats the path of an object for Graphviz syntax
|
17
|
+
# @param [CodeObjects::Base] object an object to format the path of
|
18
|
+
# @return [String] the encoded path
|
12
19
|
def format_path(object)
|
13
20
|
object.path.gsub('::', '_')
|
14
21
|
end
|
15
22
|
|
23
|
+
# Encodes text in escaped Graphviz syntax
|
24
|
+
# @param [String] text text to encode
|
25
|
+
# @return [String] the encoded text
|
16
26
|
def h(text)
|
17
27
|
text.to_s.gsub(/(\W)/, '\\\\\1')
|
18
28
|
end
|
19
29
|
|
30
|
+
# Tidies data by formatting and indenting text
|
31
|
+
# @param [String] data pre-formatted text
|
32
|
+
# @return [String] tidied text.
|
20
33
|
def tidy(data)
|
21
34
|
indent = 0
|
22
35
|
data.split(/\n/).map do |line|
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module YARD
|
2
|
+
module Templates
|
3
|
+
# Abstracts the structure for a section and its subsections into an ordered
|
4
|
+
# list of sections and subsections.
|
5
|
+
# @since 0.6.0
|
6
|
+
class Section < Array
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
def initialize(name, *args)
|
10
|
+
self.name = name
|
11
|
+
replace(parse_sections(args))
|
12
|
+
end
|
13
|
+
|
14
|
+
def dup
|
15
|
+
obj = super
|
16
|
+
obj.name = name
|
17
|
+
obj
|
18
|
+
end
|
19
|
+
|
20
|
+
def [](*args)
|
21
|
+
if args.first.is_a?(Range) || args.size > 1
|
22
|
+
obj = super(*args)
|
23
|
+
obj.name = name
|
24
|
+
return obj
|
25
|
+
elsif args.first.is_a?(Integer)
|
26
|
+
return super(*args)
|
27
|
+
end
|
28
|
+
find {|o| o.name == args.first }
|
29
|
+
end
|
30
|
+
|
31
|
+
def eql?(other)
|
32
|
+
super(other) && name == other.name
|
33
|
+
end
|
34
|
+
|
35
|
+
def ==(other)
|
36
|
+
case other
|
37
|
+
when Section
|
38
|
+
eql?(other)
|
39
|
+
when Array
|
40
|
+
to_a == other
|
41
|
+
else
|
42
|
+
name == other
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def push(*args)
|
47
|
+
super(*parse_sections(args))
|
48
|
+
end
|
49
|
+
alias << push
|
50
|
+
|
51
|
+
def unshift(*args)
|
52
|
+
super(*parse_sections(args))
|
53
|
+
end
|
54
|
+
|
55
|
+
def inspect
|
56
|
+
n = name.respond_to?(:path) ? "T('#{name.path}')" : name.inspect
|
57
|
+
subsects = empty? ? "" : ", subsections=#{super}"
|
58
|
+
"Section(#{n}#{subsects})"
|
59
|
+
end
|
60
|
+
|
61
|
+
def place(*args)
|
62
|
+
super(*parse_sections(args))
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_a
|
66
|
+
list = [name]
|
67
|
+
unless empty?
|
68
|
+
subsects = []
|
69
|
+
each {|s| subsects += s.to_a }
|
70
|
+
list << subsects
|
71
|
+
end
|
72
|
+
list
|
73
|
+
end
|
74
|
+
|
75
|
+
def any(item)
|
76
|
+
find do |section|
|
77
|
+
return section if section == item
|
78
|
+
return section.any(item) unless section.empty?
|
79
|
+
end
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def parse_sections(args)
|
86
|
+
if args.size == 1 && args.first.is_a?(Array) && !args.first.is_a?(Section)
|
87
|
+
args = args.first
|
88
|
+
end
|
89
|
+
sections = []
|
90
|
+
args.each_with_index do |name, index|
|
91
|
+
case name
|
92
|
+
when Section; sections << name
|
93
|
+
when Array; next
|
94
|
+
else
|
95
|
+
subsections = args[index + 1].is_a?(Array) ? args[index + 1] : []
|
96
|
+
if subsections.is_a?(Section)
|
97
|
+
subsections = []
|
98
|
+
end
|
99
|
+
sections << Section.new(name, subsections)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
sections
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -4,7 +4,7 @@ module YARD
|
|
4
4
|
module Templates
|
5
5
|
module Template
|
6
6
|
attr_accessor :class, :section
|
7
|
-
attr_reader :options
|
7
|
+
attr_reader :options
|
8
8
|
|
9
9
|
class << self
|
10
10
|
# @return [Array<Module>] a list of modules to be automatically included
|
@@ -94,6 +94,13 @@ module YARD
|
|
94
94
|
def T(*path)
|
95
95
|
Engine.template(*path)
|
96
96
|
end
|
97
|
+
|
98
|
+
# Alias for creating a {Section} with arguments
|
99
|
+
# @see Section#initialize
|
100
|
+
# @since 0.6.0
|
101
|
+
def S(*args)
|
102
|
+
Section.new(*args)
|
103
|
+
end
|
97
104
|
|
98
105
|
private
|
99
106
|
|
@@ -166,7 +173,7 @@ module YARD
|
|
166
173
|
# templates, they will have {Template::ClassMethods#run} called on them.
|
167
174
|
# Any subsections can be yielded to using yield or {#yieldall}
|
168
175
|
def sections(*args)
|
169
|
-
@sections.
|
176
|
+
@sections = Section.new(nil, *args) if args.size > 0
|
170
177
|
@sections
|
171
178
|
end
|
172
179
|
|
@@ -177,6 +184,7 @@ module YARD
|
|
177
184
|
# def init
|
178
185
|
# sections :section1, :section2, [:subsection1, :etc]
|
179
186
|
# end
|
187
|
+
# @see #sections
|
180
188
|
def init
|
181
189
|
end
|
182
190
|
|
@@ -184,7 +192,7 @@ module YARD
|
|
184
192
|
# not be called directly. Instead, call the class method {ClassMethods#run}
|
185
193
|
#
|
186
194
|
# @param [Hash, nil] opts any extra options to apply to sections
|
187
|
-
# @param [Array] sects a list of sections to render
|
195
|
+
# @param [Section, Array] sects a section list of sections to render
|
188
196
|
# @param [Fixnum] start_at the index in the section list to start from
|
189
197
|
# @param [Boolean] break_first if true, renders only the first section
|
190
198
|
# @yield [opts] calls for the subsections to be rendered
|
@@ -194,20 +202,16 @@ module YARD
|
|
194
202
|
out = ""
|
195
203
|
return out if sects.nil?
|
196
204
|
sects = sects[start_at..-1] if start_at > 0
|
205
|
+
sects = Section.new(nil, sects) unless sects.is_a?(Section)
|
197
206
|
add_options(opts) do
|
198
|
-
sects.
|
199
|
-
next if Array === s
|
207
|
+
sects.each do |s|
|
200
208
|
self.section = s
|
201
|
-
self.subsections = sects[index + 1]
|
202
209
|
subsection_index = 0
|
203
210
|
value = render_section(section) do |*args|
|
204
211
|
value = with_section do
|
205
|
-
run(args.first,
|
212
|
+
run(args.first, section, subsection_index, true, &block)
|
206
213
|
end
|
207
214
|
subsection_index += 1
|
208
|
-
subsection_index += 1 until subsections.nil? ||
|
209
|
-
subsections[subsection_index].nil? ||
|
210
|
-
!subsections[subsection_index].is_a?(Array)
|
211
215
|
value
|
212
216
|
end
|
213
217
|
out << (value || "")
|
@@ -221,7 +225,7 @@ module YARD
|
|
221
225
|
#
|
222
226
|
# @param [Hash] opts extra options to be applied to subsections
|
223
227
|
def yieldall(opts = nil, &block)
|
224
|
-
with_section { run(opts,
|
228
|
+
with_section { run(opts, section, &block) }
|
225
229
|
end
|
226
230
|
|
227
231
|
# @param [String, Symbol] section the section name
|
@@ -285,7 +289,7 @@ module YARD
|
|
285
289
|
end
|
286
290
|
|
287
291
|
def inspect
|
288
|
-
"Template(#{self.class.path}) [section=#{section}]"
|
292
|
+
"Template(#{self.class.path}) [section=#{section.name}]"
|
289
293
|
end
|
290
294
|
|
291
295
|
protected
|
@@ -302,13 +306,10 @@ module YARD
|
|
302
306
|
|
303
307
|
private
|
304
308
|
|
305
|
-
def subsections=(value)
|
306
|
-
@subsections = Array === value ? value : nil
|
307
|
-
end
|
308
|
-
|
309
309
|
def render_section(section, &block)
|
310
|
+
section = section.name if section.is_a?(Section)
|
310
311
|
case section
|
311
|
-
when String, Symbol
|
312
|
+
when Section, String, Symbol
|
312
313
|
if respond_to?(section)
|
313
314
|
send(section, &block)
|
314
315
|
else
|
@@ -354,9 +355,9 @@ module YARD
|
|
354
355
|
end
|
355
356
|
|
356
357
|
def with_section(&block)
|
357
|
-
|
358
|
+
sect = section
|
358
359
|
value = yield
|
359
|
-
self.section
|
360
|
+
self.section = sect
|
360
361
|
value
|
361
362
|
end
|
362
363
|
end
|
data/lib/yard/verifier.rb
CHANGED
@@ -32,6 +32,7 @@ module YARD
|
|
32
32
|
# Verifier.new('@return && @param && @yield')
|
33
33
|
class Verifier
|
34
34
|
# @return [Array<String>] a list of all expressions the verifier checks for
|
35
|
+
# @since 0.5.6
|
35
36
|
attr_reader :expressions
|
36
37
|
|
37
38
|
def expressions=(value)
|
@@ -52,6 +53,7 @@ module YARD
|
|
52
53
|
#
|
53
54
|
# @param [Array<String>] expressions a list of expressions
|
54
55
|
# @return [void]
|
56
|
+
# @since 0.5.6
|
55
57
|
def add_expressions(*expressions)
|
56
58
|
self.expressions += expressions.flatten
|
57
59
|
end
|
@@ -77,6 +79,16 @@ module YARD
|
|
77
79
|
retval
|
78
80
|
end
|
79
81
|
|
82
|
+
# Runs a list of objects against the verifier and returns the subset
|
83
|
+
# of verified objects.
|
84
|
+
#
|
85
|
+
# @param [Array<CodeObjects::Base>] list a list of code objects
|
86
|
+
# @return [Array<CodeObjects::Base>] a list of code objects that match
|
87
|
+
# the verifier.
|
88
|
+
def run(list)
|
89
|
+
list.reject {|item| call(item).is_a?(FalseClass) }
|
90
|
+
end
|
91
|
+
|
80
92
|
protected
|
81
93
|
|
82
94
|
# @return [CodeObjects::Base] the current object being tested
|
@@ -85,6 +97,9 @@ module YARD
|
|
85
97
|
|
86
98
|
private
|
87
99
|
|
100
|
+
# @private
|
101
|
+
NILCLASS_METHODS = [:type, :method_missing]
|
102
|
+
|
88
103
|
# Modifies nil to not throw NoMethodErrors. This allows
|
89
104
|
# syntax like object.tag(:return).text to work if the #tag
|
90
105
|
# call returns nil, which means users don't need to perform
|
@@ -92,13 +107,17 @@ module YARD
|
|
92
107
|
#
|
93
108
|
# @return [void]
|
94
109
|
def modify_nilclass
|
95
|
-
|
110
|
+
NILCLASS_METHODS.each do |meth|
|
111
|
+
NilClass.send(:define_method, meth) {|*args| }
|
112
|
+
end
|
96
113
|
end
|
97
114
|
|
98
115
|
# Returns the state of NilClass back to normal
|
99
116
|
# @return [void]
|
100
117
|
def unmodify_nilclass
|
101
|
-
|
118
|
+
NILCLASS_METHODS.each do |meth|
|
119
|
+
NilClass.send(:undef_method, meth)
|
120
|
+
end
|
102
121
|
end
|
103
122
|
|
104
123
|
# Creates the +__execute+ method by evaluating the expressions
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe YARD::CLI::CommandParser do
|
4
|
+
describe '#run' do
|
5
|
+
before do
|
6
|
+
@cmd = CLI::CommandParser.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should show help if --help is provided" do
|
10
|
+
command = mock(:command)
|
11
|
+
command.should_receive(:run).with('--help')
|
12
|
+
CLI::CommandParser.commands[:foo] = command
|
13
|
+
@cmd.class.default_command = :foo
|
14
|
+
@cmd.run *%w( foo --help )
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should use default command if first argument is a switch" do
|
18
|
+
command = mock(:command)
|
19
|
+
command.should_receive(:run).with('--a', 'b', 'c')
|
20
|
+
CLI::CommandParser.commands[:foo] = command
|
21
|
+
@cmd.class.default_command = :foo
|
22
|
+
@cmd.run *%w( --a b c )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should use default command if no arguments are provided" do
|
26
|
+
command = mock(:command)
|
27
|
+
command.should_receive(:run)
|
28
|
+
CLI::CommandParser.commands[:foo] = command
|
29
|
+
@cmd.class.default_command = :foo
|
30
|
+
@cmd.run
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should list commands if command is not found" do
|
34
|
+
@cmd.should_receive(:list_commands)
|
35
|
+
@cmd.run *%w( unknown_command --args )
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should list commands if --help is provided as sole argument" do
|
39
|
+
@cmd.should_receive(:list_commands)
|
40
|
+
@cmd.run *%w( --help )
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|