mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 01:56:21 +00:00
feat: improve custom theme helper registration
This commit is contained in:
parent
9c096541ce
commit
1dbb78c53f
15
dist/helpers/handlebars-helpers.js
vendored
15
dist/helpers/handlebars-helpers.js
vendored
@ -27,7 +27,7 @@ Template helper definitions for Handlebars.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = function(theme, opts) {
|
module.exports = function(theme, opts) {
|
||||||
var curGlob, ex, glob, wrappedHelpers;
|
var curGlob, ex, glob, slash, wrappedHelpers;
|
||||||
helpers.theme = theme;
|
helpers.theme = theme;
|
||||||
helpers.opts = opts;
|
helpers.opts = opts;
|
||||||
helpers.type = 'handlebars';
|
helpers.type = 'handlebars';
|
||||||
@ -50,19 +50,26 @@ Template helper definitions for Handlebars.
|
|||||||
}
|
}
|
||||||
if (_.isArray(theme.helpers)) {
|
if (_.isArray(theme.helpers)) {
|
||||||
glob = require('glob');
|
glob = require('glob');
|
||||||
|
slash = require('slash');
|
||||||
curGlob = null;
|
curGlob = null;
|
||||||
try {
|
try {
|
||||||
_.each(theme.helpers, function(fGlob) {
|
_.each(theme.helpers, function(fGlob) {
|
||||||
|
var files;
|
||||||
curGlob = fGlob;
|
curGlob = fGlob;
|
||||||
fGlob = path.join(theme.folder, fGlob);
|
fGlob = path.join(theme.folder, fGlob);
|
||||||
glob(fGlob, {}, function(er, files) {
|
files = glob.sync(slash(fGlob));
|
||||||
if (er === null && files.length > 0) {
|
if (files.length > 0) {
|
||||||
_.each(files, function(f) {
|
_.each(files, function(f) {
|
||||||
HANDLEBARS.registerHelper(require(f));
|
HANDLEBARS.registerHelper(require(f));
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
throw {
|
||||||
|
fluenterror: HMS.themeHelperLoad,
|
||||||
|
inner: er,
|
||||||
|
glob: fGlob
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
ex = _error;
|
ex = _error;
|
||||||
throw {
|
throw {
|
||||||
|
@ -43,24 +43,24 @@ module.exports = ( theme, opts ) ->
|
|||||||
|
|
||||||
if _.isArray theme.helpers
|
if _.isArray theme.helpers
|
||||||
glob = require 'glob'
|
glob = require 'glob'
|
||||||
|
slash = require 'slash'
|
||||||
curGlob = null
|
curGlob = null
|
||||||
try
|
try
|
||||||
_.each theme.helpers, (fGlob) -> # foreach theme.helpers entry
|
_.each theme.helpers, (fGlob) -> # foreach theme.helpers entry
|
||||||
curGlob = fGlob # cache in case of exception
|
curGlob = fGlob # ..cache in case of exception
|
||||||
fGlob = path.join theme.folder, fGlob # make relative to theme
|
fGlob = path.join theme.folder, fGlob # ..make relative to theme
|
||||||
glob fGlob, { }, (er, files) -> # expand the glob to paths
|
files = glob.sync slash fGlob # ..expand the glob
|
||||||
if er is null and files.length > 0 # guard against the error
|
if files.length > 0 # ..guard against empty glob
|
||||||
_.each files, (f) -> # loop over concrete paths
|
_.each files, (f) -> # ..loop over concrete paths
|
||||||
HANDLEBARS.registerHelper require f # register the path
|
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
|
||||||
|
else
|
||||||
|
throw fluenterror: HMS.themeHelperLoad, inner: er, glob: fGlob
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
catch ex
|
catch ex
|
||||||
# If a non-path is passed to glob() it will throw an error
|
throw
|
||||||
throw fluenterror: HMS.themeHelperLoad, inner: ex, glob: curGlob, exit: true
|
fluenterror: HMS.themeHelperLoad
|
||||||
|
inner: ex
|
||||||
|
glob: curGlob, exit: true
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user