partial.js 751 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Adds support for reusable partial jsdoc files.
  3. *
  4. * @module plugins/partial
  5. */
  6. 'use strict';
  7. var env = require('jsdoc/env');
  8. var fs = require('jsdoc/fs');
  9. var path = require('path');
  10. exports.handlers = {
  11. /**
  12. * Include a partial jsdoc
  13. *
  14. * @param e
  15. * @param e.filename
  16. * @param e.source
  17. * @example
  18. * @partial "partial_doc.jsdoc"
  19. */
  20. beforeParse: function(e) {
  21. e.source = e.source.replace(/(@partial ".*")+/g, function($) {
  22. var pathArg = $.match(/".*"/)[0].replace(/"/g, '');
  23. var fullPath = path.join(e.filename, '..', pathArg);
  24. var partialData = fs.readFileSync(fullPath, env.opts.encoding);
  25. return partialData;
  26. });
  27. }
  28. };