Skip to content

Commit

Permalink
Merge pull request #3 from iasql/issue-1815
Browse files Browse the repository at this point in the history
Issue 1815
  • Loading branch information
yrobla authored Jan 28, 2023
2 parents 7d64d31 + 73afd90 commit a11be12
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 84 deletions.
4 changes: 4 additions & 0 deletions dist/lib/render-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const hierarchy_1 = __importDefault(require("./resources/helpers/hierarchy"));
const if_is_reference_1 = __importDefault(require("./resources/helpers/if-is-reference"));
const if_is_equal_1 = __importDefault(require("./resources/helpers/if-is-equal"));
const if_is_table_1 = __importDefault(require("./resources/helpers/if-is-table"));
const if_is_enum_1 = __importDefault(require("./resources/helpers/if-is-enum"));
const render_type_1 = __importDefault(require("./resources/helpers/render-type"));
const if_named_anchors_1 = __importDefault(require("./resources/helpers/if-named-anchors"));
const if_show_breadcrumbs_1 = __importDefault(require("./resources/helpers/if-show-breadcrumbs"));
const if_show_named_anchors_1 = __importDefault(require("./resources/helpers/if-show-named-anchors"));
Expand Down Expand Up @@ -84,6 +86,8 @@ function registerHelpers(theme) {
(0, if_is_reference_1.default)();
(0, if_is_equal_1.default)();
(0, if_is_table_1.default)();
(0, if_is_enum_1.default)();
(0, render_type_1.default)(theme);
(0, if_named_anchors_1.default)(theme);
(0, if_show_breadcrumbs_1.default)(theme);
(0, if_show_named_anchors_1.default)(theme);
Expand Down
1 change: 1 addition & 0 deletions dist/lib/resources/helpers/if-is-enum.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (): void;
34 changes: 34 additions & 0 deletions dist/lib/resources/helpers/if-is-enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = __importStar(require("handlebars"));
function default_1() {
Handlebars.registerHelper("ifIsEnum", function (arg1, options) {
return arg1.kindString == "Enumeration"
? options.fn(this)
: options.inverse(this);
});
}
exports.default = default_1;
8 changes: 6 additions & 2 deletions dist/lib/resources/helpers/if-is-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = __importStar(require("handlebars"));
function default_1() {
Handlebars.registerHelper("ifIsTable", function (arg1, options) {
const str = arg1.name;
return !str.includes("Rpc") ? options.fn(this) : options.inverse(this);
const str = arg1.name.toLowerCase();
return !str.includes("rpc") &&
!str.startsWith("iasql") &&
arg1.kindString == "Class"
? options.fn(this)
: options.inverse(this);
});
}
exports.default = default_1;
2 changes: 2 additions & 0 deletions dist/lib/resources/helpers/render-type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { MarkdownTheme } from "../../theme";
export default function (theme: MarkdownTheme): void;
48 changes: 48 additions & 0 deletions dist/lib/resources/helpers/render-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Handlebars = __importStar(require("handlebars"));
function default_1(theme) {
Handlebars.registerHelper("renderType", function () {
var _a;
let type, color;
if (this.kindString == "Class") {
if ((_a = this.url) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes("rpcs")) {
type = "Function";
color = "95CE3D";
}
else {
type = "Table";
color = "3D95CE";
}
}
else if (this.kindString == "Enumeration") {
type = "Enum";
color = "CD3C94";
}
return `![${type}](https://img.shields.io/static/v1?label=&message=${type}&color=${color}&style=for-the-badge)`;
});
}
exports.default = default_1;
46 changes: 37 additions & 9 deletions dist/lib/resources/helpers/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ function default_1(theme) {
if (!hideInPageTOC) {
md.push(`## Table of contents\n\n`);
}
for (const child of (_b = this.children) !== null && _b !== void 0 ? _b : []) {
let sortedChildren = (_b = this.children) !== null && _b !== void 0 ? _b : [];
sortedChildren.sort(function (x, y) {
return x.name == "iasql_functions"
? -1
: y.name == "iasql_functions"
? 1
: 0;
});
for (const child of sortedChildren) {
if (((_c = child.parent) === null || _c === void 0 ? void 0 : _c.id) == 0 &&
child.kind == 2 &&
!child.name.includes("/") &&
Expand All @@ -44,16 +52,36 @@ function default_1(theme) {
!child.name.includes("interfaces") &&
!child.name.includes("subscribers")) {
md.push(`### ${child.name}\n\n`);
for (const child1 of (_d = this.children) !== null && _d !== void 0 ? _d : []) {
if (child1.name.includes(child.name) &&
(child1.name.includes("entity") || child1.name.includes("rpc"))) {
for (const child2 of (_e = child1.children) !== null && _e !== void 0 ? _e : []) {
if (!((_f = child2.url) === null || _f === void 0 ? void 0 : _f.includes("modules"))) {
md.push(`[${(0, utils_1.camelToSnakeCase)(child2.name)}](${child2.url})\n\n`);
}
}
const tables = [];
const methods = [];
const enums = [];
const filtered = sortedChildren === null || sortedChildren === void 0 ? void 0 : sortedChildren.filter((x) => x.name.includes(child.name) &&
(x.name.includes("entity") || x.name.includes("rpc")));
for (const filt of filtered) {
for (const item of (_d = filt.children) !== null && _d !== void 0 ? _d : []) {
if (item.kindString == "Class" && !((_e = item.url) === null || _e === void 0 ? void 0 : _e.includes("rpc")))
tables.push(item);
if (item.kindString == "Class" && ((_f = item.url) === null || _f === void 0 ? void 0 : _f.includes("rpc")))
methods.push(item);
if (item.kindString == "Enumeration")
enums.push(item);
}
}
if (tables.length > 0)
md.push("  **Tables**\n");
for (const child2 of tables) {
md.push(`      [${(0, utils_1.camelToSnakeCase)(child2.name)}](${child2.url})\n\n`);
}
if (methods.length > 0)
md.push("  **Functions**\n");
for (const child2 of methods) {
md.push(`      [${(0, utils_1.camelToSnakeCase)(child2.name)}](${child2.url})\n\n`);
}
if (enums.length > 0)
md.push("  **Enums**\n");
for (const child2 of enums) {
md.push(`      [${(0, utils_1.camelToSnakeCase)(child2.name)}](${child2.url})\n\n`);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/lib/resources/helpers/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ function default_1() {
exports.default = default_1;
function getLiteralType(model) {
if (typeof model.value === "bigint") {
return `\`${model.value}n\``;
return `${model.value}n`;
}
return `\`\`${JSON.stringify(model.value)}\`\``;
return `\`${JSON.stringify(model.value).replace(/"/g, "")}\``;
}
function getReflectionType(model, collapse) {
const root = model instanceof typedoc_1.ReflectionType ? model.declaration : model;
Expand Down
6 changes: 5 additions & 1 deletion dist/lib/resources/templates/reflection.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{> header}}
{{> title}}
{{#with model}}
{{renderType}}
{{#if hasComment}}
{{> comment}}

{{/if}}

{{/with}}
Expand All @@ -13,6 +13,10 @@
{{#ifIsTable this}}
## Columns
{{/ifIsTable}}
{{#ifIsEnum this}}
## Values
{{/ifIsEnum}}


{{> main}}

Expand Down
4 changes: 2 additions & 2 deletions dist/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const DEFAULT_PLUGIN_OPTIONS = {
fullNames: false,
categoryLabel: "Reference",
indexLabel: undefined,
readmeLabel: "SQL",
readmeLabel: "Reference",
position: null,
autoConfiguration: true,
usedSidebar: "docs",
Expand All @@ -19,7 +19,7 @@ const DEFAULT_PLUGIN_OPTIONS = {
hideBreadcrumbs: true,
hidePageTitle: true,
hideMembersSymbol: false,
entryDocument: "sql.md",
entryDocument: "index.md",
plugin: ["none"],
watch: false,
includeExtension: true,
Expand Down
19 changes: 10 additions & 9 deletions dist/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
getYamlItems(page) {
const pageId = this.getId(page);
const pageTitle = this.getTitle(page);
const sidebarLabel = "SQL";
const sidebarLabel = "Reference";
const sidebarPosition = "0";
let items = {
id: pageId,
Expand All @@ -101,9 +101,10 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
items = { ...items, sidebar_position: parseFloat(sidebarPosition) };
}
}
if (page.url === page.project.url && this.entryPoints.length > 1) {
items = { ...items, hide_table_of_contents: true };
}
items = {
...items,
hide_table_of_contents: true,
};
items = { ...items, custom_edit_url: null };
if (this.frontmatter) {
items = { ...items, ...this.frontmatter };
Expand Down Expand Up @@ -164,19 +165,19 @@ class DocusaurusTheme extends theme_1.MarkdownTheme {
return readmeTitle;
}
let result = (0, front_matter_1.getPageTitle)(page);
if (page.url.includes("rpcs"))
result = result.replace("Class", "Method");
const items = result.split(":");
if (items.length == 2)
return items[1].trim();
else
result = result.replace("Class", "Table");
return result;
return result;
}
get mappings() {
return super.mappings.map((mapping) => {
return mapping;
});
}
get globalsFile() {
return "sql.md";
return "index.md";
}
}
__decorate([
Expand Down
4 changes: 4 additions & 0 deletions src/lib/render-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import hierarchyHelper from "./resources/helpers/hierarchy";
import ifIsReference from "./resources/helpers/if-is-reference";
import ifIsEqual from "./resources/helpers/if-is-equal";
import ifIsTable from "./resources/helpers/if-is-table";
import ifIsEnum from "./resources/helpers/if-is-enum";
import renderTypeHelper from "./resources/helpers/render-type";
import ifNamedAnchors from "./resources/helpers/if-named-anchors";
import ifShowBreadcrumbsHelper from "./resources/helpers/if-show-breadcrumbs";
import ifShowNamedAnchorsHelper from "./resources/helpers/if-show-named-anchors";
Expand Down Expand Up @@ -67,6 +69,8 @@ export function registerHelpers(theme: MarkdownTheme) {
ifIsReference();
ifIsEqual();
ifIsTable();
ifIsEnum();
renderTypeHelper(theme);
ifNamedAnchors(theme);
ifShowBreadcrumbsHelper(theme);
ifShowNamedAnchorsHelper(theme);
Expand Down
1 change: 0 additions & 1 deletion src/lib/resources/helpers/declaration-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default function (theme: MarkdownTheme) {
if (reflectionType && reflectionType.declaration?.children) {
return ": `Object`";
}

return (
(reflection.parent?.kindOf(ReflectionKind.Enum) ? " = " : ": ") +
Handlebars.helpers.type.call(
Expand Down
9 changes: 9 additions & 0 deletions src/lib/resources/helpers/if-is-enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Handlebars from "handlebars";

export default function () {
Handlebars.registerHelper("ifIsEnum", function (arg1, options) {
return arg1.kindString == "Enumeration"
? options.fn(this)
: options.inverse(this);
});
}
8 changes: 6 additions & 2 deletions src/lib/resources/helpers/if-is-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as Handlebars from "handlebars";

export default function () {
Handlebars.registerHelper("ifIsTable", function (arg1, options) {
const str = arg1.name;
return !str.includes("Rpc") ? options.fn(this) : options.inverse(this);
const str = arg1.name.toLowerCase();
return !str.includes("rpc") &&
!str.startsWith("iasql") &&
arg1.kindString == "Class"
? options.fn(this)
: options.inverse(this);
});
}
27 changes: 27 additions & 0 deletions src/lib/resources/helpers/render-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DeclarationReflection, ParameterReflection } from "typedoc";
import { MarkdownTheme } from "../../theme";
import * as Handlebars from "handlebars";

export default function (theme: MarkdownTheme) {
Handlebars.registerHelper(
"renderType",
function (this: ParameterReflection | DeclarationReflection) {
// get type from url and class
let type, color;
if (this.kindString == "Class") {
if (this.url?.toLowerCase().includes("rpcs")) {
type = "Function";
color = "95CE3D";
} else {
type = "Table";
color = "3D95CE";
}
} else if (this.kindString == "Enumeration") {
type = "Enum";
color = "CD3C94";
}

return `![${type}](https://img.shields.io/static/v1?label=&message=${type}&color=${color}&style=for-the-badge)`;
}
);
}
Loading

0 comments on commit a11be12

Please sign in to comment.