mirror of
https://github.com/nasa/openmct.git
synced 2025-01-18 02:39:56 +00:00
[Documentation] Begin adding doc generator
Begin adding Markdown->HTML documentation generation with nomnoml embedded diagram support. MissionControl/vista#21
This commit is contained in:
parent
0b3170d2ef
commit
ad482600de
109
docsrc/gendocs.js
Normal file
109
docsrc/gendocs.js
Normal file
@ -0,0 +1,109 @@
|
||||
/*global require,process,GLOBAL*/
|
||||
/*jslint nomen: true*/
|
||||
|
||||
|
||||
var CONSTANTS = {
|
||||
DIAGRAM_WIDTH: 800,
|
||||
DIAGRAM_HEIGHT: 500
|
||||
};
|
||||
|
||||
GLOBAL.window = GLOBAL.window || {}; // nomnoml expects window to be defined
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var fs = require("fs"),
|
||||
mkdirp = require("mkdirp"),
|
||||
path = require("path"),
|
||||
glob = require("glob"),
|
||||
showdown = require("github-flavored-markdown"),
|
||||
split = require("split"),
|
||||
stream = require("stream"),
|
||||
nomnoml = require('nomnoml'),
|
||||
Canvas = require('canvas'),
|
||||
options = require("minimist")(process.argv.slice(2));
|
||||
|
||||
function renderNomnoml(source, target) {
|
||||
var canvas =
|
||||
new Canvas(CONSTANTS.DIAGRAM_WIDTH, CONSTANTS.DIAGRAM_HEIGHT);
|
||||
nomnoml.draw(canvas, source, 1.0);
|
||||
canvas.pngStream().pipe(fs.createWriteStream(target));
|
||||
}
|
||||
|
||||
function nomnomlifier(outputDirectory, prefix) {
|
||||
var transform = new stream.Transform({ objectMode: true }),
|
||||
isBuilding = false,
|
||||
counter = 1,
|
||||
outputPath,
|
||||
source = "";
|
||||
|
||||
transform._transform = function (chunk, encoding, done) {
|
||||
if (isBuilding) {
|
||||
if (chunk.trim().indexOf("```nomnoml") === 0) {
|
||||
var outputFilename = prefix + '-' + counter + '.png';
|
||||
outputPath = path.join(outputDirectory, outputFilename);
|
||||
this.push([
|
||||
"\n![Diagram ",
|
||||
counter,
|
||||
"](",
|
||||
outputFilename,
|
||||
")\n\n"
|
||||
].join(""));
|
||||
isBuilding = true;
|
||||
source = "";
|
||||
} else {
|
||||
// Otherwise, pass through
|
||||
this.push(chunk);
|
||||
}
|
||||
} else {
|
||||
if (chunk.trim() === "```") {
|
||||
// End nomnoml
|
||||
renderNomnoml(source, outputPath);
|
||||
isBuilding = false;
|
||||
} else {
|
||||
source += chunk;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
||||
function concat() {
|
||||
|
||||
}
|
||||
|
||||
function gfmifier() {
|
||||
var transform = new stream.Transform({ objectMode: true }),
|
||||
markdown = "";
|
||||
transform._transform = function (chunk, encoding, done) {
|
||||
markdown += chunk;
|
||||
};
|
||||
transform._flush = function () {
|
||||
this.push(markdown);
|
||||
};
|
||||
return transform;
|
||||
}
|
||||
|
||||
options['in'] = options['in'] || options.i;
|
||||
options.out = options.out || options.o;
|
||||
|
||||
glob(options['in'] + "/**/*.md", {}, function (err, files) {
|
||||
files.forEach(function (file) {
|
||||
var destination = file.replace(options['in'], options.out)
|
||||
.replace(/md$/, "html"),
|
||||
destPath = path.dirname(destination),
|
||||
prefix = path.basename(destination).replace(/\.html$/, "");
|
||||
|
||||
mkdirp(destPath, function (err) {
|
||||
fs.createReadStream(file, { encoding: 'utf8' })
|
||||
.pipe(split())
|
||||
.pipe(nomnomlifier(destPath, prefix))
|
||||
.pipe(gfmifier())
|
||||
.pipe(fs.createWriteStream(destination, {
|
||||
encoding: 'utf8'
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
3
docsrc/guide/index.md
Normal file
3
docsrc/guide/index.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Hello, world!
|
||||
|
||||
This is a placeholder for the developer guide.
|
33
docsrc/index.html
Normal file
33
docsrc/index.html
Normal file
@ -0,0 +1,33 @@
|
||||
<!--
|
||||
Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
as represented by the Administrator of the National Aeronautics and Space
|
||||
Administration. All rights reserved.
|
||||
|
||||
Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
License for the specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
Open MCT Web includes source code licensed under additional open source
|
||||
licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
this source code distribution or the Licensing information page available
|
||||
at runtime from the About dialog for additional information.
|
||||
-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title>Open MCT Web Documentation</title>
|
||||
</head>
|
||||
<body class="user-environ" ng-view>
|
||||
<a href="api/">API</a>
|
||||
<a href="guide/">Developer Guide</a>
|
||||
<a href="architecture/">Architecture Overview</a>
|
||||
</body>
|
||||
</html>
|
10
package.json
10
package.json
@ -16,13 +16,19 @@
|
||||
"karma-jasmine": "^0.1.5",
|
||||
"karma-phantomjs-launcher": "^0.1.4",
|
||||
"karma-requirejs": "^0.2.2",
|
||||
"requirejs": "^2.1.17"
|
||||
"requirejs": "^2.1.17",
|
||||
"github-flavored-markdown": ">= 1.0.0",
|
||||
"glob": ">= 3.0.0",
|
||||
"split": "^1.0.0",
|
||||
"mkdirp": "^0.5.1",
|
||||
"nomnoml": "^0.0.3",
|
||||
"canvas": "^1.2.7"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
"test": "karma start --single-run",
|
||||
"jshint": "jshint platform example || exit 0",
|
||||
"jsdoc": "jsdoc -c jsdoc.json -r -d docs"
|
||||
"jsdoc": "jsdoc -c jsdoc.json -r -d docs/api"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
Loading…
Reference in New Issue
Block a user