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

Refactor verbs to CoffeeScript classes.

Retire Resig's class implementation.
This commit is contained in:
hacksalot 2016-02-01 23:16:49 -05:00
parent fd39cc9fd9
commit 63a0c78fc5
14 changed files with 123 additions and 69 deletions

17
dist/verbs/analyze.js vendored
View File

@ -6,7 +6,9 @@ Implementation of the 'analyze' verb for HackMyResume.
*/ */
(function() { (function() {
var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _analyzeOne, _loadInspectors, chalk; var AnalyzeVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, ResumeFactory, Verb, _, _analyze, _analyzeOne, _loadInspectors, chalk,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
MKDIRP = require('mkdirp'); MKDIRP = require('mkdirp');
@ -27,11 +29,16 @@ Implementation of the 'analyze' verb for HackMyResume.
/** An invokable resume analysis command. */ /** An invokable resume analysis command. */
AnalyzeVerb = module.exports = Verb.extend({ module.exports = AnalyzeVerb = (function(superClass) {
init: function() { extend(AnalyzeVerb, superClass);
return this._super('analyze', _analyze);
function AnalyzeVerb() {
AnalyzeVerb.__super__.constructor.call(this, 'analyze', _analyze);
} }
});
return AnalyzeVerb;
})(Verb);
/** Private workhorse for the 'analyze' command. */ /** Private workhorse for the 'analyze' command. */

18
dist/verbs/build.js vendored
View File

@ -6,7 +6,9 @@ Implementation of the 'build' verb for HackMyResume.
*/ */
(function() { (function() {
var BuildVerb, FRESHTheme, FS, HMEVENT, HMSTATUS, JRSTheme, MD, MKDIRP, PATH, RConverter, RTYPES, ResumeFactory, Verb, _, _addFreebieFormats, _build, _err, _expand, _fmts, _loadTheme, _log, _opts, _prep, _rezObj, _single, _verifyOutputs, _verifyTheme, addFreebieFormats, build, expand, extend, loadTheme, parsePath, prep, single, verifyOutputs, verifyTheme; var BuildVerb, FRESHTheme, FS, HMEVENT, HMSTATUS, JRSTheme, MD, MKDIRP, PATH, RConverter, RTYPES, ResumeFactory, Verb, _, _addFreebieFormats, _build, _err, _expand, _fmts, _loadTheme, _log, _opts, _prep, _rezObj, _single, _verifyOutputs, _verifyTheme, addFreebieFormats, build, expand, extend, loadTheme, parsePath, prep, single, verifyOutputs, verifyTheme,
extend1 = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
_ = require('underscore'); _ = require('underscore');
@ -70,13 +72,19 @@ Implementation of the 'build' verb for HackMyResume.
/** An invokable resume generation command. */ /** An invokable resume generation command. */
BuildVerb = module.exports = Verb.extend({ module.exports = BuildVerb = (function(superClass) {
extend1(BuildVerb, superClass);
/** Create a new build verb. */ /** Create a new build verb. */
init: function() {
return this._super('build', _build); function BuildVerb() {
BuildVerb.__super__.constructor.call(this, 'build', _build);
} }
});
return BuildVerb;
})(Verb);
/** /**

17
dist/verbs/convert.js vendored
View File

@ -6,7 +6,9 @@ Implementation of the 'convert' verb for HackMyResume.
*/ */
(function() { (function() {
var ConvertVerb, HMEVENT, HMSTATUS, ResumeFactory, Verb, _, _convert, _convertOne, chalk; var ConvertVerb, HMEVENT, HMSTATUS, ResumeFactory, Verb, _, _convert, _convertOne, chalk,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ResumeFactory = require('../core/resume-factory'); ResumeFactory = require('../core/resume-factory');
@ -20,11 +22,16 @@ Implementation of the 'convert' verb for HackMyResume.
HMEVENT = require('../core/event-codes'); HMEVENT = require('../core/event-codes');
ConvertVerb = module.exports = Verb.extend({ module.exports = ConvertVerb = (function(superClass) {
init: function() { extend(ConvertVerb, superClass);
return this._super('convert', _convert);
function ConvertVerb() {
ConvertVerb.__super__.constructor.call(this, 'convert', _convert);
} }
});
return ConvertVerb;
})(Verb);
/** Private workhorse method. Convert 0..N resumes between FRESH and JRS /** Private workhorse method. Convert 0..N resumes between FRESH and JRS

17
dist/verbs/create.js vendored
View File

@ -6,7 +6,9 @@ Implementation of the 'create' verb for HackMyResume.
*/ */
(function() { (function() {
var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, chalk; var CreateVerb, HMEVENT, HMSTATUS, MKDIRP, PATH, Verb, _, _create, _createOne, chalk,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
MKDIRP = require('mkdirp'); MKDIRP = require('mkdirp');
@ -22,11 +24,16 @@ Implementation of the 'create' verb for HackMyResume.
HMEVENT = require('../core/event-codes'); HMEVENT = require('../core/event-codes');
CreateVerb = module.exports = Verb.extend({ module.exports = CreateVerb = (function(superClass) {
init: function() { extend(CreateVerb, superClass);
return this._super('new', _create);
function CreateVerb() {
CreateVerb.__super__.constructor.call(this, 'new', _create);
} }
});
return CreateVerb;
})(Verb);
/** Create a new empty resume in either FRESH or JRS format. */ /** Create a new empty resume in either FRESH or JRS format. */

17
dist/verbs/peek.js vendored
View File

@ -6,7 +6,9 @@ Implementation of the 'peek' verb for HackMyResume.
*/ */
(function() { (function() {
var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, _peek, _peekOne, safeLoadJSON; var HMEVENT, HMSTATUS, PeekVerb, Verb, _, __, _peek, _peekOne, safeLoadJSON,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Verb = require('../verbs/verb'); Verb = require('../verbs/verb');
@ -20,11 +22,16 @@ Implementation of the 'peek' verb for HackMyResume.
HMEVENT = require('../core/event-codes'); HMEVENT = require('../core/event-codes');
PeekVerb = module.exports = Verb.extend({ module.exports = PeekVerb = (function(superClass) {
init: function() { extend(PeekVerb, superClass);
return this._super('peek', _peek);
function PeekVerb() {
PeekVerb.__super__.constructor.call(this, 'peek', _peek);
} }
});
return PeekVerb;
})(Verb);
/** Peek at a resume, resume section, or resume field. */ /** Peek at a resume, resume section, or resume field. */

View File

@ -6,7 +6,9 @@ Implementation of the 'validate' verb for HackMyResume.
*/ */
(function() { (function() {
var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, _validate, _validateOne, chalk, safeLoadJSON; var FS, HMEVENT, HMSTATUS, ResumeFactory, SyntaxErrorEx, ValidateVerb, Verb, _, _validate, _validateOne, chalk, safeLoadJSON,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
FS = require('fs'); FS = require('fs');
@ -29,11 +31,16 @@ Implementation of the 'validate' verb for HackMyResume.
/** An invokable resume validation command. */ /** An invokable resume validation command. */
ValidateVerb = module.exports = Verb.extend({ module.exports = ValidateVerb = (function(superClass) {
init: function() { extend(ValidateVerb, superClass);
return this._super('validate', _validate);
function ValidateVerb() {
ValidateVerb.__super__.constructor.call(this, 'validate', _validate);
} }
});
return ValidateVerb;
})(Verb);
/** Validate 1 to N resumes in FRESH or JSON Resume format. */ /** Validate 1 to N resumes in FRESH or JSON Resume format. */

57
dist/verbs/verb.js vendored
View File

@ -6,9 +6,7 @@ Definition of the Verb class.
*/ */
(function() { (function() {
var Class, EVENTS, HMEVENT, Promise, Verb; var EVENTS, HMEVENT, Promise, Verb;
Class = require('../utils/class');
EVENTS = require('events'); EVENTS = require('events');
@ -22,17 +20,20 @@ Definition of the Verb class.
@class Verb @class Verb
*/ */
Verb = module.exports = Class.extend({ module.exports = Verb = (function() {
/** Constructor. Automatically called at creation. */ /** Constructor. Automatically called at creation. */
init: function(moniker, workhorse) { function Verb(moniker, workhorse) {
this.moniker = moniker; this.moniker = moniker;
this.workhorse = workhorse; this.workhorse = workhorse;
this.emitter = new EVENTS.EventEmitter(); this.emitter = new EVENTS.EventEmitter();
}, return;
}
/** Invoke the command. */ /** Invoke the command. */
invoke: function() {
Verb.prototype.invoke = function() {
var argsArray, that; var argsArray, that;
this.stat(HMEVENT.begin, { this.stat(HMEVENT.begin, {
cmd: this.moniker cmd: this.moniker
@ -44,23 +45,29 @@ Definition of the Verb class.
that.reject = rej; that.reject = rej;
that.workhorse.apply(that, argsArray); that.workhorse.apply(that, argsArray);
}); });
}, };
/** Forward subscriptions to the event emitter. */ /** Forward subscriptions to the event emitter. */
on: function() {
Verb.prototype.on = function() {
return this.emitter.on.apply(this.emitter, arguments); return this.emitter.on.apply(this.emitter, arguments);
}, };
/** Fire an arbitrary event, scoped to "hmr:". */ /** Fire an arbitrary event, scoped to "hmr:". */
fire: function(evtName, payload) {
Verb.prototype.fire = function(evtName, payload) {
payload = payload || {}; payload = payload || {};
payload.cmd = this.moniker; payload.cmd = this.moniker;
this.emitter.emit('hmr:' + evtName, payload); this.emitter.emit('hmr:' + evtName, payload);
return true; return true;
}, };
/** Handle an error condition. */ /** Handle an error condition. */
err: function(errorCode, payload, hot) {
Verb.prototype.err = function(errorCode, payload, hot) {
payload = payload || {}; payload = payload || {};
payload.sub = payload.fluenterror = errorCode; payload.sub = payload.fluenterror = errorCode;
payload["throw"] = hot; payload["throw"] = hot;
@ -74,25 +81,33 @@ Definition of the Verb class.
throw payload; throw payload;
} }
return true; return true;
}, };
/** Fire the 'hmr:status' error event. */ /** Fire the 'hmr:status' error event. */
stat: function(subEvent, payload) {
Verb.prototype.stat = function(subEvent, payload) {
payload = payload || {}; payload = payload || {};
payload.sub = subEvent; payload.sub = subEvent;
this.fire('status', payload); this.fire('status', payload);
return true; return true;
}, };
hasError: function() {
Verb.prototype.hasError = function() {
return this.errorCode || this.errorObj; return this.errorCode || this.errorObj;
}, };
/** Associate error info with the invocation. */ /** Associate error info with the invocation. */
setError: function(code, obj) {
Verb.prototype.setError = function(code, obj) {
this.errorCode = code; this.errorCode = code;
this.errorObj = obj; this.errorObj = obj;
} };
});
return Verb;
})();
}).call(this); }).call(this);

View File

@ -17,9 +17,9 @@ chalk = require('chalk')
###* An invokable resume analysis command. ### ###* An invokable resume analysis command. ###
AnalyzeVerb = module.exports = Verb.extend module.exports = class AnalyzeVerb extends Verb
init: -> @_super 'analyze', _analyze constructor: -> super 'analyze', _analyze

View File

@ -39,10 +39,10 @@ verifyTheme = null
loadTheme = null loadTheme = null
###* An invokable resume generation command. ### ###* An invokable resume generation command. ###
BuildVerb = module.exports = Verb.extend module.exports = class BuildVerb extends Verb
###* Create a new build verb. ### ###* Create a new build verb. ###
init: () -> @_super 'build', _build constructor: () -> super 'build', _build

View File

@ -15,9 +15,9 @@ HMEVENT = require('../core/event-codes');
ConvertVerb = module.exports = Verb.extend module.exports = class ConvertVerb extends Verb
init: -> @_super 'convert', _convert constructor: -> super 'convert', _convert

View File

@ -16,9 +16,9 @@ HMEVENT = require '../core/event-codes'
CreateVerb = module.exports = Verb.extend module.exports = class CreateVerb extends Verb
init: -> @_super 'new', _create constructor: -> super 'new', _create

View File

@ -15,9 +15,9 @@ HMEVENT = require('../core/event-codes')
PeekVerb = module.exports = Verb.extend module.exports = class PeekVerb extends Verb
init: -> @_super 'peek', _peek constructor: -> super 'peek', _peek

View File

@ -19,9 +19,9 @@ safeLoadJSON = require '../utils/safe-json-loader'
###* An invokable resume validation command. ### ###* An invokable resume validation command. ###
ValidateVerb = module.exports = Verb.extend module.exports = class ValidateVerb extends Verb
init: -> @_super 'validate', _validate constructor: -> super 'validate', _validate

View File

@ -6,8 +6,6 @@ Definition of the Verb class.
# Use J. Resig's nifty class implementation
Class = require '../utils/class'
EVENTS = require 'events' EVENTS = require 'events'
HMEVENT = require '../core/event-codes' HMEVENT = require '../core/event-codes'
Promise = require 'pinkie-promise' Promise = require 'pinkie-promise'
@ -18,14 +16,12 @@ Promise = require 'pinkie-promise'
An instantiation of a HackMyResume command. An instantiation of a HackMyResume command.
@class Verb @class Verb
### ###
Verb = module.exports = Class.extend module.exports = class Verb
###* Constructor. Automatically called at creation. ### ###* Constructor. Automatically called at creation. ###
init: ( moniker, workhorse ) -> constructor: ( @moniker, @workhorse ) ->
@moniker = moniker
@workhorse = workhorse
@emitter = new EVENTS.EventEmitter() @emitter = new EVENTS.EventEmitter()
return return