Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/partials-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var path = require('path');
var _ = require('lodash');
var fsHelper = require('fs-helper');

// Log instead of printing directly to console
const debug = require('debug')('print-loader:lib:partials-loader'); // eslint-disable-line no-console

/** @param { String } library_name
* Used as a constant so debugging is simple
*/
Expand All @@ -16,13 +19,13 @@ var library_name = 'partial-loader';
* the call to this function the template engine that was used should have the partials that exist in the
* directories provided registered and ready for use. The idea is that the template_root_directories indicate
* the top level folder to parse through for a directory whose name exists in the partials_directory_names. If
* a directory name is found under the template directory and it exists in the partials_directory_names, then
* a directory name is found under the template directory and it exists in the partials_directory_names, then
* the loader iterates in a recursive fashion from the partials directory down, registering each file that has an
* extension that is found in the template_extensions. ]
* @param { Object } options [ This is a container object for the partials-loader to use. ]
* @param { Object } options.engine_reference [ This is the template engine that the partials files found will be registered with. ]
* @param { String or Array of Strings } options.template_root_directories [ These are the template root directories that will be recursively searched through. ]
* @param { String or Array of Strings } options.partials_directory_names [ These are the directory names that will be matched against in order to identify a directory to recurse through for loading partials files. SPECIAL CHARACTERS: if the character '.' is passed in, this will indicate to the partials loader that the template directory itself should be loaded as a partials directory. If it is passed in with an array of other strings the '.' will take precedence and will just iterate from the template directory down and
* @param { String or Array of Strings } options.partials_directory_names [ These are the directory names that will be matched against in order to identify a directory to recurse through for loading partials files. SPECIAL CHARACTERS: if the character '.' is passed in, this will indicate to the partials loader that the template directory itself should be loaded as a partials directory. If it is passed in with an array of other strings the '.' will take precedence and will just iterate from the template directory down and
* @param { String OR Array of Strings } options.template_extensions [ These are the extensions of the template files to load. ]
* @param { String } options.delimiter_symbol [ This is the delimiter used for namespacing, when files are loaded their directories are separated by this value. ]
* @return { undefined } [ This returns nothing. ]
Expand Down Expand Up @@ -51,8 +54,8 @@ exports.handlebars = function(options) {
}
}

/** loadPartials
* [ This function is responsible for taking all the formatted data pointing to all the partials and recurseive
/** loadPartials
* [ This function is responsible for taking all the formatted data pointing to all the partials and recurseive
* directories, and using that information to load the partial files into the template engine.]
* @param { Object } template_engine_reference [ This is the object reference to the template engine that is loading the the partials ]
* @param { String } root_directory [ This is the root directory that is being loaded from. ]
Expand All @@ -75,10 +78,10 @@ var loadPartials = function(template_engine_reference, root_directory, current_d
var partial_name_space = fsHelper.getDirDifference(root_directory, fullPath);
partial_name_space = partial_name_space.replace(/\\/g, delimiter_symbol);

console.log('Loading Partial into Handlebars engine.');
console.log('\tPartial Name Space: ' + partial_name_space);
console.log('\tFull Path to NameSpace: ' + fullPath);
console.log('-----------------------------------------');
debug('Loading Partial into Handlebars engine.');
debug('\tPartial Name Space: ' + partial_name_space);
debug('\tFull Path to NameSpace: ' + fullPath);
debug('-----------------------------------------');

template_engine_reference.registerPartial(partial_name_space, template);
}
Expand Down Expand Up @@ -187,4 +190,4 @@ var validateTemplateExtensions = function(template_extensions) {
new Error('The template extensions passed into the ' + library_name + ' function are not an ARRAY or STRING type. Please fix this.')
}
return template_extensions;
}
}
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"homepage": "https://github.com/Bill4Time/partials-loader",
"dependencies": {
"debug": "^3.1.0",
"fs-helper": "^0.1.0",
"lodash": "^2.4.1"
},
Expand Down