@appium/typedoc-plugin-appium
Version:
TypeDoc plugin for Appium & its extensions
64 lines • 2.73 kB
JavaScript
;
/**
* Custom Handlebars helpers
* @module
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerHelpers = void 0;
const handlebars_1 = __importDefault(require("handlebars"));
const typedoc_1 = require("typedoc");
const model_1 = require("../model");
const pluralize_1 = __importDefault(require("pluralize"));
/**
* Overwrites {@linkcode typedoc-plugin-markdown#MarkdownTheme}'s `reflectionPath` helper to handle {@linkcode AppiumPluginReflectionKind} reflection kinds
* @param this Page event
* @returns Reflection path, if any
*/
function reflectionPath() {
if (this.model) {
if (this.model.kind && this.model.kind !== typedoc_1.ReflectionKind.Module) {
if (this.model.kind === model_1.AppiumPluginReflectionKind.Driver) {
return `${this.model.name} Driver`;
}
else if (this.model.kind === model_1.AppiumPluginReflectionKind.Plugin) {
return `${this.model.name} Plugin`;
}
const title = [];
if (this.model.parent && this.model.parent.parent) {
if (this.model.parent.parent.parent) {
title.push(`[${this.model.parent.parent.name}](${handlebars_1.default.helpers.relativeURL(this.model?.parent?.parent.url)})`);
}
title.push(`[${this.model.parent.name}](${handlebars_1.default.helpers.relativeURL(this.model.parent.url)})`);
}
title.push(this.model.name);
return title.length > 1 ? `${title.join('.')}` : null;
}
}
return null;
}
/**
* Helper to "pluralize" a string.
* @param value String to pluralize
* @param count Number of items to consider
* @param inclusive Whether to show the count in the output
* @returns The pluralized string (if necessary)
*/
function pluralize(value, count, inclusive = false) {
const safeValue = handlebars_1.default.escapeExpression(value);
// XXX: Handlebars seems to be passing in a truthy value here, even if the arg is unused in the template! Make double-sure it's a boolean.
inclusive = inclusive === true;
const pluralValue = (0, pluralize_1.default)(safeValue, count, inclusive);
return new handlebars_1.default.SafeString(pluralValue);
}
/**
* Registers all custom helpers with Handlebars
*/
function registerHelpers() {
handlebars_1.default.registerHelper('reflectionPath', reflectionPath);
handlebars_1.default.registerHelper('pluralize', pluralize);
}
exports.registerHelpers = registerHelpers;
//# sourceMappingURL=helpers.js.map