mustache-express.js
function loadAllPartials(unparsedPartials, partialsDirectory, partialsExtension, options, cache, partials, callback) {
	if (!partials) {
		partials = {};
	}

	// This function is called recursively. This is our base case: the point where we
	// don't call recursively anymore.
	// That point is when there are no partials that need to be parsed.
	if (unparsedPartials.length === 0) {
		return callback(null, partials);
	}

	async.map(unparsedPartials, function(partial, next) {
		var fullFilePath;
		if('function' === typeof partialsDirectory){
			fullFilePath = partialsDirectory(partial,partialsExtension);
		} else {
			fullFilePath = path.resolve(partialsDirectory, partial + partialsExtension);
		}
		return handleFile(partial, fullFilePath, options, cache, next);
	}, function(err, data) {
		if (err) {
			return callback(err);
		}

		// Add all of the data to the 'partials' object
		data.forEach(function(partialData) {
			partials[partialData.name] = partialData.data;
		});

		// Get all of the partials that are referenced by the data we've loaded
		var consolidatedPartials = consolidatePartials(data);

		// Get all of the partials that we haven't loaded yet.
		var partialsToLoad = findUnloadedPartials(consolidatedPartials, partials);

		// Recursive call.
		return loadAllPartials(partialsToLoad, partialsDirectory, partialsExtension, options, cache, partials, callback);
	});
}
function loadAllPartials(unparsedPartials, partialsDirectory, partialsExtension, options, cache, partials, callback) {
	if (!partials) {
		partials = {};
	}

	// This function is called recursively. This is our base case: the point where we
	// don't call recursively anymore.
	// That point is when there are no partials that need to be parsed.
	if (unparsedPartials.length === 0) {
		return callback(null, partials);
	}

	async.map(unparsedPartials, function(partial, next) {
		var fullFilePath;
		if('function' === typeof partialsDirectory){
			fullFilePath = partialsDirectory(partial,partialsExtension);
		} else {
			fullFilePath = path.resolve(partialsDirectory, partial + partialsExtension);
		}
		return handleFile(partial, fullFilePath, options, cache, next);
	}, function(err, data) {
		if (err) {
			return callback(err);
		}

		// Add all of the data to the 'partials' object
		data.forEach(function(partialData) {
			partials[partialData.name] = partialData.data;
		});

		// Get all of the partials that are referenced by the data we've loaded
		var consolidatedPartials = consolidatePartials(data);

		// Get all of the partials that we haven't loaded yet.
		var partialsToLoad = findUnloadedPartials(consolidatedPartials, partials);

		// Recursive call.
		return loadAllPartials(partialsToLoad, partialsDirectory, partialsExtension, options, cache, partials, callback);
	});
}
function loadAllPartials ( unparsedPartials , partialsDirectory , partialsExtension , options , cache , partials , callback ) { if ( ! partials ) { partials = { } ; } // This function is called recursively. This is our base case: the point where we // don't call recursively anymore. // That point is when there are no partials that need to be parsed. if ( unparsedPartials . length === 0 ) { return callback ( null , partials ) ; } async . map ( unparsedPartials , function ( partial , next ) { var fullFilePath ; if ( 'function' === typeof partialsDirectory ) { fullFilePath = partialsDirectory ( partial , partialsExtension ) ; } else { fullFilePath = path . resolve ( partialsDirectory , partial + partialsExtension ) ; } return handleFile ( partial , fullFilePath , options , cache , next ) ; } , function ( err , data ) { if ( err ) { return callback ( err ) ; } // Add all of the data to the 'partials' object data . forEach ( function ( partialData ) { partials [ partialData . name ] = partialData . data ; } ) ; // Get all of the partials that are referenced by the data we've loaded var consolidatedPartials = consolidatePartials ( data ) ; // Get all of the partials that we haven't loaded yet. var partialsToLoad = findUnloadedPartials ( consolidatedPartials , partials ) ; // Recursive call. return loadAllPartials ( partialsToLoad , partialsDirectory , partialsExtension , options , cache , partials , callback ) ; } ) ; }
Load all of the partials recursively
Load all of the partials recursively