0
@@ -83,7 +83,7 @@ module YARD
0
+ @docstring =
Docstring.new0
self.namespace = namespace
0
yield(self) if block_given?
0
@@ -148,25 +148,14 @@ module YARD
0
# Attaches a docstring to a code oject by parsing the comments attached to the statement
0
# and filling the {#tags} and {#docstring} methods with the parsed information.
0
- # @param [String, Array<String>
] comments
0
+ # @param [String, Array<String>
, Docstring] comments
0
# the comments attached to the code object to be parsed
0
# into a docstring and meta tags.
0
def docstring=(comments)
0
- @short_docstring = nil
0
- parse_comments(comments) if comments
0
+ @docstring = Docstring === comments ? comments : Docstring.new(comments)
0
- # Gets the first line of a docstring to the period or the first paragraph.
0
- # @return [String] The first line or paragraph of the docstring; always ends with a period.
0
- @short_docstring ||= (docstring.split(/\.|\r?\n\r?\n/).first || '')
0
- @short_docstring += '.' unless @short_docstring.empty?
0
# Default type is the lowercase class name without the "Object" suffix
0
# Override this method to provide a custom object type
0
@@ -206,113 +195,14 @@ module YARD
0
alias_method :parent, :namespace
0
alias_method :parent=, :namespace=
0
- # Convenience method to return the first tag
0
- # object in the list of tag objects of that name
0
- # doc = YARD::Documentation.new("@return zero when nil")
0
- # doc.tag("return").text # => "zero when nil"
0
- # @param [#to_s] name the tag name to return data for
0
- # @return [Tags::Tag] the first tag in the list of {#tags}
0
- @tags.find {|tag| tag.tag_name.to_s == name.to_s }
0
- # Returns a list of tags specified by +name+ or all tags if +name+ is not specified.
0
- # @param name the tag name to return data for, or nil for all tags
0
- # @return [Array<Tags::Tag>] the list of tags by the specified tag name
0
- return @tags if name.nil?
0
- @tags.select {|tag| tag.tag_name.to_s == name.to_s }
0
- # Returns true if at least one tag by the name +name+ was declared
0
- # @param [String] name the tag name to search for
0
- # @return [Boolean] whether or not the tag +name+ was declared
0
- @tags.any? {|tag| tag.tag_name.to_s == name.to_s }
0
+ def tag(name); @docstring.tag(name) end
0
+ def tags(name = nil); @docstring.tags(name) end
0
+ def has_tag?(name); @docstring.has_tag?(name) end
0
- # Parses out comments split by newlines into a new code object
0
- # @param [Array<String>, String] comments
0
- # the newline delimited array of comments. If the comments
0
- # are passed as a String, they will be split by newlines.
0
- def parse_comments(comments)
0
- return if comments.empty?
0
- meta_match = /^@(\S+)\s*(.*)/
0
- comments = comments.split(/\r?\n/) if comments.is_a? String
0
- @tags, @docstring = [], ""
0
- indent, last_indent = comments.first[/^\s*/].length, 0
0
- tag_name, tag_klass, tag_buf, raw_buf = nil, nil, "", []
0
- (comments+['']).each_with_index do |line, index|
0
- indent = line[/^\s*/].length
0
- empty = (line =~ /^\s*$/ ? true : false)
0
- done = comments.size == index
0
- if tag_name && (((indent < orig_indent && !empty) || done) ||
0
- (indent <= last_indent && line =~ meta_match))
0
- tagfactory = Tags::Library.new
0
- tag_method = "#{tag_name}_tag"
0
- if tag_name && tagfactory.respond_to?(tag_method)
0
- if tagfactory.method(tag_method).arity == 2
0
- @tags << tagfactory.send(tag_method, tag_buf, raw_buf.join("\n"))
0
- @tags << tagfactory.send(tag_method, tag_buf)
0
- log.warn "Unknown tag @#{tag_name} in documentation for `#{path}`"
0
- tag_name, tag_buf, raw_buf = nil, '', []
0
- tag_name, tag_buf = $1, $2
0
- raw_buf = [tag_buf.dup]
0
- elsif tag_name && indent >= orig_indent && !empty
0
- # Extra data added to the tag on the next line
0
- last_empty = last_line =~ /^[ \t]*$/ ? true : false
0
- tag_buf << line.gsub(/^[ \t]{#{indent}}/, last_empty ? '' : ' ')
0
- raw_buf << line.gsub(/^[ \t]{#{orig_indent}}/, '')
0
- # Regular docstring text
0
- @docstring << line << "\n"
0
- # Remove trailing/leading whitespace / newlines
0
- @docstring.gsub!(/\A[\r\n\s]+|[\r\n\s]+\Z/, '')
0
# Formats source code by removing leading indentation
0
def format_source(source)
Comments
No one has commented yet.