From f72b02a0f4c05cd383b7fc652922cd575a3663db Mon Sep 17 00:00:00 2001 From: hacksalot Date: Tue, 2 Feb 2016 13:38:12 -0500 Subject: [PATCH] Refactor generators to CoffeeScript classes. --- dist/generators/base-generator.js | 39 ++++++++++-------- dist/generators/html-generator.js | 27 ++++++++----- dist/generators/html-pdf-cli-generator.js | 33 ++++++++++----- dist/generators/html-png-generator.js | 29 +++++++++----- dist/generators/json-generator.js | 38 +++++++++++------- dist/generators/json-yaml-generator.js | 31 ++++++++++----- dist/generators/latex-generator.js | 19 ++++++--- dist/generators/markdown-generator.js | 21 ++++++---- dist/generators/template-generator.js | 42 ++++++++++++-------- dist/generators/text-generator.js | 19 ++++++--- dist/generators/word-generator.js | 23 ++++++++--- dist/generators/xml-generator.js | 21 ++++++---- dist/generators/yaml-generator.js | 17 +++++--- src/generators/base-generator.coffee | 12 ++---- src/generators/html-generator.coffee | 6 +-- src/generators/html-pdf-cli-generator.coffee | 6 +-- src/generators/html-png-generator.coffee | 6 +-- src/generators/json-generator.coffee | 10 ++--- src/generators/json-yaml-generator.coffee | 6 +-- src/generators/latex-generator.coffee | 6 +-- src/generators/markdown-generator.coffee | 8 ++-- src/generators/template-generator.coffee | 13 ++---- src/generators/text-generator.coffee | 6 +-- src/generators/word-generator.coffee | 7 ++-- src/generators/xml-generator.coffee | 9 ++--- src/generators/yaml-generator.coffee | 5 ++- 26 files changed, 276 insertions(+), 183 deletions(-) diff --git a/dist/generators/base-generator.js b/dist/generators/base-generator.js index ee8e159..b7b1889 100644 --- a/dist/generators/base-generator.js +++ b/dist/generators/base-generator.js @@ -1,34 +1,39 @@ /** Definition of the BaseGenerator class. -@module base-generator.js +@module generators/base-generator @license MIT. See LICENSE.md for details. */ + +/** +The BaseGenerator class is the root of the generator hierarchy. Functionality +common to ALL generators lives here. + */ + (function() { - var BaseGenerator, Class; + var BaseGenerator; - Class = require('../utils/class'); - - - /** - The BaseGenerator class is the root of the generator hierarchy. Functionality - common to ALL generators lives here. - */ - - BaseGenerator = module.exports = Class.extend({ + module.exports = BaseGenerator = (function() { /** Base-class initialize. */ - init: function(outputFormat) { - return this.format = outputFormat; - }, + function BaseGenerator(format) { + this.format = format; + } + /** Status codes. */ - codes: require('../core/status-codes'), + + BaseGenerator.prototype.codes = require('../core/status-codes'); + /** Generator options. */ - opts: {} - }); + + BaseGenerator.prototype.opts = {}; + + return BaseGenerator; + + })(); }).call(this); diff --git a/dist/generators/html-generator.js b/dist/generators/html-generator.js index e4f8385..1dd226b 100644 --- a/dist/generators/html-generator.js +++ b/dist/generators/html-generator.js @@ -1,12 +1,14 @@ /** Definition of the HTMLGenerator class. +@module generators/html-generator @license MIT. See LICENSE.md for details. -@module html-generator.js */ (function() { - var FS, HTML, HtmlGenerator, PATH, TemplateGenerator; + var FS, HTML, HtmlGenerator, PATH, TemplateGenerator, + 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; TemplateGenerator = require('./template-generator'); @@ -18,16 +20,20 @@ Definition of the HTMLGenerator class. require('string.prototype.endswith'); - HtmlGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('html'); - }, + module.exports = HtmlGenerator = (function(superClass) { + extend(HtmlGenerator, superClass); + + function HtmlGenerator() { + HtmlGenerator.__super__.constructor.call(this, 'html'); + } + /** Copy satellite CSS files to the destination and optionally pretty-print the HTML resume prior to saving. */ - onBeforeSave: function(info) { + + HtmlGenerator.prototype.onBeforeSave = function(info) { if (info.outputFile.endsWith('.css')) { return info.mk; } @@ -36,8 +42,11 @@ Definition of the HTMLGenerator class. } else { return info.mk; } - } - }); + }; + + return HtmlGenerator; + + })(TemplateGenerator); }).call(this); diff --git a/dist/generators/html-pdf-cli-generator.js b/dist/generators/html-pdf-cli-generator.js index 9e6ebe3..4937245 100644 --- a/dist/generators/html-pdf-cli-generator.js +++ b/dist/generators/html-pdf-cli-generator.js @@ -1,12 +1,14 @@ /** Definition of the HtmlPdfCLIGenerator class. -@module html-pdf-generator.js +@module generators/html-pdf-generator.js @license MIT. See LICENSE.md for details. */ (function() { - var FS, HMSTATUS, HtmlPdfCLIGenerator, PATH, SLASH, TemplateGenerator, _, engines; + var FS, HMSTATUS, HtmlPdfCLIGenerator, PATH, SLASH, TemplateGenerator, _, engines, + 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; TemplateGenerator = require('./template-generator'); @@ -27,13 +29,17 @@ Definition of the HtmlPdfCLIGenerator class. If an engine isn't installed for a particular platform, error out gracefully. */ - HtmlPdfCLIGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('pdf', 'html'); - }, + module.exports = HtmlPdfCLIGenerator = (function(superClass) { + extend(HtmlPdfCLIGenerator, superClass); + + function HtmlPdfCLIGenerator() { + HtmlPdfCLIGenerator.__super__.constructor.call(this, 'pdf', 'html'); + } + /** Generate the binary PDF. */ - onBeforeSave: function(info) { + + HtmlPdfCLIGenerator.prototype.onBeforeSave = function(info) { var safe_eng; safe_eng = info.opts.pdf || 'wkhtmltopdf'; if (safe_eng === 'phantom') { @@ -45,22 +51,27 @@ Definition of the HtmlPdfCLIGenerator class. engines[safe_eng].call(this, info.mk, info.outputFile, this.onError); return null; } - }, + }; + /* Low-level error callback for spawn(). May be called after HMR process termination, so object references may not be valid here. That's okay; if the references are invalid, the error was already logged. We could use spawn-watch here but that causes issues on legacy Node.js. */ - onError: function(ex, param) { + + HtmlPdfCLIGenerator.prototype.onError = function(ex, param) { var ref; if ((ref = param.errHandler) != null) { if (typeof ref.err === "function") { ref.err(HMSTATUS.pdfGeneration, ex); } } - } - }); + }; + + return HtmlPdfCLIGenerator; + + })(TemplateGenerator); engines = { diff --git a/dist/generators/html-png-generator.js b/dist/generators/html-png-generator.js index 022c680..0627383 100644 --- a/dist/generators/html-png-generator.js +++ b/dist/generators/html-png-generator.js @@ -1,12 +1,14 @@ /** Definition of the HtmlPngGenerator class. +@module generators/html-png-generator @license MIT. See LICENSE.MD for details. -@module html-png-generator.js */ (function() { - var FS, HTML, HtmlPngGenerator, PATH, SLASH, SPAWN, TemplateGenerator, phantom; + var FS, HTML, HtmlPngGenerator, PATH, SLASH, SPAWN, TemplateGenerator, phantom, + 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; TemplateGenerator = require('./template-generator'); @@ -25,12 +27,16 @@ Definition of the HtmlPngGenerator class. An HTML-based PNG resume generator for HackMyResume. */ - HtmlPngGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('png', 'html'); - }, - invoke: function(rez, themeMarkup, cssInfo, opts) {}, - generate: function(rez, f, opts) { + module.exports = HtmlPngGenerator = (function(superClass) { + extend(HtmlPngGenerator, superClass); + + function HtmlPngGenerator() { + HtmlPngGenerator.__super__.constructor.call(this, 'png', 'html'); + } + + HtmlPngGenerator.prototype.invoke = function(rez, themeMarkup, cssInfo, opts) {}; + + HtmlPngGenerator.prototype.generate = function(rez, f, opts) { var htmlFile, htmlResults; htmlResults = opts.targets.filter(function(t) { return t.fmt.outFormat === 'html'; @@ -39,8 +45,11 @@ Definition of the HtmlPngGenerator class. return fl.info.ext === 'html'; }); phantom(htmlFile[0].data, f); - } - }); + }; + + return HtmlPngGenerator; + + })(TemplateGenerator); /** diff --git a/dist/generators/json-generator.js b/dist/generators/json-generator.js index dfc1aac..2ff715e 100644 --- a/dist/generators/json-generator.js +++ b/dist/generators/json-generator.js @@ -1,12 +1,14 @@ /** Definition of the JsonGenerator class. -@license MIT. See LICENSE.md for details. @module generators/json-generator +@license MIT. See LICENSE.md for details. */ (function() { - var BaseGenerator, FS, JsonGenerator, _; + var BaseGenerator, FS, JsonGenerator, _, + 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; BaseGenerator = require('./base-generator'); @@ -15,16 +17,18 @@ Definition of the JsonGenerator class. _ = require('underscore'); - /** - The JsonGenerator generates a JSON resume directly. - */ + /** The JsonGenerator generates a JSON resume directly. */ - JsonGenerator = module.exports = BaseGenerator.extend({ - init: function() { - return this._super('json'); - }, - keys: ['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index', 'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result', 'isModified', 'htmlPreview', 'safe'], - invoke: function(rez) { + module.exports = JsonGenerator = (function(superClass) { + extend(JsonGenerator, superClass); + + function JsonGenerator() { + JsonGenerator.__super__.constructor.call(this, 'json'); + } + + JsonGenerator.prototype.keys = ['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index', 'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result', 'isModified', 'htmlPreview', 'safe']; + + JsonGenerator.prototype.invoke = function(rez) { var replacer; replacer = function(key, value) { if (_.some(this.keys, function(val) { @@ -36,11 +40,15 @@ Definition of the JsonGenerator class. } }; return JSON.stringify(rez, replacer, 2); - }, - generate: function(rez, f) { + }; + + JsonGenerator.prototype.generate = function(rez, f) { FS.writeFileSync(f, this.invoke(rez), 'utf8'); - } - }); + }; + + return JsonGenerator; + + })(BaseGenerator); }).call(this); diff --git a/dist/generators/json-yaml-generator.js b/dist/generators/json-yaml-generator.js index b2f6e04..e041aca 100644 --- a/dist/generators/json-yaml-generator.js +++ b/dist/generators/json-yaml-generator.js @@ -1,12 +1,14 @@ /** Definition of the JsonYamlGenerator class. -@module json-yaml-generator.js +@module generators/json-yaml-generator @license MIT. See LICENSE.md for details. */ (function() { - var BaseGenerator, FS, JsonYamlGenerator, YAML; + var BaseGenerator, FS, JsonYamlGenerator, YAML, + 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; BaseGenerator = require('./base-generator'); @@ -21,20 +23,27 @@ Definition of the JsonYamlGenerator class. also YamlGenerator (yaml-generator.js). */ - JsonYamlGenerator = module.exports = BaseGenerator.extend({ - init: function() { - return this._super('yml'); - }, - invoke: function(rez, themeMarkup, cssInfo, opts) { + module.exports = JsonYamlGenerator = (function(superClass) { + extend(JsonYamlGenerator, superClass); + + function JsonYamlGenerator() { + JsonYamlGenerator.__super__.constructor.call(this, 'yml'); + } + + JsonYamlGenerator.prototype.invoke = function(rez, themeMarkup, cssInfo, opts) { return YAML.stringify(JSON.parse(rez.stringify()), Infinity, 2); - }, - generate: function(rez, f, opts) { + }; + + JsonYamlGenerator.prototype.generate = function(rez, f, opts) { var data; data = YAML.stringify(JSON.parse(rez.stringify()), Infinity, 2); FS.writeFileSync(f, data, 'utf8'); return data; - } - }); + }; + + return JsonYamlGenerator; + + })(BaseGenerator); }).call(this); diff --git a/dist/generators/latex-generator.js b/dist/generators/latex-generator.js index 885e9a6..6e2d063 100644 --- a/dist/generators/latex-generator.js +++ b/dist/generators/latex-generator.js @@ -1,12 +1,14 @@ /** Definition of the LaTeXGenerator class. -@license MIT. See LICENSE.md for details. @module generators/latex-generator +@license MIT. See LICENSE.md for details. */ (function() { - var LaTeXGenerator, TemplateGenerator; + var LaTeXGenerator, TemplateGenerator, + 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; TemplateGenerator = require('./template-generator'); @@ -15,11 +17,16 @@ Definition of the LaTeXGenerator class. LaTeXGenerator generates a LaTeX resume via TemplateGenerator. */ - LaTeXGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('latex', 'tex'); + module.exports = LaTeXGenerator = (function(superClass) { + extend(LaTeXGenerator, superClass); + + function LaTeXGenerator() { + LaTeXGenerator.__super__.constructor.call(this, 'latex', 'tex'); } - }); + + return LaTeXGenerator; + + })(TemplateGenerator); }).call(this); diff --git a/dist/generators/markdown-generator.js b/dist/generators/markdown-generator.js index eba9d95..488f0da 100644 --- a/dist/generators/markdown-generator.js +++ b/dist/generators/markdown-generator.js @@ -1,12 +1,14 @@ /** Definition of the MarkdownGenerator class. -@license MIT. Copyright (c) 2015 James Devlin / FluentDesk. -@module markdown-generator.js +@module generators/markdown-generator +@license MIT. See LICENSE.md for details. */ (function() { - var MarkdownGenerator, TemplateGenerator; + var MarkdownGenerator, TemplateGenerator, + 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; TemplateGenerator = require('./template-generator'); @@ -15,11 +17,16 @@ Definition of the MarkdownGenerator class. MarkdownGenerator generates a Markdown-formatted resume via TemplateGenerator. */ - MarkdownGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('md', 'txt'); + module.exports = MarkdownGenerator = (function(superClass) { + extend(MarkdownGenerator, superClass); + + function MarkdownGenerator() { + MarkdownGenerator.__super__.constructor.call(this, 'md', 'txt'); } - }); + + return MarkdownGenerator; + + })(TemplateGenerator); }).call(this); diff --git a/dist/generators/template-generator.js b/dist/generators/template-generator.js index aaf8455..247875c 100644 --- a/dist/generators/template-generator.js +++ b/dist/generators/template-generator.js @@ -1,12 +1,14 @@ /** Definition of the TemplateGenerator class. TODO: Refactor +@module generators/template-generator @license MIT. See LICENSE.md for details. -@module template-generator.js */ (function() { - var BaseGenerator, EXTEND, FRESHTheme, FS, JRSTheme, MD, MKDIRP, PATH, TemplateGenerator, XML, _, _defaultOpts, _reg, freeze, parsePath, unfreeze; + var BaseGenerator, EXTEND, FRESHTheme, FS, JRSTheme, MD, MKDIRP, PATH, TemplateGenerator, XML, _, _defaultOpts, _reg, freeze, parsePath, unfreeze, + 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-extra'); @@ -38,16 +40,21 @@ Definition of the TemplateGenerator class. TODO: Refactor @class TemplateGenerator */ - TemplateGenerator = module.exports = BaseGenerator.extend({ + module.exports = TemplateGenerator = (function(superClass) { + extend(TemplateGenerator, superClass); + /** Constructor. Set the output format and template format for this generator. Will usually be called by a derived generator such as HTMLGenerator or MarkdownGenerator. */ - init: function(outputFormat, templateFormat, cssFile) { - this._super(outputFormat); + + function TemplateGenerator(outputFormat, templateFormat, cssFile) { + TemplateGenerator.__super__.constructor.call(this, outputFormat); this.tplFormat = templateFormat || outputFormat; - }, + return; + } + /** Generate a resume using string-based inputs and outputs without touching the filesystem. @@ -57,7 +64,8 @@ Definition of the TemplateGenerator class. TODO: Refactor @returns {Array} An array of objects representing the generated output files. */ - invoke: function(rez, opts) { + + TemplateGenerator.prototype.invoke = function(rez, opts) { var curFmt, results; opts = opts ? (this.opts = EXTEND(true, {}, _defaultOpts, opts)) : this.opts; curFmt = opts.themeObj.getFormat(this.format); @@ -80,7 +88,8 @@ Definition of the TemplateGenerator class. TODO: Refactor return { files: results }; - }, + }; + /** Generate a resume using file-based inputs and outputs. Requires access to the local filesystem. @@ -89,7 +98,8 @@ Definition of the TemplateGenerator class. TODO: Refactor @param f Full path to the output resume file to generate. @param opts Generator options. */ - generate: function(rez, f, opts) { + + TemplateGenerator.prototype.generate = function(rez, f, opts) { var curFmt, genInfo, outFolder; this.opts = EXTEND(true, {}, _defaultOpts, opts); genInfo = this.invoke(rez, null); @@ -136,7 +146,8 @@ Definition of the TemplateGenerator class. TODO: Refactor }); } return genInfo; - }, + }; + /** Perform a single resume resume transformation using string-based inputs and outputs without touching the local file system. @@ -146,7 +157,8 @@ Definition of the TemplateGenerator class. TODO: Refactor @param cssInfo Needs to be refactored. @param opts Options and passthrough data. */ - single: function(json, jst, format, opts, theme, curFmt) { + + TemplateGenerator.prototype.single = function(json, jst, format, opts, theme, curFmt) { var eng, result; if (this.opts.freezeBreaks) { jst = freeze(jst); @@ -157,13 +169,11 @@ Definition of the TemplateGenerator class. TODO: Refactor result = unfreeze(result); } return result; - } - }); + }; + return TemplateGenerator; - /** Export the TemplateGenerator function/ctor. */ - - module.exports = TemplateGenerator; + })(BaseGenerator); /** Freeze newlines for protection against errant JST parsers. */ diff --git a/dist/generators/text-generator.js b/dist/generators/text-generator.js index 25554e8..9494f8d 100644 --- a/dist/generators/text-generator.js +++ b/dist/generators/text-generator.js @@ -1,12 +1,14 @@ /** Definition of the TextGenerator class. +@module generators/text-generator @license MIT. See LICENSE.md for details. -@module text-generator.js */ (function() { - var TemplateGenerator, TextGenerator; + var TemplateGenerator, TextGenerator, + 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; TemplateGenerator = require('./template-generator'); @@ -15,11 +17,16 @@ Definition of the TextGenerator class. The TextGenerator generates a plain-text resume via the TemplateGenerator. */ - TextGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('txt'); + module.exports = TextGenerator = (function(superClass) { + extend(TextGenerator, superClass); + + function TextGenerator() { + TextGenerator.__super__.constructor.call(this, 'txt'); } - }); + + return TextGenerator; + + })(TemplateGenerator); }).call(this); diff --git a/dist/generators/word-generator.js b/dist/generators/word-generator.js index 7d019dd..ca38707 100644 --- a/dist/generators/word-generator.js +++ b/dist/generators/word-generator.js @@ -1,20 +1,31 @@ /* Definition of the WordGenerator class. -@license MIT. See LICENSE.md for details. @module generators/word-generator +@license MIT. See LICENSE.md for details. */ (function() { - var TemplateGenerator, WordGenerator; + var TemplateGenerator, WordGenerator, + 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; TemplateGenerator = require('./template-generator'); - WordGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('doc', 'xml'); + module.exports = WordGenerator = (function(superClass) { + extend(WordGenerator, superClass); + + function WordGenerator() { + return WordGenerator.__super__.constructor.apply(this, arguments); } - }); + + WordGenerator.prototype.init = function() { + return WordGenerator.__super__.init.call(this, 'doc', 'xml'); + }; + + return WordGenerator; + + })(TemplateGenerator); }).call(this); diff --git a/dist/generators/xml-generator.js b/dist/generators/xml-generator.js index df87086..ceaa685 100644 --- a/dist/generators/xml-generator.js +++ b/dist/generators/xml-generator.js @@ -6,20 +6,25 @@ Definition of the XMLGenerator class. */ (function() { - var BaseGenerator, XMLGenerator; + var BaseGenerator, XMLGenerator, + 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; BaseGenerator = require('./base-generator'); - /** - The XmlGenerator generates an XML resume via the TemplateGenerator. - */ + /** The XmlGenerator generates an XML resume via the TemplateGenerator. */ - XMLGenerator = module.exports = BaseGenerator.extend({ - init: function() { - return this._super('xml'); + module.exports = XMLGenerator = (function(superClass) { + extend(XMLGenerator, superClass); + + function XMLGenerator() { + XMLGenerator.__super__.constructor.call(this, 'xml'); } - }); + + return XMLGenerator; + + })(BaseGenerator); }).call(this); diff --git a/dist/generators/yaml-generator.js b/dist/generators/yaml-generator.js index b839a39..1d45e81 100644 --- a/dist/generators/yaml-generator.js +++ b/dist/generators/yaml-generator.js @@ -6,7 +6,9 @@ Definition of the YAMLGenerator class. */ (function() { - var TemplateGenerator, YAMLGenerator; + var TemplateGenerator, YAMLGenerator, + 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; TemplateGenerator = require('./template-generator'); @@ -15,11 +17,16 @@ Definition of the YAMLGenerator class. YamlGenerator generates a YAML-formatted resume via TemplateGenerator. */ - YAMLGenerator = module.exports = TemplateGenerator.extend({ - init: function() { - return this._super('yml', 'yml'); + module.exports = YAMLGenerator = (function(superClass) { + extend(YAMLGenerator, superClass); + + function YAMLGenerator() { + YAMLGenerator.__super__.constructor.call(this, 'yml', 'yml'); } - }); + + return YAMLGenerator; + + })(TemplateGenerator); }).call(this); diff --git a/src/generators/base-generator.coffee b/src/generators/base-generator.coffee index 5d15627..351f9ee 100644 --- a/src/generators/base-generator.coffee +++ b/src/generators/base-generator.coffee @@ -1,25 +1,19 @@ ###* Definition of the BaseGenerator class. -@module base-generator.js +@module generators/base-generator @license MIT. See LICENSE.md for details. ### - -# Use J. Resig's nifty class implementation -Class = require '../utils/class' - - - ###* The BaseGenerator class is the root of the generator hierarchy. Functionality common to ALL generators lives here. ### -BaseGenerator = module.exports = Class.extend +module.exports = class BaseGenerator ###* Base-class initialize. ### - init: ( outputFormat ) -> @format = outputFormat + constructor: ( @format ) -> ###* Status codes. ### codes: require '../core/status-codes' diff --git a/src/generators/html-generator.coffee b/src/generators/html-generator.coffee index 09888c1..df2f144 100644 --- a/src/generators/html-generator.coffee +++ b/src/generators/html-generator.coffee @@ -1,7 +1,7 @@ ###* Definition of the HTMLGenerator class. +@module generators/html-generator @license MIT. See LICENSE.md for details. -@module html-generator.js ### @@ -14,9 +14,9 @@ require 'string.prototype.endswith' -HtmlGenerator = module.exports = TemplateGenerator.extend +module.exports = class HtmlGenerator extends TemplateGenerator - init: -> @_super 'html' + constructor: -> super 'html' ###* Copy satellite CSS files to the destination and optionally pretty-print diff --git a/src/generators/html-pdf-cli-generator.coffee b/src/generators/html-pdf-cli-generator.coffee index 5af5843..776b55a 100644 --- a/src/generators/html-pdf-cli-generator.coffee +++ b/src/generators/html-pdf-cli-generator.coffee @@ -1,6 +1,6 @@ ###* Definition of the HtmlPdfCLIGenerator class. -@module html-pdf-generator.js +@module generators/html-pdf-generator.js @license MIT. See LICENSE.md for details. ### @@ -21,11 +21,11 @@ wkhtmltopdf, and other PDF engines over a CLI (command-line interface). If an engine isn't installed for a particular platform, error out gracefully. ### -HtmlPdfCLIGenerator = module.exports = TemplateGenerator.extend +module.exports = class HtmlPdfCLIGenerator extends TemplateGenerator - init: () -> @_super 'pdf', 'html' + constructor: () -> super 'pdf', 'html' diff --git a/src/generators/html-png-generator.coffee b/src/generators/html-png-generator.coffee index 36a790a..e148031 100644 --- a/src/generators/html-png-generator.coffee +++ b/src/generators/html-png-generator.coffee @@ -1,7 +1,7 @@ ###* Definition of the HtmlPngGenerator class. +@module generators/html-png-generator @license MIT. See LICENSE.MD for details. -@module html-png-generator.js ### @@ -17,9 +17,9 @@ PATH = require 'path' ###* An HTML-based PNG resume generator for HackMyResume. ### -HtmlPngGenerator = module.exports = TemplateGenerator.extend +module.exports = class HtmlPngGenerator extends TemplateGenerator - init: -> @_super 'png', 'html' + constructor: -> super 'png', 'html' invoke: ( rez, themeMarkup, cssInfo, opts ) -> # TODO: Not currently called or callable. diff --git a/src/generators/json-generator.coffee b/src/generators/json-generator.coffee index 6443cc5..584c165 100644 --- a/src/generators/json-generator.coffee +++ b/src/generators/json-generator.coffee @@ -1,20 +1,18 @@ ###* Definition of the JsonGenerator class. -@license MIT. See LICENSE.md for details. @module generators/json-generator +@license MIT. See LICENSE.md for details. ### BaseGenerator = require './base-generator' FS = require 'fs' _ = require 'underscore' -###* -The JsonGenerator generates a JSON resume directly. -### +###* The JsonGenerator generates a JSON resume directly. ### -JsonGenerator = module.exports = BaseGenerator.extend +module.exports = class JsonGenerator extends BaseGenerator - init: () -> @_super 'json' + constructor: () -> super 'json' keys: ['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index', 'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result', diff --git a/src/generators/json-yaml-generator.coffee b/src/generators/json-yaml-generator.coffee index e7041c5..bb44aab 100644 --- a/src/generators/json-yaml-generator.coffee +++ b/src/generators/json-yaml-generator.coffee @@ -1,6 +1,6 @@ ###* Definition of the JsonYamlGenerator class. -@module json-yaml-generator.js +@module generators/json-yaml-generator @license MIT. See LICENSE.md for details. ### @@ -18,9 +18,9 @@ JSON without a template, producing an equivalent YAML-formatted resume. See also YamlGenerator (yaml-generator.js). ### -JsonYamlGenerator = module.exports = BaseGenerator.extend +module.exports = class JsonYamlGenerator extends BaseGenerator - init: () -> @_super 'yml' + constructor: () -> super 'yml' invoke: ( rez, themeMarkup, cssInfo, opts ) -> YAML.stringify JSON.parse( rez.stringify() ), Infinity, 2 diff --git a/src/generators/latex-generator.coffee b/src/generators/latex-generator.coffee index f46f748..65f2a00 100644 --- a/src/generators/latex-generator.coffee +++ b/src/generators/latex-generator.coffee @@ -1,7 +1,7 @@ ###* Definition of the LaTeXGenerator class. -@license MIT. See LICENSE.md for details. @module generators/latex-generator +@license MIT. See LICENSE.md for details. ### TemplateGenerator = require './template-generator' @@ -9,6 +9,6 @@ TemplateGenerator = require './template-generator' ###* LaTeXGenerator generates a LaTeX resume via TemplateGenerator. ### -LaTeXGenerator = module.exports = TemplateGenerator.extend +module.exports = class LaTeXGenerator extends TemplateGenerator - init: () -> @_super 'latex', 'tex' + constructor: () -> super 'latex', 'tex' diff --git a/src/generators/markdown-generator.coffee b/src/generators/markdown-generator.coffee index 6e1dda9..b82f431 100644 --- a/src/generators/markdown-generator.coffee +++ b/src/generators/markdown-generator.coffee @@ -1,7 +1,7 @@ ###* Definition of the MarkdownGenerator class. -@license MIT. Copyright (c) 2015 James Devlin / FluentDesk. -@module markdown-generator.js +@module generators/markdown-generator +@license MIT. See LICENSE.md for details. ### TemplateGenerator = require './template-generator' @@ -9,6 +9,6 @@ TemplateGenerator = require './template-generator' ###* MarkdownGenerator generates a Markdown-formatted resume via TemplateGenerator. ### -MarkdownGenerator = module.exports = TemplateGenerator.extend +module.exports = class MarkdownGenerator extends TemplateGenerator - init: () -> @_super 'md', 'txt' + constructor: () -> super 'md', 'txt' diff --git a/src/generators/template-generator.coffee b/src/generators/template-generator.coffee index 68d3e12..ae615d9 100644 --- a/src/generators/template-generator.coffee +++ b/src/generators/template-generator.coffee @@ -1,7 +1,7 @@ ###* Definition of the TemplateGenerator class. TODO: Refactor +@module generators/template-generator @license MIT. See LICENSE.md for details. -@module template-generator.js ### @@ -27,14 +27,14 @@ plain text, and XML versions of Microsoft Word, Excel, and OpenOffice. @class TemplateGenerator ### -TemplateGenerator = module.exports = BaseGenerator.extend +module.exports = class TemplateGenerator extends BaseGenerator ###* Constructor. Set the output format and template format for this generator. Will usually be called by a derived generator such as HTMLGenerator or MarkdownGenerator. ### - init: ( outputFormat, templateFormat, cssFile ) -> - @_super outputFormat + constructor: ( outputFormat, templateFormat, cssFile ) -> + super outputFormat @tplFormat = templateFormat || outputFormat return @@ -149,11 +149,6 @@ TemplateGenerator = module.exports = BaseGenerator.extend -###* Export the TemplateGenerator function/ctor. ### -module.exports = TemplateGenerator - - - ###* Freeze newlines for protection against errant JST parsers. ### freeze = ( markup ) -> markup.replace( _reg.regN, _defaultOpts.nSym ) diff --git a/src/generators/text-generator.coffee b/src/generators/text-generator.coffee index ef7e2d0..d174ca3 100644 --- a/src/generators/text-generator.coffee +++ b/src/generators/text-generator.coffee @@ -1,7 +1,7 @@ ###* Definition of the TextGenerator class. +@module generators/text-generator @license MIT. See LICENSE.md for details. -@module text-generator.js ### TemplateGenerator = require './template-generator' @@ -9,6 +9,6 @@ TemplateGenerator = require './template-generator' ###* The TextGenerator generates a plain-text resume via the TemplateGenerator. ### -TextGenerator = module.exports = TemplateGenerator.extend +module.exports = class TextGenerator extends TemplateGenerator - init: () -> @_super 'txt' + constructor: () -> super 'txt' diff --git a/src/generators/word-generator.coffee b/src/generators/word-generator.coffee index 9efdcd3..e8b765d 100644 --- a/src/generators/word-generator.coffee +++ b/src/generators/word-generator.coffee @@ -1,11 +1,12 @@ ### Definition of the WordGenerator class. -@license MIT. See LICENSE.md for details. @module generators/word-generator +@license MIT. See LICENSE.md for details. ### TemplateGenerator = require './template-generator' -WordGenerator = module.exports = TemplateGenerator.extend - init: () -> @_super 'doc', 'xml' +module.exports = class WordGenerator extends TemplateGenerator + + init: () -> super 'doc', 'xml' diff --git a/src/generators/xml-generator.coffee b/src/generators/xml-generator.coffee index 42867f1..15cbccc 100644 --- a/src/generators/xml-generator.coffee +++ b/src/generators/xml-generator.coffee @@ -6,8 +6,7 @@ Definition of the XMLGenerator class. BaseGenerator = require './base-generator' -###* -The XmlGenerator generates an XML resume via the TemplateGenerator. -### -XMLGenerator = module.exports = BaseGenerator.extend - init: () -> @_super 'xml' +###* The XmlGenerator generates an XML resume via the TemplateGenerator. ### +module.exports = class XMLGenerator extends BaseGenerator + + constructor: () -> super 'xml' diff --git a/src/generators/yaml-generator.coffee b/src/generators/yaml-generator.coffee index 1817c45..5537f56 100644 --- a/src/generators/yaml-generator.coffee +++ b/src/generators/yaml-generator.coffee @@ -11,5 +11,6 @@ TemplateGenerator = require './template-generator' YamlGenerator generates a YAML-formatted resume via TemplateGenerator. ### -YAMLGenerator = module.exports = TemplateGenerator.extend - init: () -> @_super 'yml', 'yml' +module.exports = class YAMLGenerator extends TemplateGenerator + + constructor: () -> super 'yml', 'yml'