1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-02 12:27:08 +01:00

Refactor verb invocations to base.

This commit is contained in:
hacksalot
2016-01-31 08:37:12 -05:00
parent f1ba7765ee
commit 90765bf90b
14 changed files with 81 additions and 129 deletions

View File

@ -26,14 +26,7 @@ Implementation of the 'analyze' verb for HackMyResume.
AnalyzeVerb = module.exports = Verb.extend({
init: function() {
return this._super('analyze');
},
invoke: function() {
this.stat(HMEVENT.begin, {
cmd: 'analyze'
});
analyze.apply(this, arguments);
return this.stat(HMEVENT.end);
return this._super('analyze', analyze);
}
});

39
dist/verbs/build.js vendored
View File

@ -74,18 +74,7 @@ Implementation of the 'build' verb for HackMyResume.
/** Create a new build verb. */
init: function() {
return this._super('build');
},
/** Invoke the Build command. */
invoke: function() {
var ret;
this.stat(HMEVENT.begin, {
cmd: 'build'
});
ret = build.apply(this, arguments);
this.stat(HMEVENT.end);
return ret;
return this._super('build', build);
}
});
@ -95,16 +84,16 @@ Implementation of the 'build' verb for HackMyResume.
theme file, generate 0..N resumes in the desired formats.
@param src Path to the source JSON resume file: "rez/resume.json".
@param dst An array of paths to the target resume file(s).
@param theme Friendly name of the resume theme. Defaults to "modern".
@param logger Optional logging override.
@param opts Generation options.
*/
build = function(src, dst, opts) {
var ex, inv, isFRESH, mixed, newEx, orgFormat, rez, sheetObjects, sheets, tFolder, targets, theme, toFormat;
var ex, inv, isFRESH, mixed, newEx, orgFormat, problemSheets, rez, sheetObjects, sheets, tFolder, targets, theme, toFormat;
if (!src || !src.length) {
this.err(HMSTATUS.resumeNotFound, {
quit: true
});
return null;
}
prep(src, dst, opts);
sheetObjects = ResumeFactory.load(src, {
@ -115,9 +104,12 @@ Implementation of the 'build' verb for HackMyResume.
sort: _opts.sort
}
}, this);
if (!sheetObjects || _.some(sheetObjects, function(so) {
problemSheets = _.filter(sheetObjects, function(so) {
return so.fluenterror;
})) {
});
if (problemSheets && problemSheets.length) {
problemSheets[0].quit = true;
this.err(problemSheets[0].fluenterror, problemSheets[0]);
return null;
}
sheets = sheetObjects.map(function(r) {
@ -130,12 +122,14 @@ Implementation of the 'build' verb for HackMyResume.
try {
tFolder = verifyTheme.call(this, _opts.theme);
theme = _opts.themeObj = loadTheme(tFolder);
addFreebieFormats(theme);
} catch (_error) {
ex = _error;
newEx = {
fluenterror: HMSTATUS.themeLoad,
inner: ex,
attempted: _opts.theme
attempted: _opts.theme,
quit: true
};
this.err(HMSTATUS.themeLoad, newEx);
return null;
@ -147,8 +141,10 @@ Implementation of the 'build' verb for HackMyResume.
if (inv && inv.length) {
this.err(HMSTATUS.invalidFormat, {
data: inv,
theme: theme
theme: theme,
quit: true
});
return null;
}
rez = null;
if (sheets.length > 1) {
@ -186,7 +182,6 @@ Implementation of the 'build' verb for HackMyResume.
fmt: toFormat
});
}
addFreebieFormats(theme);
this.stat(HMEVENT.applyTheme, {
r: rez,
theme: theme
@ -284,9 +279,7 @@ Implementation of the 'build' verb for HackMyResume.
};
/**
Ensure that user-specified outputs/targets are valid.
*/
/** Ensure that user-specified outputs/targets are valid. */
verifyOutputs = function(targets, theme) {
this.stat(HMEVENT.verifyOutputs, {

View File

@ -22,14 +22,7 @@ Implementation of the 'convert' verb for HackMyResume.
ConvertVerb = module.exports = Verb.extend({
init: function() {
return this._super('convert');
},
invoke: function() {
this.stat(HMEVENT.begin, {
cmd: 'convert'
});
convert.apply(this, arguments);
return this.stat(HMEVENT.end);
return this._super('convert', convert);
}
});

11
dist/verbs/create.js vendored
View File

@ -24,16 +24,7 @@ Implementation of the 'create' verb for HackMyResume.
CreateVerb = module.exports = Verb.extend({
init: function() {
return this._super('new');
},
invoke: function() {
this.stat(HMEVENT.begin, {
cmd: 'create'
});
create.apply(this, arguments);
this.stat(HMEVENT.begin, {
cmd: 'convert'
});
return this._super('new', create);
}
});

9
dist/verbs/peek.js vendored
View File

@ -22,14 +22,7 @@ Implementation of the 'peek' verb for HackMyResume.
PeekVerb = module.exports = Verb.extend({
init: function() {
return this._super('peek');
},
invoke: function() {
this.stat(HMEVENT.begin, {
cmd: 'peek'
});
peek.apply(this, arguments);
return this.stat(HMEVENT.end);
return this._super('peek', peek);
}
});

View File

@ -31,16 +31,7 @@ Implementation of the 'validate' verb for HackMyResume.
ValidateVerb = module.exports = Verb.extend({
init: function() {
return this._super('validate');
},
invoke: function() {
var ret;
this.stat(HMEVENT.begin, {
cmd: 'validate'
});
ret = validate.apply(this, arguments);
this.stat(HMEVENT.end);
return ret;
return this._super('validate', validate);
}
});

18
dist/verbs/verb.js vendored
View File

@ -6,12 +6,14 @@ Definition of the Verb class.
*/
(function() {
var Class, EVENTS, Verb;
var Class, EVENTS, HMEVENT, Verb;
Class = require('../utils/class');
EVENTS = require('events');
HMEVENT = require('../core/event-codes');
/**
An instantiation of a HackMyResume command.
@ -21,9 +23,21 @@ Definition of the Verb class.
Verb = module.exports = Class.extend({
/** Constructor. Automatically called at creation. */
init: function(moniker) {
init: function(moniker, workhorse) {
this.moniker = moniker;
this.emitter = new EVENTS.EventEmitter();
this.workhorse = workhorse;
},
/** Invoke the command. */
invoke: function() {
var ret;
this.stat(HMEVENT.begin, {
cmd: this.moniker
});
ret = this.workhorse.apply(this, arguments);
this.stat(HMEVENT.end);
return ret;
},
/** Forward subscriptions to the event emitter. */