Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add work stuff. [admin]

  • Loading branch information...
commit 9221614f1e9a15a73dac2610ea9457706b7f2cb4 1 parent 0a7f6fa
@trans trans authored
View
1  .gitignore
@@ -4,5 +4,4 @@ doc
log
tmp
web
-work/sandbox
*.lock
View
81 work/reference/yard-tomdoc.rb
@@ -0,0 +1,81 @@
+require 'tomparse'
+
+module YARD
+
+ module TomDoc
+
+ # Parse comments with TomDoc and then provide YARD with results.
+ #
+ # yard - [Docstring,DocstringParser] instance of yard object
+ # comment - [String] comment string
+ #
+ # Returns [TomDoc] instance.
+ def self.yard_parse(yard, comment)
+ tomdoc = TomParse.parse(comment)
+
+ # TODO: TomParse should make the `strip` unecessary
+ tomdoc.examples.each {|ex| yard.create_tag(:example, "\n" + ex.strip) }
+
+ # TODO: how to figure-out class of argument ?
+ tomdoc.arguments.each {|arg| yard.create_tag(:param, "#{arg.name} #{arg.description}") }
+
+ if last_argument = tomdoc.arguments.last
+ last_argument.options.each do |opt|
+ yard.create_tag(:option, "#{last_argument.name} #{opt.description}")
+ end
+ end
+
+ tomdoc.raises.each {|r| yard.create_tag(:raise, r.sub(/\ARaises\s+/, '')) }
+
+ tomdoc.returns.each do |r|
+ # TODO: improve how we figure out class of argument
+ if md = /\AReturns\s+([A-Z].*?)\s+/.match(r)
+ klass = md[1]
+ desc = md.post_match
+ yard.create_tag(:return, "[#{klass}] #{desc}")
+ else
+ desc = r.sub(/\AReturns\s+/, '')
+ yard.create_tag(:return, desc)
+ end
+ end
+
+ yard.create_tag(:yield, tomdoc.yields) if tomdoc.yields
+
+ yard.create_tag(:deprecated, 'Do not use this in new code, and replace it when updating old code.') if tomdoc.deprecated?
+
+ yard.create_tag(:api, 'public') if tomdoc.public?
+ yard.create_tag(:api, 'private') if tomdoc.internal?
+
+ tomdoc
+ end
+
+ # Metadata from the project's `yard-tomdoc.yml` file.
+ #
+ # Returns [Hash] of metadata.
+ def self.metadata
+ @metadata ||= (
+ require 'yaml'
+ YAML.load_file(File.dirname(__FILE__) + '/yard-tomdoc.yml')
+ )
+ end
+
+ # When a constant is missing, see if it is a metadata entry.
+ #
+ # name - [Symbol] constant name
+ #
+ # Returns metadata value.
+ def self.const_missing(name)
+ metadata[name.to_s.downcase] || super(name)
+ end
+
+ end
+
+ if VERSION > '0.8'
+ require 'yard-tomdoc/yard081'
+ elsif VERSION == '0.8'
+ require 'yard-tomdoc/yard080'
+ else
+ require 'yard-tomdoc/yard070'
+ end
+
+end
View
1  work/sandbox/.gitignore
@@ -0,0 +1 @@
+doc
View
1  work/sandbox/.yardopts
@@ -0,0 +1 @@
+--plugin tomdoc
View
12 work/sandbox/documented.rb
@@ -0,0 +1,12 @@
+
+# Author: Mailo
+class Documented
+
+ # Deprecated: It will do a big things in future
+ #
+ # Returns String of something.
+ def dependency_fallback
+ @default.to_s
+ end
+end
+
View
18 work/sandbox/example.rb
@@ -0,0 +1,18 @@
+class Example
+ # Public: Duplicate some text an arbitrary number of times.
+ #
+ # text - The String to be duplicated.
+ # What if it has multiple lines?
+ # count - The Integer number of times to duplicate the text.
+ # This one could too.
+ #
+ # Examples
+ #
+ # multiplex('Tom', 4)
+ # # => 'TomTomTomTom'
+ #
+ # Returns the duplicated String.
+ def multiplex(text, count)
+ text * count
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.