forked from bitovi/documentjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.js
79 lines (79 loc) · 1.78 KB
/
class.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
steal.then(function() {
/**
* @class DocumentJS.types.class
* @tag documentation
* @parent DocumentJS.types
* Documents a 'Class'.
*
* A class is typically a collection of static and prototype functions.
*
* DocumentJS can automatically detect classes created with jQuery.Class.
*
* However, you can make anything a class with the __@class__ _ClassName_ directive.
*
* ###Example:
*
* @codestart
* /**
* * @@class
* * Person represents a human with a name. Read about the
* * animal class [Animal | here].
* *|
* Person = Animal.extend(
* /* @@Static *|
* {
* /* Number of People *|
* count: 0
* },
* /* @@Prototype *|
* {
* init : function(name){
* this.name = name
* this._super({warmblood: true})
* },
* /* Returns a formal name
* * @return {String} the name with "Mrs." added
* *|
* fancyName : function(){
* return "Mrs. "+this.name;
* }
* })
* @codeend
*/
DocumentJS.Type("class",
/**
* @Static
*/
{
codeMatch: /([\w\.\$]+?).extend\(\s*["']([^"']*)["']/,
// /([\w\.]*)\s*=\s*([\w\.]+?).extend\(/,
//must return the name if from the code
funcMatch: /(?:([\w\.]+)|(["'][^"']+["']))\s*[:=]\s*function\s?\(([^\)]*)/,
/*
* Parses the code to get the class data.
* @param {String} code
* @return {Object} class data
*/
code: function( code ) {
var parts = code.match(this.codeMatch);
if ( parts ) {
return {
name: parts[2],
inherits: parts[1].replace("$.", "jQuery.")
}
}
parts = code.match(this.funcMatch)
if ( parts ) {
return {
name: parts[1] ? parts[1].replace(/^this\./, "") : parts[2]
}
}
},
/*
* Possible scopes for @class.
*/
parent: /script/,
useName: true,
hasChildren: true
})
})