Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for most YARD tags.

  • Loading branch information...
commit 8072c2e72435f52cb1dba71d10ed3f10ec830c2a 1 parent 1a1fb44
@trans trans authored
Showing with 112 additions and 0 deletions.
  1. +11 −0 lib/yard-tomdoc.rb
  2. +101 −0 test/unit/test_tags.rb
View
11 lib/yard-tomdoc.rb
@@ -3,8 +3,12 @@
module YARD
module TomDoc
+ # Distribution name of this program.
NAME = 'yard-tomdoc'
+ # Tags supported by YARD that Tomparse can handle.
+ TAGS = %w{abstract attr attr_reader attr_writer attribute author deprecated note see since todo version}
+
# Parse comments with TomDoc and then provide YARD with results.
#
# yard - [Docstring,DocstringParser] instance of yard object
@@ -47,9 +51,16 @@ def self.yard_parse(yard, comment)
yard.create_tag(:api, 'public') if tomdoc.public?
yard.create_tag(:api, 'private') if tomdoc.internal?
+ tomdoc.tags.each do |label, desc|
+ if TAGS.include?(label.to_s)
+ yard.create_tag(label.to_sym, desc.to_s)
+ end
+ end
+
tomdoc
end
+ #
def self.const_missing(name)
metadata[name.to_s.downcase] || super(name)
end
View
101 test/unit/test_tags.rb
@@ -0,0 +1,101 @@
+require 'helper.rb'
+
+require "yard"
+require "yard-tomdoc"
+
+describe YARD::Docstring do
+
+ make_docstring = Proc.new do |comment|
+ if YARD::VERSION == '0.8.0'
+ YARD::DocstringParser.new.parse(comment, self).to_docstring
+ else
+ YARD::Docstring.new(comment)
+ end
+ end
+
+ before do
+ comment = <<-eof
+# Duplicate some text an arbitrary number of times.
+#
+# text - The String to be duplicated.
+# count - The Integer number of times to duplicate the text.
+# options - Options (default: {})
+# :a - Option a
+# :b - Option b
+#
+# Examples
+# multiplex('Tom', 4)
+# # => 'TomTomTomTom'
+#
+# TODO: There something important to be done!
+#
+# Returns the duplicated String.
+#
+# Raises ArgumentError if something bad happened
+eof
+
+ @docstring = make_docstring[comment]
+ end
+
+ it "should fill todo tags" do
+ tags = @docstring.tags(:todo)
+ tags.size.assert == 1
+ tags[0].text.assert == 'There something important to be done!'
+ end
+
+ it "should fill docstring with description" do
+ @docstring.assert == "Duplicate some text an arbitrary number of times."
+ end
+
+ it "should fill param tags" do
+ tags = @docstring.tags(:param)
+ tags.size.assert == 3
+ tags[0].name.assert == 'text'
+ tags[1].name.assert == 'count'
+ tags[2].name.assert == 'options'
+ end
+
+ it "should fill options tags" do
+ tags = @docstring.tags(:option)
+ tags.size.assert == 2
+ tags[0].name.assert == 'options'
+ tags[0].pair.name.assert == ':a'
+ tags[0].pair.text.assert == 'Option a'
+ tags[1].name.assert == 'options'
+ tags[1].pair.name.assert == ':b'
+ tags[1].pair.text.assert == 'Option b'
+ end
+
+ it "should fill examples tags" do
+ @docstring.tags(:example).size.assert == 1
+ @docstring.tag(:example).text.assert == "multiplex('Tom', 4)\n# => 'TomTomTomTom'"
+ end
+
+ it "should fill return tag" do
+ @docstring.tag(:return).text.assert == "the duplicated String."
+ end
+
+ it "should fill raise tag" do
+ @docstring.tag(:raise).text.assert == "ArgumentError if something bad happened"
+ end
+
+ describe "Internal description" do
+
+ it "should fill api private tag" do
+ docstring = make_docstring["# Internal: It will do a big things in future"]
+ docstring.tag(:api).text.assert == "private"
+ end
+
+ end
+
+ describe "Deprecated description" do
+
+ it "should fill deprecated tag" do
+ docstring = make_docstring["# Deprecated: Some description."]
+ docstring.tag(:deprecated).text.assert == "Do not use this in new code, and replace it when updating old code."
+ end
+
+ end
+
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.