diff --git a/lib/main.js b/lib/main.js index 988a7034325d7fcff0f6bbf1cef762c50787e7c5..afb401ee54e9cca6a84be96724c8a9ddf7ca5e7f 100644 --- a/lib/main.js +++ b/lib/main.js @@ -60,13 +60,11 @@ function writeFile(outputDir, fileName, data, cb) { */ function generateHtml(schema, cb) { var ctx = { - model: schema.getModel(), - consts: consts, - prefixes: schema.getPrefixMap(), + schema: schema, _: _ }; - ejs.renderFile('./templates/html/schema.ejs', ctx, { debug: false }, function (err, str) { + ejs.renderFile(path.join(__dirname,'../templates/html/schema.ejs'), ctx, { debug: false }, function (err, str) { if (err) { cb(err); } else { @@ -82,28 +80,18 @@ function generateHtml(schema, cb) { * @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(), + schema: schema, _: _ }; - ejs.renderFile('./templates/md/class.ejs', ctx, { debug: false }, function (err, str) { + ejs.renderFile(path.join(__dirname,'../templates/md/class.ejs'), ctx, { debug: false }, function (err, str) { if (err) { - done(err); + cb(err); } 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) { @@ -120,6 +108,7 @@ function generateJSONSchema(schema, callBack) { }); } + // parse/process command line arguments var argv = require('optimist') @@ -148,7 +137,7 @@ Schema.load(schemaFile, function (err, schema) { 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) { // generate Html @@ -160,7 +149,7 @@ Schema.load(schemaFile, function (err, schema) { generateMarkdown(schema, next); } - function toJsonLd(next) { + /* function toJsonLd(next) { // serialize RDF to JSON-LD schema.toJsonLD(function (err, doc, context) { if (err) { @@ -179,12 +168,13 @@ Schema.load(schemaFile, function (err, schema) { }); } + function toJsonSchema(next) { // Output JSON Schema for use in validation of JSON documents generateJSONSchema(schema, next); } - - async.series([ toHtml, toMarkdown, toJsonLd, toJsonSchema], function (err) { + */ + async.series([ toHtml, toMarkdown], function (err) { if (err) { logger.error(err); } else { diff --git a/lib/schema.js b/lib/schema.js index 90feca1ca8f987294ac71ee040b9842bb2ba857f..788e29c2a5ee04558ab6090f6572d1820f3079ad 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -63,6 +63,7 @@ var Schema = function (model, rdfDoc) { * @param {String|Error} cb.error error (non-null if an error occurred) * @param {Schema} cb.schema Schema instance */ +/* Schema.load = function (schemaFile, cb) { function isInstanceOf(subjects, a, b) { @@ -294,7 +295,26 @@ Schema.load = function (schemaFile, 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); + } +}); +} + async.waterfall([ readFile, resolveReferences], cb); +} /** * Returns the data model object. * diff --git a/package.json b/package.json index 973ffac13c4cedd831e159b6be780d44681688aa..2d0d1a788d309afc2e558792dcea89389f18370e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "async": "^2.0.1", "mkdirp": "^0.5.1", "ejs": "^2.4.2", - "ajv": "^5.0.1-beta" + "ajv": "^5.0.1-beta", + "json-schema-ref-parser":"3.1.2" }, "engines": { "node": ">= 0.10.0" diff --git a/templates/html/class.ejs b/templates/html/class.ejs index fec82bb3469117bf45955d56c02aafc28b206398..4545dda6139b8a2d3028212b4b109977231a7c33 100644 --- a/templates/html/class.ejs +++ b/templates/html/class.ejs @@ -18,13 +18,21 @@ **************************************************************************/ %> <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> - <div> <span style = "font-size:large">Description: </span> <%- clazz[consts.RDFS_COMMENT] %></div> - <% if (clazz[consts.SKOS_NOTE]) { %> + <div> <span style = "font-size:large">Description: </span> <%- schema["description"] %></div> + <% if (schema["note"]) { %> <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> <div style = "font-size:large"><b>Properties:</b></div> <div class=" table " data-dist-id="table_246994025"> @@ -38,12 +46,12 @@ </tr> </thead> <tbody> - <% _.forEach(clazz.properties, function (prop) { %> + <% _.forOwn(schema.properties, function (value,prop) { %> <tr> - <td align = "center"><b><%- prefixes.shrink(prop["@id"]) %></b></td> - <td><%- prop[consts.META_JSONNAME] %></td> - <td><%- model.datatypes[prop[consts.RDFS_RANGE]][consts.RDFS_LABEL] %></td> - <td><%- prop[consts.RDFS_COMMENT] %></td> + <td align = "center"><b><%- prop %></b></td> + <td><%- prop %></td> + <td><%- getType(value) %></td> + <td><%- value["description"] %></td> </tr> <% }); %> </tbody> diff --git a/templates/html/schema.ejs b/templates/html/schema.ejs index 911e297bb3cf5d17f311ad0130c5676f697bce68..2875a5106c6e433ba539676a779e12521885edc4 100644 --- a/templates/html/schema.ejs +++ b/templates/html/schema.ejs @@ -20,7 +20,7 @@ <html> <head> -<title><%- model.meta[consts.DC_TITLE] %></title> +<title><%# model.meta[consts.DC_TITLE] %></title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> @@ -40,18 +40,18 @@ <div id="containerTTMbox" class="containerTTMbox"></div> <header class="grid-container-fluid" data-profile-api="https://cc-collab.adobe.io/profile"> - <section class="grid-row"> - <nav class="grid-cols-14 grid-offset-1"> - - <!--#set var="Gnav:Locale" value="" --> - <!--#set var="Gnav:Scripts" value="false" --> - <!--#include virtual="/ubi/globalnav/_all/gnav_assets.ssi" --> - - <div class="site-header-global-nav LayoutBreakAfter"> - <div class="site-header-global-menu LayoutBreakAfter"></div> - </div> - </nav> - </section> + <section class="grid-row"> + <nav class="grid-cols-14 grid-offset-1"> + + <!--#set var="Gnav:Locale" value="" --> + <!--#set var="Gnav:Scripts" value="false" --> + <!--#include virtual="/ubi/globalnav/_all/gnav_assets.ssi" --> + + <div class="site-header-global-nav LayoutBreakAfter"> + <div class="site-header-global-menu LayoutBreakAfter"></div> + </div> + </nav> + </section> </header> @@ -68,7 +68,7 @@ </div> <input id="bookmark-display" name="bookmarks" type="checkbox"> <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> <span class="anchornav-active">Documentation</span> <span class="vertical-break">|</span> @@ -115,15 +115,15 @@ </nav></sidenav> </div> <div class="grid-cols-10 grid-offset-1 udp-target-temp-style udp-target"> - <div class="cq-dev-text"> -<h1><%- model.meta[consts.DC_TITLE] %></h1> -<div><%- model.meta[consts.RDFS_COMMENT] %></div> + <div class="cq-dev-text"> +<!-- <h1><%# model.meta[consts.DC_TITLE] %></h1> +<div><%# model.meta[consts.RDFS_COMMENT] %></div> --> <h2><u>Classes</u></h2> <ul> - <% _.forEach(model.classes, function (clazz) { %> - <%- include('class', { clazz: clazz, model: model, consts: consts, _: _, prefixes: prefixes }); %> + <%# _.forEach(model.classes, function (clazz) { %> + <%- include('class', { schema: schema, _: _}); %> <br> - <% }); %> + <%# }); %> </ul> </div></div> </div></div> </main> diff --git a/templates/md/class.ejs b/templates/md/class.ejs index 84307637b09217d254f0353545735494756d3c6d..c4cb15f2e90dfbbcbe463935c16f94eb5572ad03 100644 --- a/templates/md/class.ejs +++ b/templates/md/class.ejs @@ -26,13 +26,27 @@ function escape(s) { } 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] %> -<% if (clazz[consts.SKOS_NOTE]) { %> -Note: <%- clazz[consts.SKOS_NOTE] %><% } %> -|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]) %> | -<% }); %> +|JSON Name|Type|Description|Immutable|Mandatory|UserEditable|Note|Example Value| +|--- |--- |--- |--- |--- |--- |--- |--- |<% _.forOwn(schema.properties, function (value,prop) { %> +| <%- prop %> | <%- getType(value) %> | <%- escape(value["description"]) %> | <%- value["immutable"] %> | <%- isMandatory(prop,schema["required"]) %> | <%- !(value["readOnly"]) %> | <%- value["note"] %> | <%- value["examples"] %> |<% }); %>