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
90 lines (84 loc) · 2.46 KB
/
Copy pathfunction.js
File metadata and controls
90 lines (84 loc) · 2.46 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
steal.then(function() {
/**
* @class DocumentJS.types.function
* @tag documentation
* @parent DocumentJS.types
* Documents a function. Doc can guess at a functions name and params if the source following a comment matches something like:
*
* @codestart
* myFuncOne : function(param1, param2){} //or
* myFuncTwo = function(param1, param2){}
* @codeend
*
* ###Directives
*
* Use the following directives to document a function.
*
* @codestart
* [ DocumentJS.types.function | @function ] functionName -> Forces a function
* [ DocumentJS.tags.param | @param ] {optional:type} paramName Description -> Describes a parameter
* [ DocumentJS.tags.return | @return ] {type} Description -> Describes the return value
* @codeend
*
* ###Example
*
* @codestart
* /* Adds, Mr. or Ms. before someone's name
* * [ DocumentJS.tags.param | @param ] {String} name the persons name
* * [ DocumentJS.tags.param | @param ] {optional:Boolean} gender true if a man, false if female. Defaults to true.
* * [ DocumentJS.tags.return | @return ] {String} returns the appropriate honorific before the person's name.
* *|
* honorific = function(name, gender){
* @codeend
*/
DocumentJS.Type("function",
/**
* @Static
*/
{
codeMatch: /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[:=]\s*function\s?\(([^\)]*)/,
/*
* Parses the code to get the function data.
* Must return the name if from the code.
* @param {String} code
* @return {Object} function data
*/
code: function( code ) {
var parts = this.codeMatch(code);
if (!parts ) {
parts = code.match(/\s*function\s+([\w\.\$]+)\s*(~)?\(([^\)]*)/)
}
var data = {};
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 = {};
data.ret = {
type: 'undefined',
description: ""
}
var params = parts[3].match(/\w+/g);
if (!params ) return data;
for ( var i = 0; i < params.length; i++ ) {
data.params[params[i]] = {
description: "",
type: "",
optional: false,
order: i,
name: params[i]
};
}
return data;
},
/*
* Possible scopes for @function.
*/
parent: /static|proto|class|page/,
useName: false
})
})