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.

140 lines
4.3 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. if (tmp === undefined) {
  50. throw new Error('Could not find jsdoc for: ' + methodName);
  51. }
  52. // NOTE: Following does not show up with `gulp docs`, need to do call directly
  53. // console.log(JSON.stringify(tmp, null, 2));
  54. // Some restructuring, to adapt it to the docs layout
  55. // This needs some work to make it handle 0 and > 1 parameters
  56. var paramText = "";
  57. if (tmp.params !== undefined && tmp.params.length > 0) {
  58. let param = tmp.params[0];
  59. let tmpText = param.type.names.join('|') + ' ' + param.name;
  60. if (param.optional === true) {
  61. tmpText = '[' + tmpText + ']';
  62. }
  63. paramText = '<code>' + tmpText + '</code>';
  64. }
  65. var prototype = tmp.name + '(' + paramText + ')';
  66. var returns = 'none';
  67. if (tmp.returns !== undefined && tmp.returns.length > 0) {
  68. let name = tmp.returns[0].type.names[0];
  69. if (name !== "undefined") {
  70. returns = name;
  71. }
  72. }
  73. return {
  74. name: tmp.name,
  75. prototype: prototype,
  76. returns: returns,
  77. description: tmp.description
  78. }
  79. };
  80. return renderer;
  81. }
  82. /**
  83. Entry point for the template.
  84. This is called from `jsdoc` during execution
  85. @param {TAFFY} taffyData See <http://taffydb.com/>.
  86. @param {object} opts
  87. @param {Tutorial} tutorials
  88. */
  89. exports.publish = function(taffyData, opts, tutorials) {
  90. //console.log(JSON.stringify(opts, null, 2));
  91. var fromDir = path.resolve(opts.template);
  92. var toDir = path.join(opts.destination);
  93. var renderer = createRenderer(fromDir, taffyData);
  94. var docFiles = fs.ls(fromDir, 3);
  95. docFiles.forEach(function(fileName) {
  96. // Template filenames need to be relative to template source dir
  97. var relName = path.relative(fromDir, fileName);
  98. var outFile = path.join(toDir, relName);
  99. if (/publish.js$/.test(fileName)) return; // Skip self
  100. if (/README.md$/.test(fileName)) return; // Skip own README
  101. if (/\.tmpl$/.test(fileName)) return; // Skip .tmpl files; these are used as partials only
  102. if (!/\.html$/.test(fileName)) {
  103. // Just plain copy over non-html files
  104. var tmpDir = fs.toDir(outFile);
  105. fs.mkPath(tmpDir);
  106. fs.copyFileSync(fileName, tmpDir);
  107. return;
  108. }
  109. // Render html files as templates
  110. //console.log(relName);
  111. var html = renderer.partial(relName, {});
  112. fs.mkPath(fs.toDir(outFile));
  113. fs.writeFileSync(outFile, html, 'utf8');
  114. });
  115. //console.log(JSON.stringify(env, null, 2));
  116. };