Skip to content
Snippets Groups Projects
Commit dc3e3c91 authored by Anjan Kaur's avatar Anjan Kaur
Browse files

change for taking json-schema file as input and render it to markdown and html pages

parent 7c2595f1
No related branches found
No related tags found
No related merge requests found
...@@ -60,9 +60,7 @@ function writeFile(outputDir, fileName, data, cb) { ...@@ -60,9 +60,7 @@ function writeFile(outputDir, fileName, data, cb) {
*/ */
function generateHtml(schema, cb) { function generateHtml(schema, cb) {
var ctx = { var ctx = {
model: schema.getModel(), schema: schema,
consts: consts,
prefixes: schema.getPrefixMap(),
_: _ _: _
}; };
...@@ -82,31 +80,22 @@ function generateHtml(schema, cb) { ...@@ -82,31 +80,22 @@ function generateHtml(schema, cb) {
* @param {String|Error} cb.error error (non-null if an error occurred) * @param {String|Error} cb.error error (non-null if an error occurred)
*/ */
function generateMarkdown(schema, cb) { function generateMarkdown(schema, cb) {
// render each class in separate .md file
async.each(schema.getModel().classes,
function (cls, done) {
var ctx = { var ctx = {
clazz: cls, schema: schema,
model: schema.getModel(),
consts: consts,
prefixes: schema.getPrefixMap(),
_: _ _: _
}; };
ejs.renderFile('./templates/md/class.ejs', ctx, { debug: false }, function (err, str) { ejs.renderFile('./templates/md/class.ejs', ctx, { debug: false }, function (err, str) {
if (err) { if (err) {
done(err); cb(err);
} else { } else {
writeFile(path.join(outDir, 'md'), cls[consts.RDFS_LABEL].toLowerCase() + '.md', str, done); console.log("done");
writeFile(path.join(outDir, 'md'), schema['title'].toLowerCase() + '.md', str, cb);
} }
}); });
},
function (err) {
cb(err);
}
);
} }
function generateJSONSchema(schema, callBack) { function generateJSONSchema(schema, callBack) {
console.log("ll");
async.each(schema.getModel().classes, function (klass, eachCallback) { async.each(schema.getModel().classes, function (klass, eachCallback) {
json_schema.renderClass(klass, schema.getModel().datatypes, function (err, document) { json_schema.renderClass(klass, schema.getModel().datatypes, function (err, document) {
writeFile(path.join(outDir, 'json-schema'), klass[consts.RDFS_LABEL] + '.json', JSON.stringify(document, writeFile(path.join(outDir, 'json-schema'), klass[consts.RDFS_LABEL] + '.json', JSON.stringify(document,
...@@ -120,6 +109,7 @@ function generateJSONSchema(schema, callBack) { ...@@ -120,6 +109,7 @@ function generateJSONSchema(schema, callBack) {
}); });
} }
// parse/process command line arguments // parse/process command line arguments
var argv = require('optimist') var argv = require('optimist')
...@@ -148,7 +138,7 @@ Schema.load(schemaFile, function (err, schema) { ...@@ -148,7 +138,7 @@ Schema.load(schemaFile, function (err, schema) {
process.exit(1); process.exit(1);
} }
logger.info('parsed definitions of %d classes, %d properties and %d data types', _.keys(schema.getModel().classes).length, _.keys(schema.getModel().properties).length, _.keys(schema.getModel().datatypes).length); // logger.info('parsed definitions of %d classes, %d properties and %d data types', _.keys(schema.getModel().classes).length, _.keys(schema.getModel().properties).length, _.keys(schema.getModel().datatypes).length);
function toHtml(next) { function toHtml(next) {
// generate Html // generate Html
...@@ -160,7 +150,7 @@ Schema.load(schemaFile, function (err, schema) { ...@@ -160,7 +150,7 @@ Schema.load(schemaFile, function (err, schema) {
generateMarkdown(schema, next); generateMarkdown(schema, next);
} }
function toJsonLd(next) { /* function toJsonLd(next) {
// serialize RDF to JSON-LD // serialize RDF to JSON-LD
schema.toJsonLD(function (err, doc, context) { schema.toJsonLD(function (err, doc, context) {
if (err) { if (err) {
...@@ -179,12 +169,13 @@ Schema.load(schemaFile, function (err, schema) { ...@@ -179,12 +169,13 @@ Schema.load(schemaFile, function (err, schema) {
}); });
} }
function toJsonSchema(next) { function toJsonSchema(next) {
// Output JSON Schema for use in validation of JSON documents // Output JSON Schema for use in validation of JSON documents
generateJSONSchema(schema, next); generateJSONSchema(schema, next);
} }
*/
async.series([ toHtml, toMarkdown, toJsonLd, toJsonSchema], function (err) { async.series([ toHtml, toMarkdown], function (err) {
if (err) { if (err) {
logger.error(err); logger.error(err);
} else { } else {
......
...@@ -63,6 +63,7 @@ var Schema = function (model, rdfDoc) { ...@@ -63,6 +63,7 @@ var Schema = function (model, rdfDoc) {
* @param {String|Error} cb.error error (non-null if an error occurred) * @param {String|Error} cb.error error (non-null if an error occurred)
* @param {Schema} cb.schema Schema instance * @param {Schema} cb.schema Schema instance
*/ */
/*
Schema.load = function (schemaFile, cb) { Schema.load = function (schemaFile, cb) {
function isInstanceOf(subjects, a, b) { function isInstanceOf(subjects, a, b) {
...@@ -294,7 +295,27 @@ Schema.load = function (schemaFile, cb) { ...@@ -294,7 +295,27 @@ Schema.load = function (schemaFile, cb) {
async.waterfall([ readFile, parseTurtle, parseRDF ], cb); async.waterfall([ readFile, parseTurtle, parseRDF ], cb);
}; };
*/
var refParser = require('json-schema-ref-parser');
Schema.load = function(schemaFile, cb){
function readFile(callback) {
fs.readFile(schemaFile, callback);
}
function resolveReferences(schemaFile,callback){
//TODO change the module or write your own function too resolve $ref refrences
refParser.dereference(JSON.parse(schemaFile), function(err, schema) {
if (err) {
console.error(err);
}
else {
cb(null,schema);
console.log(schema.properties.createdByUser);
}
});
}
async.waterfall([ readFile, resolveReferences], cb);
}
/** /**
* Returns the data model object. * Returns the data model object.
* *
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
"async": "^2.0.1", "async": "^2.0.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"ejs": "^2.4.2", "ejs": "^2.4.2",
"ajv": "^5.0.1-beta" "ajv": "^5.0.1-beta",
"json-schema-ref-parser":"3.1.2"
}, },
"engines": { "engines": {
"node": ">= 0.10.0" "node": ">= 0.10.0"
......
...@@ -18,13 +18,21 @@ ...@@ -18,13 +18,21 @@
**************************************************************************/ **************************************************************************/
%> %>
<li> <li>
<div style = "font-size:x-large"><b><%- clazz[consts.RDFS_LABEL] %></b></div> <div style = "font-size:x-large"><b><%- schema["title"] %></b></div>
<br> <br>
<div> <span style = "font-size:large">Description: </span> <%- clazz[consts.RDFS_COMMENT] %></div> <div> <span style = "font-size:large">Description: </span> <%- schema["description"] %></div>
<% if (clazz[consts.SKOS_NOTE]) { %> <% if (schema["note"]) { %>
<br> <br>
<div>Note: <%- clazz[consts.SKOS_NOTE] %></div> <div>Note: <%- schema["note"] %></div>
<% } %> <% } %>
<%
function getType(valueObject) {
if( valueObject["format"] )
return valueObject["format"];
else
return valueObject["type"];
}
%>
<br> <br>
<div style = "font-size:large"><b>Properties:</b></div> <div style = "font-size:large"><b>Properties:</b></div>
<div class=" table " data-dist-id="table_246994025"> <div class=" table " data-dist-id="table_246994025">
...@@ -38,12 +46,12 @@ ...@@ -38,12 +46,12 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% _.forEach(clazz.properties, function (prop) { %> <% _.forOwn(schema.properties, function (value,prop) { %>
<tr> <tr>
<td align = "center"><b><%- prefixes.shrink(prop["@id"]) %></b></td> <td align = "center"><b><%- prop %></b></td>
<td><%- prop[consts.META_JSONNAME] %></td> <td><%- prop %></td>
<td><%- model.datatypes[prop[consts.RDFS_RANGE]][consts.RDFS_LABEL] %></td> <td><%- getType(value) %></td>
<td><%- prop[consts.RDFS_COMMENT] %></td> <td><%- value["description"] %></td>
</tr> </tr>
<% }); %> <% }); %>
</tbody> </tbody>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<html> <html>
<head> <head>
<title><%- model.meta[consts.DC_TITLE] %></title> <title><%# model.meta[consts.DC_TITLE] %></title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
...@@ -40,18 +40,18 @@ ...@@ -40,18 +40,18 @@
<div id="containerTTMbox" class="containerTTMbox"></div> <div id="containerTTMbox" class="containerTTMbox"></div>
<header class="grid-container-fluid" data-profile-api="https://cc-collab.adobe.io/profile"> <header class="grid-container-fluid" data-profile-api="https://cc-collab.adobe.io/profile">
<section class="grid-row"> <section class="grid-row">
<nav class="grid-cols-14 grid-offset-1"> <nav class="grid-cols-14 grid-offset-1">
<!--#set var="Gnav:Locale" value="" --> <!--#set var="Gnav:Locale" value="" -->
<!--#set var="Gnav:Scripts" value="false" --> <!--#set var="Gnav:Scripts" value="false" -->
<!--#include virtual="/ubi/globalnav/_all/gnav_assets.ssi" --> <!--#include virtual="/ubi/globalnav/_all/gnav_assets.ssi" -->
<div class="site-header-global-nav LayoutBreakAfter"> <div class="site-header-global-nav LayoutBreakAfter">
<div class="site-header-global-menu LayoutBreakAfter"></div> <div class="site-header-global-menu LayoutBreakAfter"></div>
</div> </div>
</nav> </nav>
</section> </section>
</header> </header>
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
</div> </div>
<input id="bookmark-display" name="bookmarks" type="checkbox"> <input id="bookmark-display" name="bookmarks" type="checkbox">
<label for="bookmark-display"></label> <label for="bookmark-display"></label>
<nav> <nav>
<a href="https://author-adobeio-stage.adobemsbasic.com/content/udp/en/products/contentapi.html" target="_self">Overview</a> <a href="https://author-adobeio-stage.adobemsbasic.com/content/udp/en/products/contentapi.html" target="_self">Overview</a>
<span class="anchornav-active">Documentation</span> <span class="anchornav-active">Documentation</span>
<span class="vertical-break">|</span> <span class="vertical-break">|</span>
...@@ -115,15 +115,15 @@ ...@@ -115,15 +115,15 @@
</nav></sidenav> </nav></sidenav>
</div> </div>
<div class="grid-cols-10 grid-offset-1 udp-target-temp-style udp-target"> <div class="grid-cols-10 grid-offset-1 udp-target-temp-style udp-target">
<div class="cq-dev-text"> <div class="cq-dev-text">
<h1><%- model.meta[consts.DC_TITLE] %></h1> <!-- <h1><%# model.meta[consts.DC_TITLE] %></h1>
<div><%- model.meta[consts.RDFS_COMMENT] %></div> <div><%# model.meta[consts.RDFS_COMMENT] %></div> -->
<h2><u>Classes</u></h2> <h2><u>Classes</u></h2>
<ul> <ul>
<% _.forEach(model.classes, function (clazz) { %> <%# _.forEach(model.classes, function (clazz) { %>
<%- include('class', { clazz: clazz, model: model, consts: consts, _: _, prefixes: prefixes }); %> <%- include('class', { schema: schema, _: _}); %>
<br> <br>
<% }); %> <%# }); %>
</ul> </ul>
</div></div> </div></div> </div></div> </div></div>
</main> </main>
......
...@@ -26,13 +26,27 @@ function escape(s) { ...@@ -26,13 +26,27 @@ function escape(s) {
} }
return ""; return "";
} }
function isMandatory(key,requiredProperties) {
if( _.indexOf(requiredProperties,key,0) != -1 )
return true;
else
return false;
}
function getType(valueObject) {
if( valueObject["format"] )
return valueObject["format"];
else
return valueObject["type"];
}
%> %>
# <%- clazz[consts.RDFS_LABEL] %> # <%- schema["title"] %>
<%- schema["description"] %>
<% if (schema["note"]) { %>
Note: <%- schema["note"] %> <% } %>
<%- clazz[consts.RDFS_COMMENT] %> |JSON Name|Type|Description|Immutable|Mandatory|UserEditable|Note|Example Value|
<% if (clazz[consts.SKOS_NOTE]) { %> |--- |--- |--- |--- |--- |--- |--- |--- |<% _.forOwn(schema.properties, function (value,prop) { %>
Note: <%- clazz[consts.SKOS_NOTE] %><% } %> | <%- prop %> | <%- getType(value) %> | <%- escape(value["description"]) %> | <%- value["immutable"] %> | <%- isMandatory(prop,schema["required"]) %> | <%- !(value["readOnly"]) %> | <%- value["note"] %> | <%- value["examples"] %> |<% }); %>
|Name|JSON Name|Type|Description|Immutable|Mandatory|UserEditable|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.PROP_IMMUTABLE]) %> | <%- escape(prop[consts.PROP_MANDATORY]) %> | <%- escape(prop[consts.PROP_USEREDITABLE]) %> | <%- 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