2016-01-27 10:29:26 +00:00
|
|
|
(function() {
|
2018-02-12 05:05:29 +00:00
|
|
|
/**
|
|
|
|
Definition of the JRSTheme class.
|
|
|
|
@module core/jrs-theme
|
|
|
|
@license MIT. See LICENSE.MD for details.
|
|
|
|
*/
|
2018-02-02 00:22:17 +00:00
|
|
|
var JRSTheme, PATH, _, errors, parsePath, pathExists;
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
_ = require('underscore');
|
|
|
|
|
|
|
|
PATH = require('path');
|
|
|
|
|
|
|
|
parsePath = require('parse-filepath');
|
|
|
|
|
|
|
|
pathExists = require('path-exists').sync;
|
|
|
|
|
2018-02-02 00:22:17 +00:00
|
|
|
errors = require('./status-codes');
|
|
|
|
|
2016-01-27 10:29:26 +00:00
|
|
|
/**
|
|
|
|
The JRSTheme class is a representation of a JSON Resume theme asset.
|
|
|
|
@class JRSTheme
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
JRSTheme = class JRSTheme {
|
2016-01-27 10:29:26 +00:00
|
|
|
/**
|
2018-02-02 00:22:17 +00:00
|
|
|
Open and parse the specified JRS theme.
|
2016-01-27 10:29:26 +00:00
|
|
|
@method open
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
open(thFolder) {
|
2016-01-27 10:29:26 +00:00
|
|
|
var pathInfo, pkgJsonPath, thApi, thPkg;
|
|
|
|
this.folder = thFolder;
|
|
|
|
pathInfo = parsePath(thFolder);
|
2018-02-12 05:05:29 +00:00
|
|
|
// Open and parse the theme's package.json file
|
2016-01-27 10:29:26 +00:00
|
|
|
pkgJsonPath = PATH.join(thFolder, 'package.json');
|
|
|
|
if (pathExists(pkgJsonPath)) {
|
2018-02-12 05:05:29 +00:00
|
|
|
thApi = require(thFolder); // Requiring the folder yields whatever the package.json's "main" is set to
|
|
|
|
thPkg = require(pkgJsonPath); // Get the package.json as JSON
|
2016-01-27 10:29:26 +00:00
|
|
|
this.name = thPkg.name;
|
|
|
|
this.render = (thApi && thApi.render) || void 0;
|
|
|
|
this.engine = 'jrs';
|
2018-02-12 05:05:29 +00:00
|
|
|
// Create theme formats (HTML and PDF). Just add the bare minimum mix of
|
|
|
|
// properties necessary to allow JSON Resume themes to share a rendering
|
|
|
|
// path with FRESH themes.
|
2016-01-27 10:29:26 +00:00
|
|
|
this.formats = {
|
|
|
|
html: {
|
|
|
|
outFormat: 'html',
|
|
|
|
files: [
|
|
|
|
{
|
|
|
|
action: 'transform',
|
|
|
|
render: this.render,
|
2016-02-13 21:08:45 +00:00
|
|
|
primary: true,
|
2016-01-27 10:29:26 +00:00
|
|
|
ext: 'html',
|
|
|
|
css: null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
pdf: {
|
|
|
|
outFormat: 'pdf',
|
|
|
|
files: [
|
|
|
|
{
|
|
|
|
action: 'transform',
|
|
|
|
render: this.render,
|
2016-02-13 21:08:45 +00:00
|
|
|
primary: true,
|
2016-01-27 10:29:26 +00:00
|
|
|
ext: 'pdf',
|
|
|
|
css: null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
throw {
|
2018-02-02 00:22:17 +00:00
|
|
|
fluenterror: errors.missingPackageJSON
|
2016-01-27 10:29:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return this;
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Determine if the theme supports the output format.
|
|
|
|
@method hasFormat
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
hasFormat(fmt) {
|
2016-01-27 10:29:26 +00:00
|
|
|
return _.has(this.formats, fmt);
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the requested output format.
|
|
|
|
@method getFormat
|
2018-02-12 05:05:29 +00:00
|
|
|
*/
|
|
|
|
getFormat(fmt) {
|
2016-01-30 16:31:39 +00:00
|
|
|
return this.formats[fmt];
|
2018-02-12 05:05:29 +00:00
|
|
|
}
|
2016-01-30 16:31:39 +00:00
|
|
|
|
2018-02-12 05:05:29 +00:00
|
|
|
};
|
2016-01-27 10:29:26 +00:00
|
|
|
|
|
|
|
module.exports = JRSTheme;
|
|
|
|
|
|
|
|
}).call(this);
|
2016-02-02 02:14:36 +00:00
|
|
|
|
|
|
|
//# sourceMappingURL=jrs-theme.js.map
|