mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 01:56:21 +00:00
feat: support custom theme helpers
This commit is contained in:
parent
7f656175f0
commit
069506e86d
6
dist/cli/error.js
vendored
6
dist/cli/error.js
vendored
@ -61,7 +61,7 @@ Error-handling routines for HackMyResume.
|
|||||||
stack = ex.stack || (ex.inner && ex.inner.stack);
|
stack = ex.stack || (ex.inner && ex.inner.stack);
|
||||||
stack && o(chalk.gray(stack));
|
stack && o(chalk.gray(stack));
|
||||||
}
|
}
|
||||||
if (shouldExit) {
|
if (shouldExit || ex.exit) {
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
o(chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
o(chalk.cyan('Exiting with error code ' + ex.fluenterror.toString()));
|
||||||
}
|
}
|
||||||
@ -262,6 +262,10 @@ Error-handling routines for HackMyResume.
|
|||||||
case HMSTATUS.unknownSchema:
|
case HMSTATUS.unknownSchema:
|
||||||
msg = M2C(this.msgs.unknownSchema.msg[0]);
|
msg = M2C(this.msgs.unknownSchema.msg[0]);
|
||||||
etype = 'error';
|
etype = 'error';
|
||||||
|
break;
|
||||||
|
case HMSTATUS.themeHelperLoad:
|
||||||
|
msg = printf(M2C(this.msgs.themeHelperLoad.msg), ex.glob);
|
||||||
|
etype = 'error';
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
msg: msg,
|
msg: msg,
|
||||||
|
5
dist/cli/msg.yml
vendored
5
dist/cli/msg.yml
vendored
@ -132,3 +132,8 @@ errors:
|
|||||||
"basics": {
|
"basics": {
|
||||||
"name": "John Doe"
|
"name": "John Doe"
|
||||||
}
|
}
|
||||||
|
themeHelperLoad:
|
||||||
|
msg: >-
|
||||||
|
An error occurred while attempting to load the '%s' theme helper. Is the
|
||||||
|
theme correctly installed?
|
||||||
|
dummy: dontcare
|
||||||
|
3
dist/core/status-codes.js
vendored
3
dist/core/status-codes.js
vendored
@ -36,7 +36,8 @@ Status codes for HackMyResume.
|
|||||||
validateError: 26,
|
validateError: 26,
|
||||||
invalidOptionsFile: 27,
|
invalidOptionsFile: 27,
|
||||||
optionsFileNotFound: 28,
|
optionsFileNotFound: 28,
|
||||||
unknownSchema: 29
|
unknownSchema: 29,
|
||||||
|
themeHelperLoad: 30
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
39
dist/helpers/handlebars-helpers.js
vendored
39
dist/helpers/handlebars-helpers.js
vendored
@ -6,7 +6,7 @@ Template helper definitions for Handlebars.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var HANDLEBARS, _, blockHelpers, helpers;
|
var HANDLEBARS, HMS, _, blockHelpers, helpers, path;
|
||||||
|
|
||||||
HANDLEBARS = require('handlebars');
|
HANDLEBARS = require('handlebars');
|
||||||
|
|
||||||
@ -14,8 +14,12 @@ Template helper definitions for Handlebars.
|
|||||||
|
|
||||||
helpers = require('./generic-helpers');
|
helpers = require('./generic-helpers');
|
||||||
|
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
blockHelpers = require('./block-helpers');
|
blockHelpers = require('./block-helpers');
|
||||||
|
|
||||||
|
HMS = require('../core/status-codes');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Register useful Handlebars helpers.
|
Register useful Handlebars helpers.
|
||||||
@ -23,7 +27,7 @@ Template helper definitions for Handlebars.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function(theme, opts) {
|
module.exports = function(theme, opts) {
|
||||||
var i, len, ref, themeHelpers, wrappedHelpers;
|
var curGlob, ex, glob, wrappedHelpers;
|
||||||
helpers.theme = theme;
|
helpers.theme = theme;
|
||||||
helpers.opts = opts;
|
helpers.opts = opts;
|
||||||
helpers.type = 'handlebars';
|
helpers.type = 'handlebars';
|
||||||
@ -41,10 +45,33 @@ Template helper definitions for Handlebars.
|
|||||||
}, this);
|
}, this);
|
||||||
HANDLEBARS.registerHelper(wrappedHelpers);
|
HANDLEBARS.registerHelper(wrappedHelpers);
|
||||||
HANDLEBARS.registerHelper(blockHelpers);
|
HANDLEBARS.registerHelper(blockHelpers);
|
||||||
ref = theme.jsFiles;
|
if (_.isString(theme.helpers)) {
|
||||||
for (i = 0, len = ref.length; i < len; i++) {
|
theme.helpers = [theme.helpers];
|
||||||
themeHelpers = ref[i];
|
}
|
||||||
HANDLEBARS.registerHelper(require(themeHelpers));
|
if (_.isArray(theme.helpers)) {
|
||||||
|
glob = require('glob');
|
||||||
|
curGlob = null;
|
||||||
|
try {
|
||||||
|
_.each(theme.helpers, function(fGlob) {
|
||||||
|
curGlob = fGlob;
|
||||||
|
fGlob = path.join(theme.folder, fGlob);
|
||||||
|
glob(fGlob, {}, function(er, files) {
|
||||||
|
if (er === null && files.length > 0) {
|
||||||
|
_.each(files, function(f) {
|
||||||
|
HANDLEBARS.registerHelper(require(f));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (_error) {
|
||||||
|
ex = _error;
|
||||||
|
throw {
|
||||||
|
fluenterror: HMS.themeHelperLoad,
|
||||||
|
inner: ex,
|
||||||
|
glob: curGlob,
|
||||||
|
exit: true
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ ErrorHandler = module.exports =
|
|||||||
stack && o( chalk.gray( stack ) );
|
stack && o( chalk.gray( stack ) );
|
||||||
|
|
||||||
# Quit if necessary
|
# Quit if necessary
|
||||||
if shouldExit
|
if shouldExit or ex.exit
|
||||||
if @debug
|
if @debug
|
||||||
o chalk.cyan('Exiting with error code ' + ex.fluenterror.toString())
|
o chalk.cyan('Exiting with error code ' + ex.fluenterror.toString())
|
||||||
if @assert
|
if @assert
|
||||||
@ -253,6 +253,11 @@ assembleError = ( ex ) ->
|
|||||||
#msg += "\n" + M2C( @msgs.unknownSchema.msg[1], 'yellow' )
|
#msg += "\n" + M2C( @msgs.unknownSchema.msg[1], 'yellow' )
|
||||||
etype = 'error'
|
etype = 'error'
|
||||||
|
|
||||||
|
when HMSTATUS.themeHelperLoad
|
||||||
|
msg = printf M2C( @msgs.themeHelperLoad.msg ), ex.glob
|
||||||
|
etype = 'error'
|
||||||
|
|
||||||
|
|
||||||
msg: msg # The error message to display
|
msg: msg # The error message to display
|
||||||
withStack: withStack # Whether to include the stack
|
withStack: withStack # Whether to include the stack
|
||||||
quit: quit
|
quit: quit
|
||||||
|
@ -132,3 +132,8 @@ errors:
|
|||||||
"basics": {
|
"basics": {
|
||||||
"name": "John Doe"
|
"name": "John Doe"
|
||||||
}
|
}
|
||||||
|
themeHelperLoad:
|
||||||
|
msg: >-
|
||||||
|
An error occurred while attempting to load the '%s' theme helper. Is the
|
||||||
|
theme correctly installed?
|
||||||
|
dummy: dontcare
|
||||||
|
@ -36,3 +36,4 @@ module.exports =
|
|||||||
invalidOptionsFile: 27
|
invalidOptionsFile: 27
|
||||||
optionsFileNotFound: 28
|
optionsFileNotFound: 28
|
||||||
unknownSchema: 29
|
unknownSchema: 29
|
||||||
|
themeHelperLoad: 30
|
||||||
|
@ -8,7 +8,9 @@ Template helper definitions for Handlebars.
|
|||||||
HANDLEBARS = require 'handlebars'
|
HANDLEBARS = require 'handlebars'
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
helpers = require './generic-helpers'
|
helpers = require './generic-helpers'
|
||||||
|
path = require 'path'
|
||||||
blockHelpers = require './block-helpers'
|
blockHelpers = require './block-helpers'
|
||||||
|
HMS = require '../core/status-codes'
|
||||||
|
|
||||||
###*
|
###*
|
||||||
Register useful Handlebars helpers.
|
Register useful Handlebars helpers.
|
||||||
@ -33,6 +35,32 @@ module.exports = ( theme, opts ) ->
|
|||||||
|
|
||||||
HANDLEBARS.registerHelper wrappedHelpers
|
HANDLEBARS.registerHelper wrappedHelpers
|
||||||
HANDLEBARS.registerHelper blockHelpers
|
HANDLEBARS.registerHelper blockHelpers
|
||||||
for themeHelpers in theme.jsFiles
|
|
||||||
HANDLEBARS.registerHelper require themeHelpers
|
# Register any theme-provided custom helpers...
|
||||||
return
|
|
||||||
|
# Normalize "theme.helpers" (string or array) to an array
|
||||||
|
theme.helpers = [ theme.helpers ] if _.isString theme.helpers
|
||||||
|
|
||||||
|
if _.isArray theme.helpers
|
||||||
|
glob = require 'glob'
|
||||||
|
curGlob = null
|
||||||
|
try
|
||||||
|
_.each theme.helpers, (fGlob) -> # foreach theme.helpers entry
|
||||||
|
curGlob = fGlob # cache in case of exception
|
||||||
|
fGlob = path.join theme.folder, fGlob # make relative to theme
|
||||||
|
glob fGlob, { }, (er, files) -> # expand the glob to paths
|
||||||
|
if er is null and files.length > 0 # guard against the error
|
||||||
|
_.each files, (f) -> # loop over concrete paths
|
||||||
|
HANDLEBARS.registerHelper require f # register the path
|
||||||
|
return
|
||||||
|
# else if er # glob error occurred
|
||||||
|
# throw fluenterror: HMS.themeHelperLoad, inner: er, glob: fGlob
|
||||||
|
# else if files.length < 1 # glob returned no results
|
||||||
|
# throw fluenterror: HMS.themeHelperLoad
|
||||||
|
return
|
||||||
|
return
|
||||||
|
return
|
||||||
|
catch ex
|
||||||
|
# If a non-path is passed to glob() it will throw an error
|
||||||
|
throw fluenterror: HMS.themeHelperLoad, inner: ex, glob: curGlob, exit: true
|
||||||
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user