From b21fd93d66731db3fc5c19ce2a12b3734f4d4cf7 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Wed, 30 Dec 2015 12:08:46 -0500 Subject: [PATCH] Introduce JRSTheme class. Start splitting out logic into dedicated abstractions for both FRESH and JSON Resume themes given the different structure and use cases of each. --- src/core/jrs-theme.js | 70 ++++++++++++++++++++++++++++++++++++++++ src/core/status-codes.js | 4 ++- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/core/jrs-theme.js diff --git a/src/core/jrs-theme.js b/src/core/jrs-theme.js new file mode 100644 index 0000000..26904c2 --- /dev/null +++ b/src/core/jrs-theme.js @@ -0,0 +1,70 @@ +/** +Definition of the JRSTheme class. +@module jrs-theme.js +@license MIT. See LICENSE.MD for details. +*/ + +(function() { + + + + var _ = require('underscore') + , PATH = require('path') + , parsePath = require('parse-filepath') + , pathExists = require('path-exists').sync; + + + + /** + The JRSTheme class is a representation of a JSON Resume theme asset. + @class JRSTheme + */ + function JRSTheme() { + + } + + /** + Open and parse the specified theme. + */ + JRSTheme.prototype.open = function( themeFolder ) { + + this.folder = themeFolder; + + // Open the [theme-name].json file; should have the same name as folder + var pathInfo = parsePath( themeFolder ); + + // Open and parse the theme's package.json file. + var packageJsonPath = PATH.join(themeFolder, 'package.json'); + if( pathExists( packageJsonPath ) ) { + var themePack = require( themeFolder ); + var themePkgJson = require( packageJsonPath ); + this.name = themePkgJson.name; + this.render = (themePack && themePack.render) || undefined; + this.formats = { + html: { title: 'html', outFormat: 'html', ext: 'html' } + }; + } + else { + throw { fluenterror: 10 }; + } + + return this; + }; + + /** + Determine if the theme supports the specified output format. + */ + JRSTheme.prototype.hasFormat = function( fmt ) { + return _.has( this.formats, fmt ); + }; + + /** + Determine if the theme supports the specified output format. + */ + JRSTheme.prototype.getFormat = function( fmt ) { + return this.formats[ fmt ]; + }; + + module.exports = JRSTheme; + +}()); diff --git a/src/core/status-codes.js b/src/core/status-codes.js index d0467c7..400467f 100644 --- a/src/core/status-codes.js +++ b/src/core/status-codes.js @@ -1,6 +1,7 @@ /** Status codes for HackMyResume. @module status-codes.js +@license MIT. See LICENSE.MD for details. */ (function(){ @@ -15,7 +16,8 @@ Status codes for HackMyResume. resumeNotFoundAlt: 6, inputOutputParity: 7, createNameMissing: 8, - wkhtmltopdf: 9 + wkhtmltopdf: 9, + missingPackageJSON: 10 }; }());