1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-21 16:00:11 +00:00

Improve PEEK command behavior.

This commit is contained in:
hacksalot 2016-01-18 19:20:17 -05:00
parent a81ad0fef2
commit 181419ae28
2 changed files with 32 additions and 14 deletions

View File

@ -197,16 +197,22 @@ Output routines for HackMyResume.
break;
case HME.beforePeek:
if( evt.target )
L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
else
L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
// if( evt.target )
// L(M2C(this.msgs.beforePeek.msg[0], evt.isError ? 'red' : 'green'), evt.target, evt.file);
// else
// L(M2C(this.msgs.beforePeek.msg[1], evt.isError ? 'red' : 'green'), evt.file);
break;
case HME.afterPeek:
if( evt.target )
console.dir( evt.target, { depth: null, colors: true } );
var sty = evt.error ? 'red' : ( evt.target !== undefined ? 'green' : 'yellow' );
if( evt.requested )
L(M2C(this.msgs.beforePeek.msg[0], sty), evt.requested, evt.file);
else
L(M2C(this.msgs.beforePeek.msg[1], sty), evt.file);
if( evt.target !== undefined )
console.dir( evt.target, { depth: null, colors: true } );
else if( !evt.error )
L(M2C( this.msgs.afterPeek.msg, 'yellow'), evt.requested, evt.file);
break;

View File

@ -46,9 +46,26 @@ Implementation of the 'peek' verb for HackMyResume.
_.each( src, function( t ) {
var obj = safeLoadJSON( t );
this.stat( HMEVENT.beforePeek, { file: t, target: objPath, isError: obj.ex } );
// Fire the 'beforePeek' event 2nd, so we have error/warning/success
this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
// Load the input file JSON 1st
var obj = safeLoadJSON( t );
// Fetch the requested object path (or the entire file)
var tgt;
if( !obj.ex )
tgt = objPath ? __.get( obj.json, objPath ) : obj.json;
// Fire the 'afterPeek' event with collected info
this.stat( HMEVENT.afterPeek, {
file: t,
requested: objPath,
target: tgt,
error: obj.ex
});
// safeLoadJSON can only return a READ error or a PARSE error
if( obj.ex ) {
if( obj.ex.operation === 'parse' )
this.err( HMSTATUS.parseError, obj.ex );
@ -56,12 +73,7 @@ Implementation of the 'peek' verb for HackMyResume.
obj.ex.quiet = true;
this.err( HMSTATUS.readError, obj.ex );
}
return;
}
var targ = objPath ? __.get( obj.json, objPath ) : obj.json;
this.stat( HMEVENT.afterPeek, { file: t, requested: objPath, target: targ } );
}
}, this);