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
data/README.pdf
DELETED
Binary file
|
data/lib/code_object.rb
DELETED
@@ -1,337 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/tag_library'
|
2
|
-
require File.dirname(__FILE__) + '/formatter'
|
3
|
-
|
4
|
-
module YARD #:nodoc:
|
5
|
-
##
|
6
|
-
# The documentation parser is responsible for parsing the docstring into
|
7
|
-
# text and saving the meta tags attached to it
|
8
|
-
#
|
9
|
-
# @author Loren Segal
|
10
|
-
class CodeObject
|
11
|
-
SCOPES = [:class, :instance]
|
12
|
-
VISIBILITIES = [:private, :protected, :public]
|
13
|
-
|
14
|
-
attr_reader :source, :full_source, :file, :line, :docstring, :attributes
|
15
|
-
|
16
|
-
attr_reader :name, :type
|
17
|
-
attr_accessor :visibility, :scope
|
18
|
-
attr_accessor :parent, :children
|
19
|
-
|
20
|
-
##
|
21
|
-
# Creates a new code object with necessary information such as the object's name (not full path),
|
22
|
-
# it's type (:class, :module, :method, etc.), visibility (:public, :private, :protected) and scope
|
23
|
-
# (:instance or :class level). Optionally you can specify a parent object and comments too, but these
|
24
|
-
# can also be assigned later through the {#parent=} and {#attach_docstring} methods.
|
25
|
-
#
|
26
|
-
# @param [String] name the name of the object, not including its namespace ('initialize' for this method)
|
27
|
-
# @param [Symbol] type the type of object this is, including (but not limited to):
|
28
|
-
# :module, :class, :method, :constant
|
29
|
-
# @param [Symbol] visibility :public, :protected or :private depending on the visibility of the object
|
30
|
-
# @param [Symbol] scope :instance or :class depending on if the object is instance level or class level.
|
31
|
-
# Instance level objects use the '#' character to separate from their parent instead of '::'
|
32
|
-
# @param [CodeObject] parent The parent of this object. Without a parent this object will not be registered
|
33
|
-
# in the {Namespace}
|
34
|
-
# @param [String] comments Comments to be parsed as a docstring for the object.
|
35
|
-
# @return [CodeObject] the created code object
|
36
|
-
# @yieldparam [CodeObject] _self the object is yielded during initialization to perform any initialization operations
|
37
|
-
# on it more conveniently.
|
38
|
-
# @see #attach_docstring
|
39
|
-
# @see #parent=
|
40
|
-
def initialize(name, type, visibility = :public, scope = :instance, parent = nil, comments = nil)
|
41
|
-
@name, @type, @visibility, @scope = name, type, visibility.to_sym, scope.to_sym
|
42
|
-
@tags, @attributes, @children = [], {}, []
|
43
|
-
self.parent = parent
|
44
|
-
attach_docstring(comments)
|
45
|
-
yield(self) if block_given?
|
46
|
-
end
|
47
|
-
|
48
|
-
##
|
49
|
-
# Attaches source code to a code object with an optional file location
|
50
|
-
#
|
51
|
-
# @param [Statement, String] statement the +Statement+ holding the source code
|
52
|
-
# or the raw source as a +String+ for the
|
53
|
-
# definition of the code object only (not the block)
|
54
|
-
# @param [String] file the filename the source resides in
|
55
|
-
def attach_source(statement, file = nil)
|
56
|
-
if statement.is_a? String
|
57
|
-
@source = statement
|
58
|
-
else
|
59
|
-
@source = statement.tokens.to_s
|
60
|
-
@line = statement.tokens.first.line_no
|
61
|
-
attach_full_source statement.tokens.to_s + (statement.block.to_s rescue "")
|
62
|
-
end
|
63
|
-
@file = file
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# Manually attaches full source code for an object given the source
|
68
|
-
# as a +String+
|
69
|
-
#
|
70
|
-
# @param [String] source the source code for the object
|
71
|
-
def attach_full_source(source)
|
72
|
-
@full_source = source
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Attaches a docstring to a code oject by parsing the comments attached to the statement
|
77
|
-
# and filling the {#tags} and {#docstring} methods with the parsed information.
|
78
|
-
#
|
79
|
-
# @param [String, Array<String>] comments the comments attached to the code object to be
|
80
|
-
# parsed into a docstring and meta tags.
|
81
|
-
def attach_docstring(comments)
|
82
|
-
parse_comments(comments) if comments
|
83
|
-
end
|
84
|
-
|
85
|
-
def [](key)
|
86
|
-
@attributes[key.to_sym]
|
87
|
-
end
|
88
|
-
|
89
|
-
def []=(key, value)
|
90
|
-
@attributes[key.to_sym] = value
|
91
|
-
end
|
92
|
-
|
93
|
-
##
|
94
|
-
# Sets the parent object and registers the object path with
|
95
|
-
# the {Namespace}. If the object was already registered
|
96
|
-
# to an old path, it will be removed from the namespace.
|
97
|
-
#
|
98
|
-
# @param [CodeObject] value the new parent object
|
99
|
-
# @see Namespace
|
100
|
-
def parent=(value)
|
101
|
-
# Delete old object path if there was one
|
102
|
-
Namespace.instance.namespace.delete(path) if parent
|
103
|
-
|
104
|
-
@parent = value
|
105
|
-
|
106
|
-
# Register new path with namespace
|
107
|
-
Namespace.add_object(self) if value
|
108
|
-
end
|
109
|
-
|
110
|
-
##
|
111
|
-
# See if the method call exists in the attributes hash, and return
|
112
|
-
# it. Otherwise send the missing method call up the stack.
|
113
|
-
#
|
114
|
-
# @param meth the method name called. This method is checked in the
|
115
|
-
# attributes hash
|
116
|
-
# @param args the arguments to the call
|
117
|
-
# @param block an optional block for the call
|
118
|
-
def method_missing(meth, *args, &block)
|
119
|
-
return self[meth] if self[meth]
|
120
|
-
super
|
121
|
-
end
|
122
|
-
|
123
|
-
##
|
124
|
-
# Returns the unique path for this code object. The resulting path will be
|
125
|
-
# a Ruby style path name of the namespace the object resides in plus the
|
126
|
-
# object name delimited by a "::" or "#" depending on if the object is an
|
127
|
-
# instance level object or a class level object.
|
128
|
-
#
|
129
|
-
# Example:
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
def path
|
134
|
-
[(parent.path if parent && parent.type != :root), name].join(scope == :instance ? "#" : "::").gsub(/^::/, '').trim
|
135
|
-
end
|
136
|
-
|
137
|
-
##
|
138
|
-
# Convenience method to return the first tag
|
139
|
-
# object in the list of tag objects of that name
|
140
|
-
#
|
141
|
-
# Example:
|
142
|
-
# doc = YARD::Documentation.new("@return zero when nil")
|
143
|
-
# doc.tag("return").text # => "zero when nil"
|
144
|
-
#
|
145
|
-
# @param [#to_s] name the tag name to return data for
|
146
|
-
# @return [BaseTag] the first tag in the list of {#tags}
|
147
|
-
def tag(name)
|
148
|
-
name = name.to_s
|
149
|
-
@tags.find {|tag| tag.tag_name == name }
|
150
|
-
end
|
151
|
-
|
152
|
-
##
|
153
|
-
# Returns a list of tags specified by +name+ or all tags if +name+ is not specified.
|
154
|
-
#
|
155
|
-
# @param name the tag name to return data for, or nil for all tags
|
156
|
-
# @return [Array<BaseTag>] the list of tags by the specified tag name
|
157
|
-
def tags(name = nil)
|
158
|
-
return @tags if name.nil?
|
159
|
-
name = name.to_s
|
160
|
-
@tags.select {|tag| tag.tag_name == name }
|
161
|
-
end
|
162
|
-
|
163
|
-
##
|
164
|
-
# Returns true if at least one tag by the name +name+ was declared
|
165
|
-
#
|
166
|
-
# @param [String] name the tag name to search for
|
167
|
-
# @return [Boolean] whether or not the tag +name+ was declared
|
168
|
-
def has_tag?(name)
|
169
|
-
name = name.to_s
|
170
|
-
@tags.any? {|tag| tag.tag_name == name }
|
171
|
-
end
|
172
|
-
|
173
|
-
private
|
174
|
-
##
|
175
|
-
# Parses out comments split by newlines into a new code object
|
176
|
-
#
|
177
|
-
# @param [Array<String>, String] comments the newline delimited
|
178
|
-
# array of comments. If the comments
|
179
|
-
# are passed as a String, they will
|
180
|
-
# be split by newlines.
|
181
|
-
def parse_comments(comments)
|
182
|
-
return if comments.empty?
|
183
|
-
meta_match = /^\s*@(\S+)\s*(.*)/
|
184
|
-
comments = comments.split(/\r?\n/) if comments.is_a? String
|
185
|
-
@tags, @docstring = [], ""
|
186
|
-
|
187
|
-
indent, last_indent = comments.first[/^\s*/].length, 0
|
188
|
-
tag_name, tag_klass, tag_buf = nil, nil, ""
|
189
|
-
|
190
|
-
# Add an extra line to catch a meta directive on the last line
|
191
|
-
(comments+['']).each do |line|
|
192
|
-
indent = line[/^\s*/].length
|
193
|
-
|
194
|
-
if (indent < last_indent && tag_name) || line == '' || line =~ meta_match
|
195
|
-
tag_method = "#{tag_name}_tag"
|
196
|
-
if tag_name && TagLibrary.respond_to?(tag_method)
|
197
|
-
@tags << TagLibrary.send(tag_method, tag_buf.squeeze(" "))
|
198
|
-
end
|
199
|
-
tag_name, tag_buf = nil, ''
|
200
|
-
end
|
201
|
-
|
202
|
-
# Found a meta tag
|
203
|
-
if line =~ meta_match
|
204
|
-
tag_name, tag_buf = $1, $2
|
205
|
-
elsif indent >= last_indent && tag_name
|
206
|
-
# Extra data added to the tag on the next line
|
207
|
-
tag_buf << line
|
208
|
-
else
|
209
|
-
# Regular docstring text
|
210
|
-
@docstring << line << "\n"
|
211
|
-
end
|
212
|
-
|
213
|
-
last_indent = indent
|
214
|
-
end
|
215
|
-
|
216
|
-
# Remove trailing/leading whitespace / newlines
|
217
|
-
@docstring.gsub!(/\A[\r\n\s]+|[\r\n\s]+\Z/, '')
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
class CodeObjectWithMethods < CodeObject
|
222
|
-
def initialize(name, type, parent = nil, comments = nil)
|
223
|
-
super(name, type, :public, :class, parent, comments) do |obj|
|
224
|
-
obj[:attributes] = {}
|
225
|
-
obj[:instance_methods] = {}
|
226
|
-
obj[:class_methods] = {}
|
227
|
-
obj[:constants] = {}
|
228
|
-
obj[:class_variables] = {}
|
229
|
-
obj[:mixins] = []
|
230
|
-
yield(obj) if block_given?
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
def inherited_class_methods
|
235
|
-
inherited_methods(:class)
|
236
|
-
end
|
237
|
-
|
238
|
-
def inherited_instance_methods
|
239
|
-
inherited_methods(:instance)
|
240
|
-
end
|
241
|
-
|
242
|
-
def inherited_methods(scopes = [:class, :instance])
|
243
|
-
[scopes].flatten.each do |scope|
|
244
|
-
full_mixins.inject({}) {|hash, mixin| hash.update(mixin.send(scope + "_methods")) }
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
def full_mixins
|
249
|
-
mixins.collect {|mixin| Namespace.find_from_path(self, mixin).path rescue mixin }
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
class ModuleObject < CodeObjectWithMethods
|
254
|
-
def initialize(name, *args)
|
255
|
-
super(name, :module, *args) do |obj|
|
256
|
-
yield(obj) if block_given?
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
def superclasses
|
261
|
-
#STDERR.puts "Warning: someone expected module #{path} to respond to #superclasses"
|
262
|
-
[]
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
class ClassObject < CodeObjectWithMethods
|
267
|
-
BASE_OBJECT = "Object"
|
268
|
-
|
269
|
-
def initialize(name, superclass = BASE_OBJECT, *args)
|
270
|
-
super(name, :class, *args) do |obj|
|
271
|
-
obj[:superclass] = superclass
|
272
|
-
yield(obj) if block_given?
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
def inherited_methods(scopes = [:class, :instance])
|
277
|
-
inherited_methods = super
|
278
|
-
superobject = Namespace.find_from_path(path, superclass)
|
279
|
-
if superobject && superobject.path != path # avoid infinite loop
|
280
|
-
[scopes].flatten.each do |scope|
|
281
|
-
inherited_methods.update(superobject.send(scope + "_methods"))
|
282
|
-
inherited_methods.update(superobject.send("inherited_#{scope}_methods"))
|
283
|
-
end
|
284
|
-
end
|
285
|
-
inherited_methods
|
286
|
-
end
|
287
|
-
|
288
|
-
def superclasses
|
289
|
-
superobject = Namespace.find_from_path(path, superclass)
|
290
|
-
return ["Object"] unless superobject
|
291
|
-
return [] if path == superobject.path
|
292
|
-
[superobject.path, *superobject.superclasses]
|
293
|
-
end
|
294
|
-
|
295
|
-
def inheritance_tree
|
296
|
-
full_mixins.reverse + superclasses
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
class MethodObject < CodeObject
|
301
|
-
# @param [String] name the name of the method
|
302
|
-
# @param visibility the object visibility (:public, :private, :protected)
|
303
|
-
# @param [String] scope the object scope (:instance, :class)
|
304
|
-
# @param [CodeObjectWithMethods] parent the object that holds this method
|
305
|
-
def initialize(name, visibility, scope, parent, comments = nil)
|
306
|
-
super(name, :method, visibility, scope, parent, comments) do |obj|
|
307
|
-
pmethods = parent["#{scope}_methods".to_sym]
|
308
|
-
pmethods.update(name.to_s => obj) if pmethods
|
309
|
-
yield(obj) if block_given?
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
class ConstantObject < CodeObject
|
315
|
-
def initialize(name, parent = nil, statement = nil)
|
316
|
-
super(name, :constant, :public, :class, parent) do |obj|
|
317
|
-
if statement
|
318
|
-
obj.attach_docstring(statement.comments)
|
319
|
-
obj.attach_source(statement)
|
320
|
-
parent[:constants].update(name.to_s => obj)
|
321
|
-
yield(obj) if block_given?
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
class ClassVariableObject < CodeObject
|
328
|
-
def initialize(statement, parent)
|
329
|
-
name, value = *statement.tokens.to_s.gsub(/\r?\n/, '').split(/\s*=\s*/, 2)
|
330
|
-
super(name, :class_variable, :public, :class, parent) do |obj|
|
331
|
-
obj.parent[:class_variables].update(name => obj)
|
332
|
-
obj.attach_docstring(statement.comments)
|
333
|
-
obj.attach_source("#{name} = #{value}")
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
data/lib/extra.rb
DELETED
data/lib/formatter.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'erubis'
|
3
|
-
require 'rdoc/markup/simple_markup'
|
4
|
-
require 'rdoc/markup/simple_markup/to_html'
|
5
|
-
|
6
|
-
SMP = SM::SimpleMarkup.new
|
7
|
-
SMH = SM::ToHtml.new
|
8
|
-
|
9
|
-
module YARD
|
10
|
-
##
|
11
|
-
# Formats the code objects in the {Namespace} in a variety of formats
|
12
|
-
#
|
13
|
-
# @author Loren Segal
|
14
|
-
# @version 1.0
|
15
|
-
class Formatter
|
16
|
-
##
|
17
|
-
# Formats an object as a specified output format. Default is +:html+.
|
18
|
-
#
|
19
|
-
# @param format the output format to generate documentation in.
|
20
|
-
# Defaults to +:html+, which is a synonym for <tt>:xhtml</tt>
|
21
|
-
# @param template the template sub directory to use, default is <tt>:default</tt>
|
22
|
-
# @see OUTPUT_FORMATS
|
23
|
-
def format(object, format, template)
|
24
|
-
object = Namespace.at(object) if object.is_a? String
|
25
|
-
@object, @format, @template = object, format, template
|
26
|
-
render(@object.type)
|
27
|
-
end
|
28
|
-
|
29
|
-
##
|
30
|
-
# Directory for templates. Override this to load your own templates
|
31
|
-
def template_directory
|
32
|
-
File.join(File.dirname(__FILE__), '..', 'templates')
|
33
|
-
end
|
34
|
-
|
35
|
-
def render(type, format = @format, template = @template)
|
36
|
-
formatter = self
|
37
|
-
_binding = @object ? @object.instance_eval("binding") : binding
|
38
|
-
filename = File.join(template_directory, template.to_s, format.to_s, "#{type}.erb")
|
39
|
-
Erubis::Eruby.new("<% extend #{format.to_s.capitalize}Formatter %>\n" +
|
40
|
-
IO.read(filename), :trim => true).result(_binding)
|
41
|
-
rescue => e
|
42
|
-
STDERR.puts "Could not render template #{filename}: #{e.message}"
|
43
|
-
STDERR.puts e.backtrace[0, 5].map {|x| "\t#{x}" }
|
44
|
-
STDERR.puts
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
module HtmlFormatter
|
49
|
-
def link_to_path(name, from_path = nil, label = nil)
|
50
|
-
return "<a href='#instance_method-#{name[1..-1]}'>#{label || name}</a>" if name =~ /^\#/ && from_path.nil?
|
51
|
-
|
52
|
-
if from_path
|
53
|
-
obj = Namespace.find_from_path(from_path, name)
|
54
|
-
else
|
55
|
-
obj = Namespace.at(name)
|
56
|
-
end
|
57
|
-
|
58
|
-
label = name if label.nil?
|
59
|
-
if obj
|
60
|
-
file = (obj.parent || obj).path.gsub("::","_") + ".html"
|
61
|
-
case obj
|
62
|
-
when ConstantObject
|
63
|
-
"<a href='#{file}#const-#{obj.name}'>#{label}</a>"
|
64
|
-
when ClassVariableObject
|
65
|
-
"<a href='#{file}#cvar-#{obj.name}'>#{label}</a>"
|
66
|
-
when MethodObject
|
67
|
-
"<a href='#{file}##{obj.scope}_method-#{obj.name}'>#{label}</a>"
|
68
|
-
else
|
69
|
-
"<a href='#{obj.path.gsub("::","_")}.html'>#{label}</a>"
|
70
|
-
end
|
71
|
-
else
|
72
|
-
name
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def to_html(text, path = @object)
|
77
|
-
resolve_links(SMP.convert(text || "", SMH).gsub(/\A<p>|<\/p>\Z/,''), path)
|
78
|
-
end
|
79
|
-
|
80
|
-
def resolve_links(text, path)
|
81
|
-
text.gsub(/\{(.+?)\}/) {|match| "<tt>" + link_to_path(match, path) + "</tt>" }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
class CodeObject
|
86
|
-
def to_s(format = :html, template = :default)
|
87
|
-
Formatter.new.format(self, format, template)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
class YARD::AttributeHandler < YARD::CodeObjectHandler
|
2
|
-
handles /\Aattr(_(reader|writer|accessor))?\b/
|
3
|
-
|
4
|
-
def process
|
5
|
-
begin
|
6
|
-
attr_type = statement.tokens.first.text.to_sym
|
7
|
-
symbols = eval("[" + statement.tokens[1..-1].to_s + "]")
|
8
|
-
read, write = true, false
|
9
|
-
rescue SyntaxError
|
10
|
-
Logger.warning "in AttributeHandler: Undocumentable attribute statement: '#{statement.tokens.to_s}'"
|
11
|
-
return
|
12
|
-
end
|
13
|
-
|
14
|
-
# Change read/write based on attr_reader/writer/accessor
|
15
|
-
case attr_type
|
16
|
-
when :attr
|
17
|
-
# In the case of 'attr', the second parameter (if given) isn't a symbol.
|
18
|
-
read = symbols.pop if symbols.size == 2
|
19
|
-
when :attr_accessor
|
20
|
-
write = true
|
21
|
-
when :attr_reader
|
22
|
-
# change nothing
|
23
|
-
when :attr_writer
|
24
|
-
read, write = false, true
|
25
|
-
end
|
26
|
-
|
27
|
-
# Add all attributes
|
28
|
-
symbols.each do |name|
|
29
|
-
name = name.to_s
|
30
|
-
object[:attributes].update(name.to_s => { :read => read, :write => write }) if object.type == :class
|
31
|
-
|
32
|
-
# Show their methods as well
|
33
|
-
[name, "#{name}="].each do |method|
|
34
|
-
YARD::MethodObject.new(method, current_visibility, current_scope, object, statement.comments) do |obj|
|
35
|
-
if method.to_s.include? "="
|
36
|
-
src = "def #{method}(value)"
|
37
|
-
full_src = "#{src}\n @#{name} = value\nend"
|
38
|
-
doc = "Sets the attribute +#{name}+\n@param value the value to set the attribute +#{name}+ to."
|
39
|
-
else
|
40
|
-
src = "def #{method}"
|
41
|
-
full_src = "#{src}\n @#{name}\nend"
|
42
|
-
doc = "Returns the value of attribute +#{name}+"
|
43
|
-
end
|
44
|
-
obj.attach_source(src)
|
45
|
-
obj.attach_full_source(full_src)
|
46
|
-
obj.attach_docstring(doc)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|