Skip to content

Commit

Permalink
use updated resolve-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jun 13, 2014
1 parent f4b7f6c commit d080639
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions lib/helpers.js
@@ -1,48 +1,32 @@
/**
* Assemble Helpers
* Assemble <http://assemble.io>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Upstage.
* Copyright (c) 2014, Jon Schlinkert, Brian Woodward, contributors.
* Licensed under the MIT License (MIT).
*/
'use strict';

// Node.js
var path = require('path');
var fs = require('fs');

// node_modules
var resolve = require('resolve-dep');
var grunt = require('grunt');
var _ = require('lodash');


module.exports.register = function(patterns, plugin, engine, options, params) {

// Resolve and load helpers from node_modules, if the helper name is listed both
// in the "helpers" option of the assemble task and devDependencies.
var resolvedFiles = resolve.loadDev(patterns) || [];
var grunt = require('grunt');

// Load local helpers defined in the "helpers" option of the assemble task.
var localFiles = grunt.file.expand(options, patterns) || [];

var files = _.union([], resolvedFiles, localFiles);
files.forEach(function(file) {
var helper = null;
module.exports.register = function(patterns, currentEngine, engineInstance, options, params) {
resolve(patterns).forEach(function(filepath) {
var fn = null;
try {
helper = require(path.normalize(path.join(options.cwd || process.cwd() || '', file)));
if(typeof helper !== 'undefined') {
if(typeof helper.register !== 'undefined') {
helper.register(engine, options, params);
} else {
plugin.registerFunctions(helper, options, params);
fn = require(path.resolve(filepath));
if(typeof fn !== 'undefined') {
if (typeof fn === 'object' && Object.keys(fn).length >= 1) {
if(typeof fn.register !== 'undefined') {
fn.register(engineInstance, options, params);
} else {
currentEngine.registerFunctions(fn, options, params);
}
}
}
} catch (ex) {
grunt.log.writeln('Error loading helpers from file: ' + file);
grunt.log.writeln(ex);
} catch (err) {
grunt.log.writeln('Error loading helpers from file: ' + filepath);
grunt.log.writeln(err);
}
});
};


0 comments on commit d080639

Please sign in to comment.