Skip to content

Commit

Permalink
feat: add CLI option --title to specify page title
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
mikaello committed Apr 2, 2022
1 parent 88887d2 commit 2ddbca2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ npx @mikaello/avrodoc-plus -i source -o out.html
Pass in a source folder that will recursively parsed and crawled for avsc files
- -o _outputfile_
The file where the generated doc should be written to
- --title _Avrodoc for ACME_
The title that will be used in the generated HTML page, deafults to _Avrodoc_.
- -s _external stylesheet less file_
Your own less file, used to override specific style of your generated page
- --ignore-invalid
Expand Down
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ app.use(lessMiddleware(__dirname + "/public"));
app.use(express.static(path.join(__dirname, "public")));

app.get("/", async function (req, res) {
const html = await topLevelHTML([], { schemata: schemata });
const html = await topLevelHTML("Server side Avrodoc", [], {
schemata: schemata,
});
res.set("Content-Type", "text/html").send(html);
});

Expand Down
4 changes: 3 additions & 1 deletion src/avrodoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const avrodocDebug = debug("avrodoc:avrodoc");

/**
*
* @param {string} title the main title of the generated Avrodoc page
* @param {Array<string>} extra_less_files an array with extra less files to be added
* @param {Array<string>} inputfiles an array with resolved filenames to be read and parsed and eventually added to the avrodoc
* @param {string} outputfile the html file that should be written
*/
async function createAvroDoc(
title,
extra_less_files,
inputfiles,
outputfile,
Expand All @@ -30,7 +32,7 @@ async function createAvroDoc(
})
.filter((s) => s != null);

const html = await topLevelHTML(extra_less_files, {
const html = await topLevelHTML(title, extra_less_files, {
inline: true,
schemata,
});
Expand Down
2 changes: 1 addition & 1 deletion src/avrodoc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("test HTML generation", () => {

test("avrodoc creates documentation", async () => {
await expect(
createAvroDoc([], ["./schemata/example.avsc"], testFile)
createAvroDoc("Test: Avrodoc", [], ["./schemata/example.avsc"], testFile)
).resolves.toBeUndefined();

expect(readFileSync(testFile, "utf-8")).toContain(
Expand Down
12 changes: 11 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const argv = arg({
"--input": String,
"-i": "--input",

"--title": String,

"--style": String,
"-s": "--style",

Expand Down Expand Up @@ -52,6 +54,7 @@ const extra_less_files = argv["--style"] ? [argv["--style"]] : [];
if (argv["--ignore-invalid"]) {
ignoreInvalidSchemas = true;
}
const pageTitle = argv["--title"];

//valid input?
if (!inputFiles || inputFiles.length === 0 || outputFile === null) {
Expand All @@ -60,7 +63,14 @@ if (!inputFiles || inputFiles.length === 0 || outputFile === null) {
);
process.exit(1);
}
createAvroDoc(extra_less_files, inputFiles, outputFile, ignoreInvalidSchemas);

createAvroDoc(
pageTitle,
extra_less_files,
inputFiles,
outputFile,
ignoreInvalidSchemas
);

//private stuff

Expand Down
5 changes: 3 additions & 2 deletions src/static_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ function inlineContent(extra_less_files, callback) {
/**
* Generate HTML and CSS
*
* @param {string} title - main title of the page
* @param {string[]} extra_less_files
* @param {Object} options - inline function for LESS and context options for DustJs
* @returns {Promise<string>}
*/
function topLevelHTML(extra_less_files, options) {
function topLevelHTML(title, extra_less_files, options) {
return new Promise((resolve, reject) => {
(options.inline ? inlineContent : remoteContent)(
extra_less_files,
Expand All @@ -194,7 +195,7 @@ function topLevelHTML(extra_less_files, options) {
}

const context = {
title: "Avrodoc",
title: title ?? "Avrodoc",
content: content,
schemata: "[]",
...options,
Expand Down

0 comments on commit 2ddbca2

Please sign in to comment.