diff --git a/lib/main.js b/lib/main.js
index 2f0a6f27ac5bbc20e70a7e5beb958a5e2aeeabe0..e46a7b1885c57dd923d8b4635f473ec838bae9cf 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -25,6 +25,7 @@ var _ = require('lodash');
var async = require('async');
var ejs = require('ejs');
var logger = require('winston');
+var mkdirp = require('mkdirp');
var consts = require('./constants');
var Schema = require('./schema');
@@ -35,7 +36,7 @@ function writeFile(outputDir, fileName, data, cb) {
// make sure output dir exists
fs.stat(outputDir, function (err, stat) {
if (err) {
- fs.mkdir(outputDir, next);
+ mkdirp(outputDir, next);
} else {
next();
}
@@ -64,15 +65,46 @@ function generateHtml(schema, cb) {
_: _
};
- ejs.renderFile('./templates/schema.ejs', ctx, function (err, str) {
+ ejs.renderFile('./templates/html/schema.ejs', ctx, { debug: false }, function (err, str) {
if (err) {
cb(err);
} else {
- writeFile(outDir, baseName + '.html', str, cb);
+ writeFile(path.join(outDir, 'html'), baseName + '.html', str, cb);
}
});
}
+/**
+ *
+ * @param {Schema} schema instance
+ * @param {Function} cb callback called on completion
+ * @param {String|Error} cb.error error (non-null if an error occurred)
+ */
+function generateMarkdown(schema, cb) {
+ // render each class in separate .md file
+ async.each(schema.getModel().classes,
+ function (cls, done) {
+ var ctx = {
+ clazz: cls,
+ model: schema.getModel(),
+ consts: consts,
+ prefixes: schema.getPrefixMap(),
+ _: _
+ };
+ ejs.renderFile('./templates/md/class.ejs', ctx, { debug: false }, function (err, str) {
+ if (err) {
+ done(err);
+ } else {
+ writeFile(path.join(outDir, 'md'), cls[consts.RDFS_LABEL] + '.md', str, done);
+ }
+ });
+ },
+ function (err) {
+ cb(err);
+ }
+ );
+}
+
// parse/process command line arguments
var argv = require('optimist')
@@ -108,14 +140,19 @@ Schema.load(schemaFile, function (err, schema) {
generateHtml(schema, next);
}
+ function toMarkdown(next) {
+ // generate Markdown
+ generateMarkdown(schema, next);
+ }
+
function toJsonLd(next) {
// serialize RDF to JSON-LD
schema.toJsonLD(function (err, doc) {
- writeFile(outDir, baseName + '.json', JSON.stringify(doc, null, 2), next);
+ writeFile(path.join(outDir, 'json'), baseName + '.json', JSON.stringify(doc, null, 2), next);
});
}
- async.series([ toHtml, toJsonLd ], function (err) {
+ async.series([ toHtml, toMarkdown, toJsonLd ], function (err) {
if (err) {
logger.error(err);
} else {
diff --git a/package.json b/package.json
index f55073ebba7b59400fd6fd255346a72d788ff71d..d5b4e50bede0715b33c4a3d50934d0f1795eda24 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"winston": "^2.2.0",
"lodash": "^4.5.0",
"async": "^2.0.1",
+ "mkdirp": "^0.5.1",
"ejs": "^2.4.2"
},
"engines": {
diff --git a/templates/class.ejs b/templates/html/class.ejs
similarity index 100%
rename from templates/class.ejs
rename to templates/html/class.ejs
diff --git a/templates/schema.ejs b/templates/html/schema.ejs
similarity index 95%
rename from templates/schema.ejs
rename to templates/html/schema.ejs
index 3262d6c9961d3f08bbfc7856f88a106b0397ab4c..911e297bb3cf5d17f311ad0130c5676f697bce68 100644
--- a/templates/schema.ejs
+++ b/templates/html/schema.ejs
@@ -28,12 +28,12 @@
<link rel="icon" href="https://wwwimages2.adobe.com/include/img/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="https://wwwimages2.adobe.com/include/img/favicon.ico" type="image/x-icon">
-<link rel="stylesheet" href="../public/css/adobe.css" type="text/css" />
+<link rel="stylesheet" href="../../public/css/adobe.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../public//css/aceui-reimagine.min.css"/>
-<link rel="stylesheet" href="../public/css/thirdparty-new.css" type="text/css" />
-<link rel="stylesheet" href="../public/css/customized.css" type="text/css" />
-<link rel="stylesheet" type="text/css" href="../public/css/icons.min.css"/>
-<link rel="stylesheet" href="../public/css/clientlib-all.css" type="text/css" />
+<link rel="stylesheet" href="../../public/css/thirdparty-new.css" type="text/css" />
+<link rel="stylesheet" href="../../public/css/customized.css" type="text/css" />
+<link rel="stylesheet" type="text/css" href="../../public/css/icons.min.css"/>
+<link rel="stylesheet" href="../../public/css/clientlib-all.css" type="text/css" />
</head>
<body class="Lobby globalnav__external__no-touch" data-personalization-json="/content/udp/en/products/contentapi/docs/getting-started.loggedin.json" data-seed-personalization="" data-seed-themes="" data-seed-modal="" data-seed-details="" data-seed-messages="" data-seed-deeplink=""><div data-country="US" data-language="en" data-locale="en_US" id="globalnav__header" class="globalnav__js__header globalnav__feature-flag--dc">
diff --git a/templates/md/class.ejs b/templates/md/class.ejs
new file mode 100644
index 0000000000000000000000000000000000000000..e3fc15b634f405b2bcb03fcb54d0b26b4913e7c5
--- /dev/null
+++ b/templates/md/class.ejs
@@ -0,0 +1,35 @@
+<%
+/*************************************************************************
+ *
+ * ADOBE CONFIDENTIAL
+ * ___________________
+ *
+ * Copyright 2016 Adobe Systems Incorporated
+ * All Rights Reserved.
+ *
+ * NOTICE: All information contained herein is, and remains
+ * the property of Adobe Systems Incorporated and its suppliers,
+ * if any. The intellectual and technical concepts contained
+ * herein are proprietary to Adobe Systems Incorporated and its
+ * suppliers and are protected by trade secret or copyright law.
+ * Dissemination of this information or reproduction of this material
+ * is strictly forbidden unless prior written permission is obtained
+ * from Adobe Systems Incorporated.
+ **************************************************************************/
+%>
+<%
+function escape(s) {
+ return s.replace(/\n/g, '<br>');
+}
+%>
+*<%- clazz[consts.RDFS_LABEL] %>*
+
+<%- clazz[consts.RDFS_COMMENT] %>
+
+<% if (clazz[consts.SKOS_NOTE]) { %>
+Note: <%- clazz[consts.SKOS_NOTE] %>
+
+<% } %>
+|Name|JSON Name|Type|Description|Note|Example Value|
+|--- |--- |--- |--- |--- |--- |<% _.forEach(clazz.properties, function (prop) { %>
+| <%- prefixes.shrink(prop["@id"]) %> | <%- prop[consts.META_JSONNAME] %> | <%- model.datatypes[prop[consts.RDFS_RANGE]][consts.RDFS_LABEL] %> | <%- escape(prop[consts.RDFS_COMMENT]) %> | <%- escape(prop[consts.SKOS_NOTE]) %> | <%- escape(prop[consts.SKOS_EXAMPLE]) %> | <% }); %>