Skip to content
Snippets Groups Projects
Commit 011ff272 authored by Stefan Guggisberg's avatar Stefan Guggisberg
Browse files

added skeleton code to generate markdown per class

parent d27cb8c7
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ var _ = require('lodash'); ...@@ -25,6 +25,7 @@ var _ = require('lodash');
var async = require('async'); var async = require('async');
var ejs = require('ejs'); var ejs = require('ejs');
var logger = require('winston'); var logger = require('winston');
var mkdirp = require('mkdirp');
var consts = require('./constants'); var consts = require('./constants');
var Schema = require('./schema'); var Schema = require('./schema');
...@@ -35,7 +36,7 @@ function writeFile(outputDir, fileName, data, cb) { ...@@ -35,7 +36,7 @@ function writeFile(outputDir, fileName, data, cb) {
// make sure output dir exists // make sure output dir exists
fs.stat(outputDir, function (err, stat) { fs.stat(outputDir, function (err, stat) {
if (err) { if (err) {
fs.mkdir(outputDir, next); mkdirp(outputDir, next);
} else { } else {
next(); next();
} }
...@@ -64,15 +65,46 @@ function generateHtml(schema, cb) { ...@@ -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) { if (err) {
cb(err); cb(err);
} else { } 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 // parse/process command line arguments
var argv = require('optimist') var argv = require('optimist')
...@@ -108,14 +140,19 @@ Schema.load(schemaFile, function (err, schema) { ...@@ -108,14 +140,19 @@ Schema.load(schemaFile, function (err, schema) {
generateHtml(schema, next); generateHtml(schema, next);
} }
function toMarkdown(next) {
// generate Markdown
generateMarkdown(schema, next);
}
function toJsonLd(next) { function toJsonLd(next) {
// serialize RDF to JSON-LD // serialize RDF to JSON-LD
schema.toJsonLD(function (err, doc) { 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) { if (err) {
logger.error(err); logger.error(err);
} else { } else {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"winston": "^2.2.0", "winston": "^2.2.0",
"lodash": "^4.5.0", "lodash": "^4.5.0",
"async": "^2.0.1", "async": "^2.0.1",
"mkdirp": "^0.5.1",
"ejs": "^2.4.2" "ejs": "^2.4.2"
}, },
"engines": { "engines": {
......
File moved
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
<link rel="icon" href="https://wwwimages2.adobe.com/include/img/favicon.ico" type="image/x-icon"> <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="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" 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/thirdparty-new.css" type="text/css" />
<link rel="stylesheet" href="../public/css/customized.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" 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/clientlib-all.css" type="text/css" />
</head> </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"> <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">
......
<%
/*************************************************************************
*
* 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]) %> | <% }); %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment