Comparing version 0.0.1 to 0.0.2
'use strict'; | ||
var | ||
compileTemplate = require('simple-template-js'); | ||
compile = require('simple-template-js'); | ||
var renderRoot = compileTemplate([ | ||
'# <%= ctx.title %>', | ||
'<%= ctx.description || "" %>', | ||
'| property | type | description |', | ||
'|----------|------|-------------|' | ||
].join('\n'), 'path,ctx'); | ||
var | ||
defaultTemplate = [ | ||
'<% if (path.length === 0) { %>', | ||
'# <%= prop.title %>\n', | ||
'<%= prop.description || "" %>\n', | ||
'| property | type | description |\n', | ||
'|----------|------|-------------|\n', | ||
'<% } else { %>', | ||
'| <%= path.join(".") %> | <%= prop.enum ? "enum" : prop.type %> | <%= prop.description %> |\n', | ||
'<% } %>' | ||
].join(''); | ||
var render = compileTemplate([ | ||
'| <%= path.join(".") %> ', | ||
'| <%= ctx.enum ? "enum" : ctx.type %> ', | ||
'| <%= ctx.description %> |' | ||
].join(''), 'path,ctx'); | ||
function walk(out, path, ctx) { | ||
if (path.length === 0) { | ||
out.push(renderRoot(path, ctx)); | ||
} else { | ||
out.push(render(path, ctx)); | ||
} | ||
if (ctx.properties) { | ||
for (var name in ctx.properties) { | ||
walk(out, path.concat(name), ctx.properties[name]); | ||
function walk(out, path, prop, render) { | ||
out.push(render(path, prop)); | ||
if (prop.properties) { | ||
for (var name in prop.properties) { | ||
walk(out, path.concat(name), prop.properties[name], render); | ||
} | ||
@@ -33,8 +27,8 @@ } | ||
function jsonDoc(schema) { | ||
var out = []; | ||
walk(out, [], schema); | ||
return out.join('\n'); | ||
function jsonDoc(schema, template) { | ||
var out = [], render = compile(template || defaultTemplate, 'path,prop'); | ||
walk(out, [], schema, render); | ||
return out.join(''); | ||
} | ||
module.exports = jsonDoc; |
{ | ||
"name": "json-doc", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Make Markdown from JSON Schema", | ||
@@ -5,0 +5,0 @@ "author": "snoguchi", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6626
165