Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for doc filenames

  • Loading branch information...
commit 339fe284bffd9802e62d79f2b17974fbbcb46103 1 parent e13663e
Peter Wagenet authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 lib/parsejs/docs.rb
View
22 lib/parsejs/docs.rb
@@ -70,6 +70,11 @@ class ExtractDocs < CommentScanner
def initialize(*)
@current_variables = []
@current_class = []
+ @filename = []
+ end
+
+ def visit(ast, filename=nil)
+ with_filename(filename){ super(ast) }
end
def visit_Program(program)
@@ -84,6 +89,13 @@ def visit_FunctionExpression(expr)
with_variables(expr, expr.params.list.map(&:val)) { super }
end
+ def with_filename(filename)
+ @filename.push(filename)
+ yield
+ ensure
+ @filename.pop
+ end
+
def with_variables(expr, params=expr.params.map(&:val))
locals = FindVars.find_variables(expr)
@current_variables.push(locals | params)
@@ -138,6 +150,7 @@ def visit_AssignmentExpression(expr)
class_name = left_string.split(".")[-1]
obj = YARD::CodeObjects::ClassObject.new(namespace_obj, class_name)
+ obj.add_file(current_filename) if current_filename
obj.docstring = stripped_comment
@current_class.push [klass, extends, obj]
@@ -161,7 +174,9 @@ def build_namespace(namespace)
ns
else
name = namespace.gsub('::', '.')
- YARD::CodeObjects::ModuleObject.new(:root, name)
+ obj = YARD::CodeObjects::ModuleObject.new(:root, name)
+ obj.add_file(current_filename) if current_filename
+ obj
end
end
@@ -174,6 +189,10 @@ def current_yard_class
@current_class.last[2]
end
+ def current_filename
+ @filename.compact.last
+ end
+
def visit_Property(property)
return if @current_class.empty?
@@ -183,6 +202,7 @@ def visit_Property(property)
case property.value
when FunctionDeclaration, FunctionExpression
obj = YARD::CodeObjects::MethodObject.new(current_yard_class, property.key.val)
+ obj.add_file(current_filename) if current_filename
obj.docstring = stripped_comment
else
# found a non-method property
Please sign in to comment.
Something went wrong with that request. Please try again.