jsdoc/plugins/partial.js
Jeff Williams ae94af0cd8 turn env global into a module, and use the module instead of the global (#812)
The `env` global remains available, since templates and plugins may rely upon it, but it's deprecated as of JSDoc 3.4.0.
2015-02-17 19:07:10 -08:00

33 lines
805 B
JavaScript

/**
@overview Adds support for reusable partial jsdoc files.
@module plugins/partial
@author Ludo Antonov <ludo@hulu.com>
*/
'use strict';
var env = require('jsdoc/env');
var fs = require('jsdoc/fs');
var path = require('path');
exports.handlers = {
/**
* Include a partial jsdoc
*
* @param e
* @param e.filename
* @param e.source
* @example
* @partial "partial_doc.jsdoc"
*/
beforeParse: function(e) {
e.source = e.source.replace(/(@partial \".*\")+/g, function($) {
var pathArg = $.match(/\".*\"/)[0].replace(/"/g, '');
var fullPath = path.join(e.filename, '..', pathArg);
var partialData = fs.readFileSync(fullPath, env.opts.encoding);
return partialData;
});
}
};