Skip to content
Snippets Groups Projects
Commit 41f2da0f authored by Lars Trieloff's avatar Lars Trieloff
Browse files

#14 move frontmatter into separate template, fix frontmatter

parent 23e16b16
No related branches found
No related tags found
No related merge requests found
---
template: reference
foo: bar
---
---
---
template : reference
foo : bar
---
# Abstract # Abstract
* **Type:** object * **Type:** object
...@@ -11,22 +21,15 @@ This is an abstract schema. It has `definitions`, but does not declare any prope ...@@ -11,22 +21,15 @@ This is an abstract schema. It has `definitions`, but does not declare any prope
## first ## first
### Properties ### Properties
### foo ### foo
* **Type:** string * **Type:** string
A unique identifier given to every addressable thing. A unique identifier given to every addressable thing.
## second ## second
### Properties ### Properties
### bar ### bar
* **Type:** string * **Type:** string
A unique identifier given to every addressable thing. A unique identifier given to every addressable thing.
---
template: reference
foo: bar
---
---
---
template : reference
foo : bar
---
# Definitions # Definitions
* **Type:** object * **Type:** object
This is an example of using a `definitions` object within a schema. This is an example of using a `definitions` object within a schema.
It is imported using `allOf` and `$ref`. It is imported using `allOf` and `$ref`.
## Properties ## Properties
### id ### id
* **Required** * **Required**
* **Type:** string * **Type:** string
...@@ -23,5 +29,3 @@ It is imported using `allOf` and `$ref`. ...@@ -23,5 +29,3 @@ It is imported using `allOf` and `$ref`.
A unique identifier given to every addressable thing. A unique identifier given to every addressable thing.
---
template: reference
foo: bar
---
---
---
template : reference
foo : bar
---
# Example # Example
* **Type:** object * **Type:** object
...@@ -18,20 +28,14 @@ This is an example schema with examples. Too many examples? There can never be t ...@@ -18,20 +28,14 @@ This is an example schema with examples. Too many examples? There can never be t
``` ```
## Properties ## Properties
### foo ### foo
* **Type:** string * **Type:** string
A simple string. A simple string.
### bar ### bar
* **Type:** string * **Type:** string
A simple string. A simple string.
---
template: reference
foo: bar
---
---
---
template : reference
foo : bar
---
# Simple # Simple
* **Type:** object * **Type:** object
This is a *very* simple example of a JSON schema. There is only one property. This is a *very* simple example of a JSON schema. There is only one property.
## Properties ## Properties
### id ### id
* **Type:** string * **Type:** string
* **Format:** uri * **Format:** uri
A unique identifier given to every addressable thing. A unique identifier given to every addressable thing.
---
template: reference
foo: bar
---
---
---
template : reference
foo : bar
---
# Subdir # Subdir
* **Type:** object * **Type:** object
...@@ -11,15 +21,10 @@ A schema in a sub directory ...@@ -11,15 +21,10 @@ A schema in a sub directory
## content ## content
### Properties ### Properties
### id ### id
* **Type:** string * **Type:** string
* **Format:** uri * **Format:** uri
A unique identifier given to every addressable thing. A unique identifier given to every addressable thing.
...@@ -19,7 +19,15 @@ function render([ template, context ]) { ...@@ -19,7 +19,15 @@ function render([ template, context ]) {
} }
function build(total, fragment) { function build(total, fragment) {
return total + fragment; return total + '\n' + fragment.replace(/\n\n/g, '\n');
}
function assoc(obj, key, value) {
if (obj==null) {
return assoc({}, key, value);
}
obj[key] = value;
return obj;
} }
const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) { const generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) {
...@@ -30,9 +38,18 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen ...@@ -30,9 +38,18 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
dependencyMap:dependencyMap dependencyMap:dependencyMap
}; };
console.log(schema.metaElements);
const multi = [ const multi = [
[ path.join(__dirname, '../templates/md/topSchema.ejs'), ctx ] [ 'header.ejs', { meta: schema.metaElements } ],
]; [ 'divider.ejs', null ],
[ 'topSchema.ejs', ctx ]
].map(([ template, context ]) => {
return [
path.join(__dirname, '../templates/md/' + template),
assoc(context, '_', _)
];
});
return Promise.reduce(Promise.map(multi, render), build, '').then(str => { return Promise.reduce(Promise.map(multi, render), build, '').then(str => {
//console.log('Writing markdown (promise)'); //console.log('Writing markdown (promise)');
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"scripts": { "scripts": {
"lint": "eslint .", "lint": "eslint .",
"start": "node cli.js", "start": "node cli.js",
"test": "npm run lint && jasmine && node cli.js -d examples/schemas -o examples/docs -x examples/generated-schemas", "test": "npm run lint && jasmine && node cli.js -d examples/schemas -o examples/docs -x examples/generated-schemas -m template=reference -m foo=bar",
"cover": "istanbul cover --root lib --print detail jasmine" "cover": "istanbul cover --root lib --print detail jasmine"
}, },
"dependencies": { "dependencies": {
......
<% /**
* Copyright 2017 Adobe Systems Incorporated. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/ %>
---
\ No newline at end of file
<% /**
* Copyright 2017 Adobe Systems Incorporated. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/ %>
<% if (meta) { %>
---
<% _.forIn(meta, (value, key, object) => { %>
<%= key %>: <%= value %>
<% }); %>
---
<% } %>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment