forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
115 lines (100 loc) · 2.48 KB
/
Copy pathfunction.js
File metadata and controls
115 lines (100 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
steal('./helpers/getParent.js',
'documentjs/tags/helpers/typeNameDescription.js',function(getParent, tnd) {
/**
* @constructor DocumentJS.tags.function @function
*
* @parent DocumentJS
*
* Specifies the comment is for a function. Use [documentjs/tags/param @param] to
* specify the arguments of a function.
*
* @signature `@function [NAME] [TITLE]`
*
* @codestart
* /**
* * @function lib.Component.prototype.update update
* * @parent lib.Component
* *|
* C.p.update = function(){
*
* }
* @codeend
*
* @param {String} [NAME] The name of the function. It should
* be supplied if it can not be determined from the code block
* following the comment.
*
* @param {String} [TITLE] The title to be used for display purposes.
*
* @body
*
* ## Code Matching
*
* The `@function` type can be infered from code like the following:
*
* @codestart
* /**
* * The foo function exists
* *|
* foo: function(){}
* /**
* * The bar function exists
* *|
* bar = function(){}
* @codeend
*/
return {
codeMatch: /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[:=]\s*function\s?\(([^\)]*)/,
code: function( code, scope, docMap ) {
var parts = code.match(this.codeMatch);
if (!parts ) {
parts = code.match(/\s*function\s+([\w\.\$]+)\s*(~)?\(([^\)]*)/)
}
var data = {
type: "function"
};
if (!parts ) {
return;
}
data.name = parts[1] ? parts[1].replace(/^this\./, "").replace(/^\$./, "jQuery.") : parts[2];
//clean up name if it has ""
//if (/^["']/.test(data.name) ) {
// data.name = data.name.substr(1, data.name.length - 2).replace(/\./g, ".").replace(/>/g, ">");
//}
data.params = [];
var params = parts[3].match(/\w+/g);
if ( params ) {
for ( var i = 0; i < params.length; i++ ) {
data.params.push({
name: params[i],
types: [{type: "*"}]
});
}
}
// assign name and parent
if(scope && docMap){
var parentAndName = getParent.andName({
parents: "*",
useName: ["constructor","static","prototype"],
scope: scope,
docMap: docMap,
name: data.name
});
data.parent = parentAndName.parent;
data.name = parentAndName.name;
}
return data;
},
add: function(line, curData, scope, docMap){
var data = tnd(line);
this.title = data.description;
if(data.name) {
this.name = data.name;
}
this.type = "function";
if(!data.params){
data.params = [];
}
}
}
})