@@ -20,6 +20,9 @@ blocks.debug = {
2020 addType : function ( name , checkCallback ) {
2121 customTypes [ name . toLowerCase ( ) ] = checkCallback ;
2222 } ,
23+ available : function ( ) {
24+ return blocks . debug . enabled && ! blocks . debug . executing && blocks . debug . paused === 0 ;
25+ } ,
2326 paused : 0 ,
2427 checkArgs : debugFunc ( function ( method , args , options ) {
2528 if ( ! blocks . debug . enabled ) {
@@ -37,6 +40,44 @@ blocks.debug = {
3740 blocks . debug . printErrors ( method , args , options , errors ) ;
3841 } ) ,
3942
43+ throwMessage : debugFunc ( function ( errorMessage , method , style ) {
44+ if ( ! errorMessage ) return ;
45+
46+ var type = typeof style == 'string' ? style : 'Info' ;
47+
48+ if ( ! style || typeof style != 'object' ) {
49+ style = defaultStyles [ type . toLowerCase ( ) ] ;
50+ }
51+
52+ var message = blocks . debug . Message ( ) ;
53+
54+ message . addSpan ( type , style ) . addText ( ' in ' ) ;
55+
56+ // No method => No name and no usage, so we at least print a stack trace
57+ if ( ! method ) {
58+ message . addText ( 'unspecified method - ' )
59+ . addText ( errorMessage ) ;
60+
61+ message . beginCollapsedGroup ( ) ;
62+
63+ message . addText ( 'Stack trace:' )
64+ . newLine ( )
65+ . addText ( new Error ( ) . stack ) ;
66+
67+ message . endGroup ( ) ;
68+ }
69+
70+ // Print method name, error message and add usage
71+ if ( method ) {
72+ message . addSpan ( method . name + '()' , { background : '#EEE' } )
73+ . addText ( ' - ' )
74+ . addText ( errorMessage ) ;
75+ addMethodReference ( message , method , true ) ;
76+ }
77+
78+ message . print ( ) ;
79+ } ) ,
80+
4081 printErrors : function ( method , args , options , errors ) {
4182 if ( ! blocks . debug . enabled ) {
4283 return ;
@@ -52,7 +93,7 @@ blocks.debug = {
5293 }
5394
5495 message
55- . addSpan ( 'Arguments mismatch:' , { background : 'yellow' } )
96+ . addSpan ( 'Arguments mismatch:' , defaultStyles . info )
5697 . addText ( ' ' ) ;
5798
5899 if ( one ) {
@@ -95,10 +136,10 @@ blocks.debug = {
95136 queryNotExists : debugFunc ( function ( query , element ) {
96137 var message = blocks . debug . Message ( ) ;
97138 message . beginSpan ( { 'font-weight' : 'bold' } ) ;
98- message . addSpan ( 'Warning:' , { background : 'orange' , padding : '0 3px' } ) ;
139+ message . addSpan ( 'Warning:' , blocks . extend ( { } , defaultStyles . warning , { padding : '0 3px' } ) ) ;
99140
100141 message . addText ( ' ' ) ;
101- message . addSpan ( query . name , { background : 'red' , color : 'white' } ) ;
142+ message . addSpan ( query . name , defaultStyles . error ) ;
102143 message . addSpan ( '(' + query . params . join ( ', ' ) + ')' , { background : '#EEE' } ) ;
103144
104145 message . addText ( ' - data-query ' ) ;
@@ -122,14 +163,14 @@ blocks.debug = {
122163
123164 message . beginCollapsedGroup ( ) ;
124165 message . beginSpan ( { 'font-weight' : 'bold' } ) ;
125- message . addSpan ( 'Critical:' , { background : 'red' , color : 'white' } ) ;
166+ message . addSpan ( 'Critical:' , defaultStyles . error ) ;
126167 message . addText ( ' ' ) ;
127168 message . beginSpan ( { background : '#EEE' } ) ;
128169 message . addText ( query . name + '(' ) ;
129170 for ( var i = 0 ; i < params . length ; i ++ ) {
130171 param = params [ i ] ;
131172 if ( param == failedParameter ) {
132- message . addSpan ( param , { background : 'red' , color : 'white' } ) ;
173+ message . addSpan ( param , defaultStyles . error ) ;
133174 } else {
134175 message . addText ( param ) ;
135176 }
@@ -154,9 +195,9 @@ blocks.debug = {
154195 var message = new blocks . debug . Message ( ) ;
155196
156197 message . beginSpan ( { 'font-weight' : 'bold' } ) ;
157- message . addSpan ( 'Critical:' , { background : 'red' , color : 'white' } ) ;
198+ message . addSpan ( 'Critical:' , defaultStyles . error ) ;
158199 message . addText ( ' ' ) ;
159- message . addSpan ( '{{' + expressionText + '}}' , { background : 'red' , color : 'white' } ) ;
200+ message . addSpan ( '{{' + expressionText + '}}' , defaultStyles . error ) ;
160201 message . addText ( ' - exception thrown while executing expression' ) ;
161202 message . endSpan ( ) ;
162203
@@ -244,7 +285,7 @@ function addError(message, error, method, paramNames) {
244285 }
245286
246287 message . beginSpan ( {
247- 'background-color ' : '#EEE'
288+ 'background' : '#EEE'
248289 } ) ;
249290
250291 message . addText ( method . name + '(' ) ;
@@ -258,11 +299,7 @@ function addError(message, error, method, paramNames) {
258299 }
259300 for ( index = error . actual ; index < error . expected ; index ++ ) {
260301 message
261- . beginSpan ( {
262- 'background-color' : 'red' ,
263- padding : '0 5px' ,
264- color : 'white'
265- } )
302+ . beginSpan ( blocks . extend ( { } , defaultStyles . error , { padding : '0 5px' } ) )
266303 . addText ( paramNames [ index ] || '?' )
267304 . endSpan ( ) ;
268305 if ( index != error . expected - 1 ) {
@@ -279,11 +316,7 @@ function addError(message, error, method, paramNames) {
279316 message . addText ( ', ' ) ;
280317 }
281318 for ( index = error . expected ; index < error . actual ; index ++ ) {
282- message . addSpan ( paramNames [ index ] , {
283- 'background-color' : 'red' ,
284- 'text-decoration' : 'line-through' ,
285- color : 'white'
286- } ) ;
319+ message . addSpan ( paramNames [ index ] , blocks . extend ( { } , defaultStyles . error , { 'text-decoration' : 'line-through' } ) ) ;
287320 if ( index != error . actual - 1 ) {
288321 message . addText ( ', ' ) ;
289322 }
@@ -295,10 +328,7 @@ function addError(message, error, method, paramNames) {
295328 case 'param' :
296329 for ( index = 0 ; index < paramNames . length ; index ++ ) {
297330 if ( method . params [ index ] == error . param ) {
298- message . addSpan ( paramNames [ index ] , {
299- 'background-color' : 'red' ,
300- color : 'white'
301- } ) ;
331+ message . addSpan ( paramNames [ index ] , defaultStyles . error ) ;
302332 } else {
303333 message . addText ( paramNames [ index ] ) ;
304334 }
@@ -556,30 +586,6 @@ function addMethodSignature(message, method) {
556586 message . newLine ( ) ;
557587}
558588
559- function examples ( method ) {
560- var examples = method . examples ;
561-
562- if ( examples ) {
563- console . groupCollapsed ( '%cUsage examples' , 'color: blue;' ) ;
564-
565- for ( var i = 0 ; i < examples . length ; i ++ ) {
566- console . log ( examples [ i ] . code ) ;
567- if ( i != examples . length - 1 ) {
568- console . log ( '-------------------------------' ) ;
569- }
570- }
571-
572- console . groupEnd ( ) ;
573- }
574- }
575-
576- function params ( method ) {
577- var params = method . params ;
578- for ( var i = 0 ; i < params . length ; i ++ ) {
579- console . log ( ' ' + method . params [ i ] . name + ': ' + method . params [ i ] . description ) ;
580- }
581- }
582-
583589function hasArgumentsParam ( method ) {
584590 var params = method . params ;
585591 for ( var i = 0 ; i < params . length ; i ++ ) {
@@ -828,3 +834,16 @@ var highlightjs = {
828834 color : '#e7635f'
829835 }
830836} ;
837+
838+ var defaultStyles = {
839+ warning : {
840+ background : 'orange'
841+ } ,
842+ error : {
843+ background : 'red' ,
844+ color : 'white'
845+ } ,
846+ info : {
847+ background : 'yellow'
848+ }
849+ } ;
0 commit comments