Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4b7f6c
commit d080639
Showing
1 changed file
with
17 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); | ||
}; | ||
|
||
|