forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
constructor.js
145 lines (144 loc) · 4.82 KB
/
constructor.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Documents javascript constructor classes typically created like:
* new MyContructor(args).
*
* A constructor can be described by putting @constructor as the first declaritive.
* To describe the construction function, write that after init. Example:
*
* @codestart
* /* @constructor
* * Person represents a human with a name
* * @init
* * You must pass in a name.
* * @params {String} name A person's name
* *|
* Person = function(name){
* this.name = name
* Person.count ++;
* }
* /* @Static *|
* steal.Object.extend(Person, {
* /* Number of People *|
* count: 0
* })
* /* @Prototype *|
* Person.prototype = {
* /* Returns a formal name
* * @return {String} the name with "Mrs." added
* *|
* fancy_name : function(){
* return "Mrs. "+this.name;
* }
* }
* @codeend
*
*/
DocumentJS.Pair.extend('DocumentJS.Constructor',
/* @Static */
{
code_match: DocumentJS.Function.code_match,
starts_scope: true,
listing: [],
create_index : function(){
var res = '<html><head><link rel="stylesheet" href="../style.css" type="text/css" />'+
'<title>Constructors</title></head><body>'
res += '<h1>Constructors <label>LIST</label></h1>'
for(var i = 0; i < this.listing.length; i++){
var name = this.listing[i].name;
res += "<a href='"+name+".html'>"+name+"</a> "
}
res +="</body></html>"
new steal.File('docs/constructors/index2.html').save(res);
//MVCOptions.save('docs/constructors/index2.html', res)
},
init : function(){
this.add(
DocumentJS.Directive.Init,
DocumentJS.Directive.Param,
DocumentJS.Directive.Inherits,
DocumentJS.Directive.Parent,
DocumentJS.Directive.Author,
DocumentJS.Directive.Return,
DocumentJS.Directive.Download,
DocumentJS.Directive.Hide, DocumentJS.Directive.CodeStart, DocumentJS.Directive.CodeEnd, DocumentJS.Directive.Alias,
DocumentJS.Directive.Plugin, DocumentJS.Directive.Tag, DocumentJS.Directive.iFrame, DocumentJS.Directive.Demo,
DocumentJS.Directive.Test);
this._super();
this.serialize('name',['linker','children'],'inherits','alias',['real_comment','comment'],'shortName',
'ret','params','plugin','tags','download','downloadSize',['init_description','init'],'test')
}
},
/* @Prototype */
{
/**
*
* @param {Object} comment
* @param {Object} code
* @param {Object} scope
*/
init: function(comment, code, scope ){
this._super(comment, code, scope);
//this.Class.listing.push(this);
},
add_parent : function(scope){
while(scope.Class.shortName.toLowerCase() != 'script'){
scope = scope.parent;
if(!scope)
print("cant find file parent of "+this.comment)
}
this.parent = scope;
this.parent.add(this);
},
code_setup: DocumentJS.Function.prototype.code_setup,
toFile : function(name){
//try{
var res = this.jsonp();
new steal.File('apps/'+name+'/docs/'+this.name+".json").save(res);
//}catch(e ){
// throw
//}
},
/**
* Returns the HTML signiture of the constructor function.
*/
signiture : function(){
var res = [];
var ordered = this.ordered_params();
for(var n = 0; n < ordered.length; n++){
res.push(ordered[n].name)
}
var n = this.alias ? this.alias : this.name;
//if(this.parent.Class.shortName == 'static')
// n = this.parent.parent.name+"."+this.name;
//else if(this.parent.Class.shortName == 'prototype')
// n = this.parent.parent.name.toLowerCase()+"."+this.name;
if(this.ret.type =='undefined'){
n = "new "+n;
this.ret.type = this.alias ? this.alias.toLowerCase() : this.name.toLowerCase();
}
return n+"("+res.join(", ")+") -> "+this.ret.type;
},
cleaned_comment : function(){
return DocumentJS.link_content(this.real_comment).replace(/\n\s*\n/g,"<br/><br/>");
},
url : function(){
return this.name+".html";
},
comment_setup_complete : function(){
if(!this.name){
print("Error! No name defined for \n-----------------------")
print(this.comment)
print('-----------------------')
} else if(!this.init_description){
print("Error! No init_description defined for "+this.name+"\n-----------------------")
print(this.comment)
print('-----------------------')
}
},
constructor_add: function(line){
var m = line.match(/^@\w+ ([\w\.]+)/)
if(m){
this.name = m[1];
}
}
});