Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jsonschema2md
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fork
jsonschema2md
Commits
23e16b16
Commit
23e16b16
authored
7 years ago
by
Lars Trieloff
Browse files
Options
Downloads
Patches
Plain Diff
#14 support multiple, modular templates
parent
c7b9b820
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/markdownWriter.js
+14
-1
14 additions, 1 deletion
lib/markdownWriter.js
spec/lib/writeFiles.spec.js
+1
-2
1 addition, 2 deletions
spec/lib/writeFiles.spec.js
with
15 additions
and
3 deletions
lib/markdownWriter.js
+
14
−
1
View file @
23e16b16
...
@@ -13,6 +13,15 @@ var ejs = require('ejs');
...
@@ -13,6 +13,15 @@ var ejs = require('ejs');
const
pejs
=
Promise
.
promisifyAll
(
ejs
);
const
pejs
=
Promise
.
promisifyAll
(
ejs
);
var
validUrl
=
require
(
'
valid-url
'
);
var
validUrl
=
require
(
'
valid-url
'
);
function
render
([
template
,
context
])
{
console
.
log
(
'
rendering
'
+
template
);
return
pejs
.
renderFileAsync
(
template
,
context
,
{
debug
:
false
});
}
function
build
(
total
,
fragment
)
{
return
total
+
fragment
;
}
const
generateMarkdown
=
function
(
filename
,
schema
,
schemaPath
,
outDir
,
dependencyMap
)
{
const
generateMarkdown
=
function
(
filename
,
schema
,
schemaPath
,
outDir
,
dependencyMap
)
{
var
ctx
=
{
var
ctx
=
{
schema
:
schema
,
schema
:
schema
,
...
@@ -21,7 +30,11 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
...
@@ -21,7 +30,11 @@ const generateMarkdown = function(filename, schema, schemaPath, outDir, dependen
dependencyMap
:
dependencyMap
dependencyMap
:
dependencyMap
};
};
return
pejs
.
renderFileAsync
(
path
.
join
(
__dirname
,
'
../templates/md/topSchema.ejs
'
),
ctx
,
{
debug
:
false
}).
then
(
str
=>
{
const
multi
=
[
[
path
.
join
(
__dirname
,
'
../templates/md/topSchema.ejs
'
),
ctx
]
];
return
Promise
.
reduce
(
Promise
.
map
(
multi
,
render
),
build
,
''
).
then
(
str
=>
{
//console.log('Writing markdown (promise)');
//console.log('Writing markdown (promise)');
const
mdfile
=
path
.
basename
(
filename
).
slice
(
0
,
-
5
)
+
'
.md
'
;
const
mdfile
=
path
.
basename
(
filename
).
slice
(
0
,
-
5
)
+
'
.md
'
;
return
writeFile
(
path
.
join
(
path
.
join
(
outDir
),
path
.
dirname
(
filename
.
substr
(
schemaPath
.
length
))),
mdfile
,
str
);
return
writeFile
(
path
.
join
(
path
.
join
(
outDir
),
path
.
dirname
(
filename
.
substr
(
schemaPath
.
length
))),
mdfile
,
str
);
...
...
This diff is collapsed.
Click to expand it.
spec/lib/writeFiles.spec.js
+
1
−
2
View file @
23e16b16
...
@@ -16,8 +16,7 @@ describe('writeFiles module', () => {
...
@@ -16,8 +16,7 @@ describe('writeFiles module', () => {
it
(
'
should invoke ejs.renderFile with the topSchema ejs template
'
,
()
=>
{
it
(
'
should invoke ejs.renderFile with the topSchema ejs template
'
,
()
=>
{
markdownWriter
(
'
somefile
'
,
{
'
my
'
:
'
schema
'
});
markdownWriter
(
'
somefile
'
,
{
'
my
'
:
'
schema
'
});
var
renderArgs
=
ejs
.
renderFile
.
calls
.
argsFor
(
0
);
var
renderArgs
=
ejs
.
renderFile
.
calls
.
argsFor
(
0
);
expect
(
renderArgs
[
0
]).
toContain
(
'
topSchema.ejs
'
);
expect
(
renderArgs
);
expect
(
renderArgs
[
1
].
schema
.
my
).
toEqual
(
'
schema
'
);
});
});
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment