mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 10:04:08 +03:00
feat(cli): Add templateOptions param to pass additional data to custom template (#792)
* Add templateOptions param to pass additional data to custom template * Update README for ReDoc cli
This commit is contained in:
parent
889cbe3f79
commit
4e8ee0305d
|
@ -17,5 +17,6 @@ Some examples:
|
||||||
- Bundle with main color changed to `orange`: <br> `$ redoc-cli bundle [spec] --options.theme.colors.primary.main=orange`
|
- Bundle with main color changed to `orange`: <br> `$ redoc-cli bundle [spec] --options.theme.colors.primary.main=orange`
|
||||||
- Serve with `nativeScrollbars` option set to true: <br> `$ redoc-cli serve [spec] --options.nativeScrollbars`
|
- Serve with `nativeScrollbars` option set to true: <br> `$ redoc-cli serve [spec] --options.nativeScrollbars`
|
||||||
- Bundle using custom template (check [default template](https://github.com/Rebilly/ReDoc/blob/master/cli/template.hbs) for reference): <br> `$ redoc-cli bundle [spec] -t custom.hbs`
|
- Bundle using custom template (check [default template](https://github.com/Rebilly/ReDoc/blob/master/cli/template.hbs) for reference): <br> `$ redoc-cli bundle [spec] -t custom.hbs`
|
||||||
|
- Bundle using custom template and add custom `templateOptions`: <br> `$ redoc-cli bundle [spec] -t custom.hbs --templateOptions.metaDescription "Page meta description"`
|
||||||
|
|
||||||
For more details run `redoc-cli --help`.
|
For more details run `redoc-cli --help`.
|
||||||
|
|
15
cli/index.ts
15
cli/index.ts
|
@ -26,6 +26,7 @@ interface Options {
|
||||||
output?: string;
|
output?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
templateFileName?: string;
|
templateFileName?: string;
|
||||||
|
templateOptions?: any;
|
||||||
redocOptions?: any;
|
redocOptions?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,6 +66,7 @@ YargsParser.command(
|
||||||
ssr: argv.ssr,
|
ssr: argv.ssr,
|
||||||
watch: argv.watch,
|
watch: argv.watch,
|
||||||
templateFileName: argv.template,
|
templateFileName: argv.template,
|
||||||
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: argv.options || {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,6 +114,7 @@ YargsParser.command(
|
||||||
cdn: argv.cdn,
|
cdn: argv.cdn,
|
||||||
title: argv.title,
|
title: argv.title,
|
||||||
templateFileName: argv.template,
|
templateFileName: argv.template,
|
||||||
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: argv.options || {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,6 +131,9 @@ YargsParser.command(
|
||||||
describe: 'Path to handlebars page template, see https://git.io/vh8fP for the example ',
|
describe: 'Path to handlebars page template, see https://git.io/vh8fP for the example ',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
})
|
})
|
||||||
|
.options('templateOptions', {
|
||||||
|
describe: 'Additional options that you want pass to template. Use dot notation, e.g. templateOptions.metaDescription',
|
||||||
|
})
|
||||||
.options('options', {
|
.options('options', {
|
||||||
describe: 'ReDoc options, use dot notation, e.g. options.nativeScrollbars',
|
describe: 'ReDoc options, use dot notation, e.g. options.nativeScrollbars',
|
||||||
}).argv;
|
}).argv;
|
||||||
|
@ -207,7 +213,7 @@ async function bundle(pathToSpec, options: Options = {}) {
|
||||||
async function getPageHTML(
|
async function getPageHTML(
|
||||||
spec: any,
|
spec: any,
|
||||||
pathToSpec: string,
|
pathToSpec: string,
|
||||||
{ ssr, cdn, title, templateFileName, redocOptions = {} }: Options,
|
{ ssr, cdn, title, templateFileName, templateOptions, redocOptions = {} }: Options,
|
||||||
) {
|
) {
|
||||||
let html;
|
let html;
|
||||||
let css;
|
let css;
|
||||||
|
@ -241,15 +247,16 @@ async function getPageHTML(
|
||||||
ssr
|
ssr
|
||||||
? 'hydrate(__redoc_state, container);'
|
? 'hydrate(__redoc_state, container);'
|
||||||
: `init("spec.json", ${JSON.stringify(redocOptions)}, container)`
|
: `init("spec.json", ${JSON.stringify(redocOptions)}, container)`
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>`,
|
</script>`,
|
||||||
redocHead: ssr
|
redocHead: ssr
|
||||||
? (cdn
|
? (cdn
|
||||||
? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
|
? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
|
||||||
: `<script>${redocStandaloneSrc}</script>`) + css
|
: `<script>${redocStandaloneSrc}</script>`) + css
|
||||||
: '<script src="redoc.standalone.js"></script>',
|
: '<script src="redoc.standalone.js"></script>',
|
||||||
title,
|
title,
|
||||||
|
templateOptions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user