1
+ var Declaration , DocRenderer , addJQuery , main ;
2
+ Declaration = ( function ( ) {
3
+ function Declaration ( declaration ) {
4
+ this . declaration = declaration ;
5
+ }
6
+ Declaration . prototype . returnType = function ( ) {
7
+ var pattern ;
8
+ pattern = / .\( ( .+ ?) \) / ;
9
+ return this . declaration . match ( pattern ) [ 1 ] ;
10
+ } ;
11
+ Declaration . prototype . methodName = function ( ) {
12
+ var pattern ;
13
+ if ( this . hasParameters ( ) ) {
14
+ pattern = / .+ ?\) ( .+ ?) : / ;
15
+ } else {
16
+ pattern = / .+ ?\) ( .+ ) / ;
17
+ }
18
+ return this . declaration . match ( pattern ) [ 1 ] ;
19
+ } ;
20
+ Declaration . prototype . isInstanceMethod = function ( ) {
21
+ var pattern ;
22
+ pattern = / - .+ / ;
23
+ return ! ! this . declaration . match ( pattern ) ;
24
+ } ;
25
+ Declaration . prototype . parameters = function ( ) {
26
+ var parameter , parameters , pattern , _i , _len , _results ;
27
+ if ( ! this . hasParameters ( ) ) {
28
+ return [ ] ;
29
+ }
30
+ pattern = / ( ( [ a - z A - Z ] + ?: ) ? \( .+ ?\) .+ ?\b ) / g;
31
+ parameters = this . declaration . match ( pattern ) . slice ( 1 ) ;
32
+ _results = [ ] ;
33
+ for ( _i = 0 , _len = parameters . length ; _i < _len ; _i ++ ) {
34
+ parameter = parameters [ _i ] ;
35
+ _results . push ( this . mapParameter ( parameter ) ) ;
36
+ }
37
+ return _results ;
38
+ } ;
39
+ Declaration . prototype . hasParameters = function ( ) {
40
+ return this . declaration . indexOf ( ":" ) !== - 1 ;
41
+ } ;
42
+ Declaration . prototype . mapParameter = function ( parameter ) {
43
+ var arg , key , pattern , type , value , _ref , _ref2 ;
44
+ if ( parameter [ 0 ] === "(" ) {
45
+ pattern = / \( ( .+ ?) \) ( .+ ) / ;
46
+ return parameter . match ( pattern ) . slice ( 1 , 3 ) . reverse ( ) ;
47
+ } else {
48
+ pattern = / \( ( .+ ?) \) ( .+ ) / ;
49
+ _ref = parameter . split ( ':' ) , key = _ref [ 0 ] , arg = _ref [ 1 ] ;
50
+ _ref2 = arg . match ( pattern ) . slice ( 1 , 3 ) . reverse ( ) , value = _ref2 [ 0 ] , type = _ref2 [ 1 ] ;
51
+ return [ "" + key + ": " + value , type ] ;
52
+ }
53
+ } ;
54
+ return Declaration ;
55
+ } ) ( ) ;
56
+ DocRenderer = ( function ( ) {
57
+ function DocRenderer ( className , declarationText ) {
58
+ this . className = className ;
59
+ this . declarationText = declarationText ;
60
+ }
61
+ DocRenderer . prototype . render = function ( ) {
62
+ var i , length , param , parameters , str ;
63
+ try {
64
+ this . declaration = new Declaration ( this . declarationText ) ;
65
+ parameters = this . declaration . parameters ( ) ;
66
+ length = parameters . length ;
67
+ i = 0 ;
68
+ str = "<div><span>" + this . className + ( this . separator ( ) ) + ( this . declaration . methodName ( ) ) + "</span>" ;
69
+ str += "<span style='color: #fff'><table style='color: #000; margin-left: 20px'>" ;
70
+ str += ( ( function ( ) {
71
+ var _i , _len , _results ;
72
+ _results = [ ] ;
73
+ for ( _i = 0 , _len = parameters . length ; _i < _len ; _i ++ ) {
74
+ param = parameters [ _i ] ;
75
+ _results . push ( "<tr><td>" + param [ 0 ] + ( this . addComma ( ( i += 1 ) , length ) ) + "</td><td style='color: gray; padding-left: 10px;'># (" + param [ 1 ] + ")</td></tr>" ) ;
76
+ }
77
+ return _results ;
78
+ } ) . call ( this ) ) . join ( ) ;
79
+ str += "</table></span><div style='margin-top: 10px; color: gray;'>Return type: (" + ( this . declaration . returnType ( ) ) + ")</div> </div>" ;
80
+ return str ;
81
+ } catch ( err ) {
82
+ return 'Could not parse or render, check issues at <a href="https://github.com/joakimk/macruby-docs-js/issues">https://github.com/joakimk/macruby-docs-js/issues</a>.' ;
83
+ }
84
+ } ;
85
+ DocRenderer . prototype . separator = function ( ) {
86
+ if ( this . declaration . isInstanceMethod ( ) ) {
87
+ return "#" ;
88
+ } else {
89
+ return "." ;
90
+ }
91
+ } ;
92
+ DocRenderer . prototype . addComma = function ( i , length ) {
93
+ if ( length !== i ) {
94
+ return ',' ;
95
+ } else {
96
+ return '' ;
97
+ }
98
+ } ;
99
+ return DocRenderer ;
100
+ } ) ( ) ;
101
+ if ( ! window . in_tests ) {
102
+ addJQuery = function ( callback ) {
103
+ var addScriptToPage , script ;
104
+ script = document . createElement ( "script" ) ;
105
+ script . setAttribute ( "src" , "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" ) ;
106
+ addScriptToPage = function ( ) {
107
+ script = document . createElement ( "script" ) ;
108
+ script . textContent = "(" + callback . toString ( ) + ")();" ;
109
+ return document . body . appendChild ( script ) ;
110
+ } ;
111
+ script . addEventListener ( 'load' , addScriptToPage , false ) ;
112
+ return document . body . appendChild ( script ) ;
113
+ } ;
114
+ main = function ( ) {
115
+ var check ;
116
+ $ . noConflict ( ) ;
117
+ check = function ( ) {
118
+ var className ;
119
+ try {
120
+ className = jQuery ( "#pageTitle" , window . parent . frames [ 0 ] . document ) . html ( ) . split ( " " ) [ 0 ] ;
121
+ if ( jQuery ( ".declaration .macruby" , window . parent . frames [ 0 ] . document ) . length > 0 ) {
122
+ return ;
123
+ }
124
+ return jQuery . each ( jQuery ( ".api .declaration" , window . parent . frames [ 0 ] . document ) , function ( i , element ) {
125
+ var content ;
126
+ content = element . textContent ;
127
+ return element . innerHTML = element . innerHTML + "<h5 class='macruby' style='margin-top: 20px'>MacRuby</h5>" + new DocRenderer ( className , content ) . render ( ) ;
128
+ } ) ;
129
+ } catch ( err ) {
130
+ console . log ( "macruby-docs.user.js error:" ) ;
131
+ return console . log ( err ) ;
132
+ }
133
+ } ;
134
+ return setInterval ( check , 1000 ) ;
135
+ } ;
136
+ addJQuery ( main ) ;
137
+ }
0 commit comments