mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-03 04:47:07 +01:00
Gather.
This commit is contained in:
167
dist/core/fresh-theme.js
vendored
167
dist/core/fresh-theme.js
vendored
@ -6,7 +6,7 @@ Definition of the FRESHTheme class.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var EXTEND, FRESHTheme, FS, HMSTATUS, PATH, READFILES, _, _load, friendlyName, loadSafeJson, moment, parsePath, pathExists, validator;
|
||||
var EXTEND, FRESHTheme, FS, HMSTATUS, PATH, READFILES, _, _load, _loadOne, friendlyName, loadSafeJson, moment, parsePath, pathExists, validator;
|
||||
|
||||
FS = require('fs');
|
||||
|
||||
@ -31,9 +31,7 @@ Definition of the FRESHTheme class.
|
||||
READFILES = require('recursive-readdir-sync');
|
||||
|
||||
|
||||
/*
|
||||
The FRESHTheme class is a representation of a FRESH theme
|
||||
asset. See also: JRSTheme.
|
||||
/* A representation of a FRESH theme asset.
|
||||
@class FRESHTheme
|
||||
*/
|
||||
|
||||
@ -41,9 +39,7 @@ Definition of the FRESHTheme class.
|
||||
function FRESHTheme() {}
|
||||
|
||||
|
||||
/*
|
||||
Open and parse the specified theme.
|
||||
*/
|
||||
/* Open and parse the specified theme. */
|
||||
|
||||
FRESHTheme.prototype.open = function(themeFolder) {
|
||||
var cached, formatsHash, pathInfo, that, themeFile, themeInfo;
|
||||
@ -96,9 +92,7 @@ Definition of the FRESHTheme class.
|
||||
})();
|
||||
|
||||
|
||||
/* Load the theme implicitly, by scanning the theme folder for files. TODO:
|
||||
Refactor duplicated code with loadExplicit.
|
||||
*/
|
||||
/* Load and parse theme source files. */
|
||||
|
||||
_load = function(formatsHash) {
|
||||
var copyOnly, fmts, major, that, tplFolder;
|
||||
@ -107,74 +101,8 @@ Definition of the FRESHTheme class.
|
||||
tplFolder = PATH.join(this.folder, 'src');
|
||||
copyOnly = ['.ttf', '.otf', '.png', '.jpg', '.jpeg', '.pdf'];
|
||||
fmts = READFILES(tplFolder).map(function(absPath) {
|
||||
var absPathSafe, act, idx, isMajor, obj, outFmt, pathInfo, portion, ref, ref1, reg, res;
|
||||
pathInfo = parsePath(absPath);
|
||||
absPathSafe = absPath.trim().toLowerCase();
|
||||
outFmt = '';
|
||||
isMajor = false;
|
||||
if (that.formats) {
|
||||
outFmt = _.find(Object.keys(that.formats), function(fmtKey) {
|
||||
var fmtVal;
|
||||
fmtVal = that.formats[fmtKey];
|
||||
return _.some(fmtVal.transform, function(fpath) {
|
||||
var absPathB;
|
||||
absPathB = PATH.join(that.folder, fpath).trim().toLowerCase();
|
||||
return absPathB === absPathSafe;
|
||||
});
|
||||
});
|
||||
if (outFmt) {
|
||||
isMajor = true;
|
||||
}
|
||||
}
|
||||
if (!outFmt) {
|
||||
portion = pathInfo.dirname.replace(tplFolder, '');
|
||||
if (portion && portion.trim()) {
|
||||
if (portion[1] === '_') {
|
||||
return;
|
||||
}
|
||||
reg = /^(?:\/|\\)(html|latex|doc|pdf|png|partials)(?:\/|\\)?/ig;
|
||||
res = reg.exec(portion);
|
||||
if (res) {
|
||||
if (res[1] !== 'partials') {
|
||||
outFmt = res[1];
|
||||
} else {
|
||||
that.partials = that.partials || [];
|
||||
that.partials.push({
|
||||
name: pathInfo.name,
|
||||
path: absPath
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!outFmt) {
|
||||
idx = pathInfo.name.lastIndexOf('-');
|
||||
outFmt = idx === -1 ? pathInfo.name : pathInfo.name.substr(idx + 1);
|
||||
isMajor = true;
|
||||
}
|
||||
act = _.contains(copyOnly, pathInfo.extname) ? 'copy' : 'transform';
|
||||
formatsHash[outFmt] = formatsHash[outFmt] || {
|
||||
outFormat: outFmt,
|
||||
files: []
|
||||
};
|
||||
if ((ref = that.formats) != null ? (ref1 = ref[outFmt]) != null ? ref1.symLinks : void 0 : void 0) {
|
||||
formatsHash[outFmt].symLinks = that.formats[outFmt].symLinks;
|
||||
}
|
||||
obj = {
|
||||
action: act,
|
||||
path: absPath,
|
||||
major: isMajor,
|
||||
orgPath: PATH.relative(tplFolder, absPath),
|
||||
ext: pathInfo.extname.slice(1),
|
||||
title: friendlyName(outFmt),
|
||||
pre: outFmt,
|
||||
data: FS.readFileSync(absPath, 'utf8'),
|
||||
css: null
|
||||
};
|
||||
formatsHash[outFmt].files.push(obj);
|
||||
return obj;
|
||||
});
|
||||
return _loadOne.call(this, absPath, formatsHash, tplFolder);
|
||||
}, this);
|
||||
this.cssFiles = fmts.filter(function(fmt) {
|
||||
return fmt && (fmt.ext === 'css');
|
||||
});
|
||||
@ -200,14 +128,87 @@ Definition of the FRESHTheme class.
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Return a more friendly name for certain formats.
|
||||
TODO: Refactor
|
||||
*/
|
||||
/* Load a single theme file. */
|
||||
|
||||
_loadOne = function(absPath, formatsHash, tplFolder) {
|
||||
var absPathSafe, act, idx, obj, outFmt, pathInfo, portion, ref, ref1, reg, res, shouldTransform;
|
||||
pathInfo = parsePath(absPath);
|
||||
absPathSafe = absPath.trim().toLowerCase();
|
||||
outFmt = '';
|
||||
shouldTransform = false;
|
||||
if (this.explicit) {
|
||||
outFmt = _.find(Object.keys(this.formats), function(fmtKey) {
|
||||
var fmtVal;
|
||||
fmtVal = this.formats[fmtKey];
|
||||
return _.some(fmtVal.transform, function(fpath) {
|
||||
var absPathB;
|
||||
absPathB = PATH.join(this.folder, fpath).trim().toLowerCase();
|
||||
return absPathB === absPathSafe;
|
||||
}, this);
|
||||
}, this);
|
||||
if (outFmt) {
|
||||
act = 'transform';
|
||||
}
|
||||
}
|
||||
if (!outFmt) {
|
||||
portion = pathInfo.dirname.replace(tplFolder, '');
|
||||
if (portion && portion.trim()) {
|
||||
if (portion[1] === '_') {
|
||||
return;
|
||||
}
|
||||
reg = /^(?:\/|\\)(html|latex|doc|pdf|png|partials)(?:\/|\\)?/ig;
|
||||
res = reg.exec(portion);
|
||||
if (res) {
|
||||
if (res[1] !== 'partials') {
|
||||
outFmt = res[1];
|
||||
if (!this.explicit) {
|
||||
act = 'transform';
|
||||
}
|
||||
} else {
|
||||
this.partials = this.partials || [];
|
||||
this.partials.push({
|
||||
name: pathInfo.name,
|
||||
path: absPath
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!outFmt) {
|
||||
idx = pathInfo.name.lastIndexOf('-');
|
||||
outFmt = idx === -1 ? pathInfo.name : pathInfo.name.substr(idx + 1);
|
||||
if (!this.explicit) {
|
||||
act = 'transform';
|
||||
}
|
||||
}
|
||||
formatsHash[outFmt] = formatsHash[outFmt] || {
|
||||
outFormat: outFmt,
|
||||
files: []
|
||||
};
|
||||
if ((ref = this.formats) != null ? (ref1 = ref[outFmt]) != null ? ref1.symLinks : void 0 : void 0) {
|
||||
formatsHash[outFmt].symLinks = this.formats[outFmt].symLinks;
|
||||
}
|
||||
obj = {
|
||||
action: act,
|
||||
path: absPath,
|
||||
orgPath: PATH.relative(tplFolder, absPath),
|
||||
ext: pathInfo.extname.slice(1),
|
||||
title: friendlyName(outFmt),
|
||||
pre: outFmt,
|
||||
data: FS.readFileSync(absPath, 'utf8'),
|
||||
css: null
|
||||
};
|
||||
formatsHash[outFmt].files.push(obj);
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/* Return a more friendly name for certain formats. */
|
||||
|
||||
friendlyName = function(val) {
|
||||
var friendly;
|
||||
val = val.trim().toLowerCase();
|
||||
val = (val && val.trim().toLowerCase()) || '';
|
||||
friendly = {
|
||||
yml: 'yaml',
|
||||
md: 'markdown',
|
||||
|
Reference in New Issue
Block a user