Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add work stuff. [admin]

  • Loading branch information...
commit 9221614f1e9a15a73dac2610ea9457706b7f2cb4 1 parent 0a7f6fa
7rans authored January 21, 2013
1  .gitignore
@@ -4,5 +4,4 @@ doc
4 4
 log
5 5
 tmp
6 6
 web
7  
-work/sandbox
8 7
 *.lock
81  work/reference/yard-tomdoc.rb
... ...
@@ -0,0 +1,81 @@
  1
+require 'tomparse'
  2
+
  3
+module YARD
  4
+
  5
+  module TomDoc
  6
+
  7
+    # Parse comments with TomDoc and then provide YARD with results. 
  8
+    #
  9
+    # yard    - [Docstring,DocstringParser] instance of yard object
  10
+    # comment - [String] comment string
  11
+    #
  12
+    # Returns [TomDoc] instance.
  13
+    def self.yard_parse(yard, comment)
  14
+      tomdoc = TomParse.parse(comment)
  15
+
  16
+      # TODO: TomParse should make the `strip` unecessary
  17
+      tomdoc.examples.each {|ex| yard.create_tag(:example, "\n" + ex.strip) }
  18
+
  19
+      # TODO: how to figure-out class of argument ?
  20
+      tomdoc.arguments.each {|arg| yard.create_tag(:param, "#{arg.name} #{arg.description}") }
  21
+
  22
+      if last_argument = tomdoc.arguments.last
  23
+        last_argument.options.each do |opt|
  24
+          yard.create_tag(:option, "#{last_argument.name} #{opt.description}")
  25
+        end
  26
+      end
  27
+
  28
+      tomdoc.raises.each {|r| yard.create_tag(:raise, r.sub(/\ARaises\s+/, '')) }
  29
+
  30
+      tomdoc.returns.each do |r|
  31
+      # TODO: improve how we figure out class of argument
  32
+        if md = /\AReturns\s+([A-Z].*?)\s+/.match(r)
  33
+          klass = md[1]
  34
+          desc  = md.post_match
  35
+          yard.create_tag(:return, "[#{klass}] #{desc}")
  36
+        else
  37
+          desc = r.sub(/\AReturns\s+/, '')
  38
+          yard.create_tag(:return, desc)
  39
+        end
  40
+      end
  41
+
  42
+      yard.create_tag(:yield, tomdoc.yields) if tomdoc.yields
  43
+
  44
+      yard.create_tag(:deprecated, 'Do not use this in new code, and replace it when updating old code.') if tomdoc.deprecated?
  45
+
  46
+      yard.create_tag(:api, 'public')  if tomdoc.public?
  47
+      yard.create_tag(:api, 'private') if tomdoc.internal?
  48
+
  49
+      tomdoc
  50
+    end
  51
+
  52
+    # Metadata from the project's `yard-tomdoc.yml` file.
  53
+    # 
  54
+    # Returns [Hash] of metadata.
  55
+    def self.metadata
  56
+      @metadata ||= (
  57
+        require 'yaml'
  58
+        YAML.load_file(File.dirname(__FILE__) + '/yard-tomdoc.yml')
  59
+      )
  60
+    end
  61
+
  62
+    # When a constant is missing, see if it is a metadata entry.
  63
+    #
  64
+    # name - [Symbol] constant name
  65
+    #
  66
+    # Returns metadata value.
  67
+    def self.const_missing(name)
  68
+      metadata[name.to_s.downcase] || super(name)
  69
+    end
  70
+
  71
+  end
  72
+
  73
+  if VERSION > '0.8'
  74
+    require 'yard-tomdoc/yard081'
  75
+  elsif VERSION == '0.8'
  76
+    require 'yard-tomdoc/yard080'
  77
+  else
  78
+    require 'yard-tomdoc/yard070'
  79
+  end
  80
+
  81
+end
1  work/sandbox/.gitignore
... ...
@@ -0,0 +1 @@
  1
+doc
1  work/sandbox/.yardopts
... ...
@@ -0,0 +1 @@
  1
+--plugin tomdoc
12  work/sandbox/documented.rb
... ...
@@ -0,0 +1,12 @@
  1
+
  2
+# Author: Mailo
  3
+class Documented
  4
+  
  5
+  # Deprecated: It will do a big things in future
  6
+  #
  7
+  # Returns String of something.
  8
+  def dependency_fallback
  9
+    @default.to_s
  10
+  end
  11
+end
  12
+
18  work/sandbox/example.rb
... ...
@@ -0,0 +1,18 @@
  1
+class Example
  2
+  # Public: Duplicate some text an arbitrary number of times.
  3
+  #
  4
+  # text  - The String to be duplicated.
  5
+  #         What if it has multiple lines?
  6
+  # count - The Integer number of times to duplicate the text.
  7
+  #         This one could too.
  8
+  #
  9
+  # Examples
  10
+  #
  11
+  #   multiplex('Tom', 4)
  12
+  #   # => 'TomTomTomTom'
  13
+  #
  14
+  # Returns the duplicated String.
  15
+  def multiplex(text, count)
  16
+    text * count
  17
+  end
  18
+end

0 notes on commit 9221614

Please sign in to comment.
Something went wrong with that request. Please try again.