mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 00:10:15 +00:00
Refactor verbs to CoffeeScript classes.
Retire Resig's class implementation.
This commit is contained in:
parent
fd39cc9fd9
commit
63a0c78fc5
17
dist/verbs/analyze.js
vendored
17
dist/verbs/analyze.js
vendored
@ -6,7 +6,9 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(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');
|
||||
|
||||
@ -27,11 +29,16 @@ Implementation of the 'analyze' verb for HackMyResume.
|
||||
|
||||
/** An invokable resume analysis command. */
|
||||
|
||||
AnalyzeVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('analyze', _analyze);
|
||||
module.exports = AnalyzeVerb = (function(superClass) {
|
||||
extend(AnalyzeVerb, superClass);
|
||||
|
||||
function AnalyzeVerb() {
|
||||
AnalyzeVerb.__super__.constructor.call(this, 'analyze', _analyze);
|
||||
}
|
||||
});
|
||||
|
||||
return AnalyzeVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Private workhorse for the 'analyze' command. */
|
||||
|
18
dist/verbs/build.js
vendored
18
dist/verbs/build.js
vendored
@ -6,7 +6,9 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(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');
|
||||
|
||||
@ -70,13 +72,19 @@ Implementation of the 'build' verb for HackMyResume.
|
||||
|
||||
/** An invokable resume generation command. */
|
||||
|
||||
BuildVerb = module.exports = Verb.extend({
|
||||
module.exports = BuildVerb = (function(superClass) {
|
||||
extend1(BuildVerb, superClass);
|
||||
|
||||
|
||||
/** 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
17
dist/verbs/convert.js
vendored
@ -6,7 +6,9 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(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');
|
||||
|
||||
@ -20,11 +22,16 @@ Implementation of the 'convert' verb for HackMyResume.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
ConvertVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('convert', _convert);
|
||||
module.exports = ConvertVerb = (function(superClass) {
|
||||
extend(ConvertVerb, superClass);
|
||||
|
||||
function ConvertVerb() {
|
||||
ConvertVerb.__super__.constructor.call(this, 'convert', _convert);
|
||||
}
|
||||
});
|
||||
|
||||
return ConvertVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Private workhorse method. Convert 0..N resumes between FRESH and JRS
|
||||
|
17
dist/verbs/create.js
vendored
17
dist/verbs/create.js
vendored
@ -6,7 +6,9 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(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');
|
||||
|
||||
@ -22,11 +24,16 @@ Implementation of the 'create' verb for HackMyResume.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
CreateVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('new', _create);
|
||||
module.exports = CreateVerb = (function(superClass) {
|
||||
extend(CreateVerb, superClass);
|
||||
|
||||
function CreateVerb() {
|
||||
CreateVerb.__super__.constructor.call(this, 'new', _create);
|
||||
}
|
||||
});
|
||||
|
||||
return CreateVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Create a new empty resume in either FRESH or JRS format. */
|
||||
|
17
dist/verbs/peek.js
vendored
17
dist/verbs/peek.js
vendored
@ -6,7 +6,9 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(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');
|
||||
|
||||
@ -20,11 +22,16 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
|
||||
HMEVENT = require('../core/event-codes');
|
||||
|
||||
PeekVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('peek', _peek);
|
||||
module.exports = PeekVerb = (function(superClass) {
|
||||
extend(PeekVerb, superClass);
|
||||
|
||||
function PeekVerb() {
|
||||
PeekVerb.__super__.constructor.call(this, 'peek', _peek);
|
||||
}
|
||||
});
|
||||
|
||||
return PeekVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Peek at a resume, resume section, or resume field. */
|
||||
|
17
dist/verbs/validate.js
vendored
17
dist/verbs/validate.js
vendored
@ -6,7 +6,9 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
*/
|
||||
|
||||
(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');
|
||||
|
||||
@ -29,11 +31,16 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
|
||||
/** An invokable resume validation command. */
|
||||
|
||||
ValidateVerb = module.exports = Verb.extend({
|
||||
init: function() {
|
||||
return this._super('validate', _validate);
|
||||
module.exports = ValidateVerb = (function(superClass) {
|
||||
extend(ValidateVerb, superClass);
|
||||
|
||||
function ValidateVerb() {
|
||||
ValidateVerb.__super__.constructor.call(this, 'validate', _validate);
|
||||
}
|
||||
});
|
||||
|
||||
return ValidateVerb;
|
||||
|
||||
})(Verb);
|
||||
|
||||
|
||||
/** Validate 1 to N resumes in FRESH or JSON Resume format. */
|
||||
|
57
dist/verbs/verb.js
vendored
57
dist/verbs/verb.js
vendored
@ -6,9 +6,7 @@ Definition of the Verb class.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var Class, EVENTS, HMEVENT, Promise, Verb;
|
||||
|
||||
Class = require('../utils/class');
|
||||
var EVENTS, HMEVENT, Promise, Verb;
|
||||
|
||||
EVENTS = require('events');
|
||||
|
||||
@ -22,17 +20,20 @@ Definition of the Verb class.
|
||||
@class Verb
|
||||
*/
|
||||
|
||||
Verb = module.exports = Class.extend({
|
||||
module.exports = Verb = (function() {
|
||||
|
||||
/** Constructor. Automatically called at creation. */
|
||||
init: function(moniker, workhorse) {
|
||||
function Verb(moniker, workhorse) {
|
||||
this.moniker = moniker;
|
||||
this.workhorse = workhorse;
|
||||
this.emitter = new EVENTS.EventEmitter();
|
||||
},
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** Invoke the command. */
|
||||
invoke: function() {
|
||||
|
||||
Verb.prototype.invoke = function() {
|
||||
var argsArray, that;
|
||||
this.stat(HMEVENT.begin, {
|
||||
cmd: this.moniker
|
||||
@ -44,23 +45,29 @@ Definition of the Verb class.
|
||||
that.reject = rej;
|
||||
that.workhorse.apply(that, argsArray);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Forward subscriptions to the event emitter. */
|
||||
on: function() {
|
||||
|
||||
Verb.prototype.on = function() {
|
||||
return this.emitter.on.apply(this.emitter, arguments);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Fire an arbitrary event, scoped to "hmr:". */
|
||||
fire: function(evtName, payload) {
|
||||
|
||||
Verb.prototype.fire = function(evtName, payload) {
|
||||
payload = payload || {};
|
||||
payload.cmd = this.moniker;
|
||||
this.emitter.emit('hmr:' + evtName, payload);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Handle an error condition. */
|
||||
err: function(errorCode, payload, hot) {
|
||||
|
||||
Verb.prototype.err = function(errorCode, payload, hot) {
|
||||
payload = payload || {};
|
||||
payload.sub = payload.fluenterror = errorCode;
|
||||
payload["throw"] = hot;
|
||||
@ -74,25 +81,33 @@ Definition of the Verb class.
|
||||
throw payload;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Fire the 'hmr:status' error event. */
|
||||
stat: function(subEvent, payload) {
|
||||
|
||||
Verb.prototype.stat = function(subEvent, payload) {
|
||||
payload = payload || {};
|
||||
payload.sub = subEvent;
|
||||
this.fire('status', payload);
|
||||
return true;
|
||||
},
|
||||
hasError: function() {
|
||||
};
|
||||
|
||||
Verb.prototype.hasError = function() {
|
||||
return this.errorCode || this.errorObj;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** Associate error info with the invocation. */
|
||||
setError: function(code, obj) {
|
||||
|
||||
Verb.prototype.setError = function(code, obj) {
|
||||
this.errorCode = code;
|
||||
this.errorObj = obj;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Verb;
|
||||
|
||||
})();
|
||||
|
||||
}).call(this);
|
||||
|
||||
|
@ -17,9 +17,9 @@ chalk = require('chalk')
|
||||
|
||||
|
||||
###* An invokable resume analysis command. ###
|
||||
AnalyzeVerb = module.exports = Verb.extend
|
||||
module.exports = class AnalyzeVerb extends Verb
|
||||
|
||||
init: -> @_super 'analyze', _analyze
|
||||
constructor: -> super 'analyze', _analyze
|
||||
|
||||
|
||||
|
||||
|
@ -39,10 +39,10 @@ verifyTheme = null
|
||||
loadTheme = null
|
||||
|
||||
###* An invokable resume generation command. ###
|
||||
BuildVerb = module.exports = Verb.extend
|
||||
module.exports = class BuildVerb extends Verb
|
||||
|
||||
###* Create a new build verb. ###
|
||||
init: () -> @_super 'build', _build
|
||||
constructor: () -> super 'build', _build
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -19,9 +19,9 @@ safeLoadJSON = require '../utils/safe-json-loader'
|
||||
|
||||
|
||||
###* An invokable resume validation command. ###
|
||||
ValidateVerb = module.exports = Verb.extend
|
||||
module.exports = class ValidateVerb extends Verb
|
||||
|
||||
init: -> @_super 'validate', _validate
|
||||
constructor: -> super 'validate', _validate
|
||||
|
||||
|
||||
|
||||
|
@ -6,8 +6,6 @@ Definition of the Verb class.
|
||||
|
||||
|
||||
|
||||
# Use J. Resig's nifty class implementation
|
||||
Class = require '../utils/class'
|
||||
EVENTS = require 'events'
|
||||
HMEVENT = require '../core/event-codes'
|
||||
Promise = require 'pinkie-promise'
|
||||
@ -18,14 +16,12 @@ Promise = require 'pinkie-promise'
|
||||
An instantiation of a HackMyResume command.
|
||||
@class Verb
|
||||
###
|
||||
Verb = module.exports = Class.extend
|
||||
module.exports = class Verb
|
||||
|
||||
|
||||
|
||||
###* Constructor. Automatically called at creation. ###
|
||||
init: ( moniker, workhorse ) ->
|
||||
@moniker = moniker
|
||||
@workhorse = workhorse
|
||||
constructor: ( @moniker, @workhorse ) ->
|
||||
@emitter = new EVENTS.EventEmitter()
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user