forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd.js
76 lines (69 loc) · 2.28 KB
/
add.js
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
/**
* Used to set scope to add to classes or methods in another file.
* Examples:
* @codestart no-highlight
* /* @add steal.String Static *| adds to steal.String's static methods
* /* @add steal.Controller Prototype *| adds to steal.Controller's prototype methods
* @codeend
* It's important to note that add must be in its own comment block.
*/
DocumentJS.Pair.extend('DocumentJS.Add',
{
comment_setup: DocumentJS.Function.prototype.comment_setup,
/**
* Looks for a line like @add (scope) (Static|Prototype)
* @param {String} line the line that had @add
*/
add_add : function(line){
var m = line.match(/^@add\s+([\w\.]+)\s*([\w\.]+)?/i)
if(m){
var sub = m.pop()
this.sub_scope = sub ? sub.toLowerCase() : null;
this.scope_name = m.pop()
}
},
/**
* Searches for the new scope.
* @return {DocumentJS.Pair} The new scope where additional comments will be added
*/
scope : function(){
var Class = DocumentJS.Class
//find
var inst;
for(var l =0 ; l < Class.listing.length; l++){
if(Class.listing[l].name == this.scope_name) {
inst = Class.listing[l];break;
}
}
if(!inst){
var Class = DocumentJS.Constructor
for(var l =0 ; l < Class.listing.length; l++){
if(Class.listing[l].name == this.scope_name) {
inst = Class.listing[l];break;
}
}
}
if(!inst){
var Class = DocumentJS.Page
for(var l =0 ; l < Class.listing.length; l++){
if(Class.listing[l].name == this.scope_name) {
inst = Class.listing[l];break;
}
}
}
if(!inst) return this;
if(this.sub_scope){
var children = inst.children;
var child;
for(var i=0; i< children.length; i++){
if(children[i].Class.shortName.toLowerCase() == this.sub_scope.toLowerCase()) {
child = children[i];break;
}
}
if(child) return child;
}
return inst;
},
toHTML: function(){return ""},
linker: function(){}
});