vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.7 KiB

  1. /*==============================================================================
  2. Demo template, showing how documentation can be generated for `vis.js`.
  3. ------------------------------------------------------------------------------
  4. ## Notes on `jsdoc` code
  5. // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
  6. // doesn't try to hand them out later
  7. indexUrl = helper.getUniqueFilename('index');
  8. // don't call registerLink() on this one! 'index' is also a valid longname
  9. globalUrl = helper.getUniqueFilename('global');
  10. helper.registerLink('global', globalUrl);
  11. ============================================================================== */
  12. 'use strict';
  13. //var taffy = require('taffydb').taffy; // not really required here, left for reference
  14. // Internal modules of `jsdoc` are available here.
  15. // This is not the complete list, there may be more useful stuff in jsdoc
  16. // For all modules scan in: '/usr/lib/node_modules/jsdoc/lib/jsdoc/' (or similar on your system)
  17. var fs = require('jsdoc/fs');
  18. var path = require('jsdoc/path');
  19. var template = require('jsdoc/template');
  20. /**
  21. * Set up the template rendering engine.
  22. */
  23. function createRenderer(fromDir, data) {
  24. var renderer = new template.Template(fromDir); // Param is the template source directory.
  25. // All template files are relative to this directory!
  26. /**
  27. * Example helper method
  28. *
  29. * This can be called from within a template as follows:
  30. *
  31. * ```
  32. * <?js
  33. * var self = this;
  34. * ?>
  35. * ...
  36. * <?js= self.helper('hello!') ?>
  37. * ```
  38. *
  39. * /
  40. renderer.helper = function(val) {
  41. return 'this is a helper! ' + val;
  42. };
  43. */
  44. /**
  45. * Retrieves jsdoc info for the passed instance method.
  46. */
  47. renderer.getComment = function(methodName) {
  48. var tmp = data().filter({longname: methodName}).get()[0];
  49. //console.log(JSON.stringify(tmp));
  50. // Some restructuring, to adapt it to the docs layout
  51. // This needs some work to make it handle 0 and > 1 parameters
  52. var param = tmp.params[0];
  53. var prototype = tmp.name + '(<code>' + param.type.names.join('|') + ' ' + param.name + '</code>)';
  54. var returns = tmp.returns[0].type.names;
  55. return {
  56. prototype: prototype,
  57. returns: returns,
  58. description: tmp.description
  59. }
  60. };
  61. return renderer;
  62. }
  63. /**
  64. Entry point for the template.
  65. This is called from `jsdoc` during execution
  66. @param {TAFFY} taffyData See <http://taffydb.com/>.
  67. @param {object} opts
  68. @param {Tutorial} tutorials
  69. */
  70. exports.publish = function(taffyData, opts, tutorials) {
  71. //console.log(JSON.stringify(opts, null, 2));
  72. var fromDir = path.resolve(opts.template);
  73. var toDir = path.join(opts.destination);
  74. var renderer = createRenderer(fromDir, taffyData);
  75. var docFiles = fs.ls(fromDir, 3);
  76. docFiles.forEach(function(fileName) {
  77. // Template filenames need to be relative to template source dir
  78. var relName = path.relative(fromDir, fileName);
  79. var outFile = path.join(toDir, relName);
  80. if (/publish.js$/.test(fileName)) return; // Skip self
  81. if (/README.md$/.test(fileName)) return; // Skip own README
  82. if (/\.tmpl$/.test(fileName)) return; // Skip .tmpl files; these are used as partials only
  83. if (!/\.html$/.test(fileName)) {
  84. // Just plain copy over non-html files
  85. var tmpDir = fs.toDir(outFile);
  86. fs.mkPath(tmpDir);
  87. fs.copyFileSync(fileName, tmpDir);
  88. return;
  89. }
  90. // Render html files as templates
  91. //console.log(relName);
  92. var html = renderer.partial(relName, {});
  93. fs.mkPath(fs.toDir(outFile));
  94. fs.writeFileSync(outFile, html, 'utf8');
  95. });
  96. //console.log(JSON.stringify(env, null, 2));
  97. };