forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.js
55 lines (51 loc) · 1.55 KB
/
file.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
/**
* Represents a file.
* Breaks up file into comment and code parts.
* Creates new [DocumentJS.Pair | Doc.Pairs].
* @hide
*/
DocumentJS.Pair.extend('DocumentJS.Script',
{
group : new RegExp("(?:/\\*(?:[^*]|(?:\\*+[^*/]))*\\*+/\[^\\w\\{\\(\\[/]*[^\\n]*)", "g"),
splitter : new RegExp("(?:/\\*+((?:[^*]|(?:\\*+[^*/]))*)\\*+/\[^\\w\\{\\(\\[\"'\$]*([^\\r\\n]*))")
},{
/**
* Generates docs for a file.
* @param {Object} inc an object that has path and text attributes
*/
init : function(inc){
this.children = [];
this.name = inc.path;
this.src=inc.src;
//check if the source has @documentjs-ignore
if(!/\@documentjs-ignore/.test(this.src)){
this.generate();
}
},
generate : function(){
var pairs = this.src.match(this.Class.group);
//clean comments
var scope = this;
if(!pairs) return;
for(var i = 0; i < pairs.length ; i ++){
var splits = pairs[i].match(this.Class.splitter);
var comment = splits[1].replace(/^[^\w@]*/,'').replace(/\r?\n(\s*\*+)?/g,'\n');
var code = splits[2];
var pair = DocumentJS.Pair.create( comment , code, scope);
if(pair){
//get the new scope if you need it
scope = pair.scope();
}
}
},
/**
* Removes comment text from a comment.
* @param {Object} comment
*/
clean_comment : function(comment){
return comment.replace(/\/\*|\*\//,'').replace(/\r?\n\s*\*?\s*/g,'\n')
},
full_name: function(){
return "";
}
});