@appium/typedoc-plugin-appium
Version:
TypeDoc plugin for Appium & its extensions
122 lines • 6.25 kB
JavaScript
;
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _AppiumTheme_instances, _AppiumTheme_extensionTemplateRenderer, _AppiumTheme_log, _AppiumTheme_opts, _AppiumTheme_createTemplateRenderer;
Object.defineProperty(exports, "__esModule", { value: true });
exports.configureTheme = exports.AppiumTheme = exports.THEME_NAME = void 0;
const lodash_1 = __importDefault(require("lodash"));
const typedoc_plugin_markdown_1 = require("typedoc-plugin-markdown");
const logger_1 = require("../logger");
const model_1 = require("../model");
const options_1 = require("../options");
const helpers_1 = require("./helpers");
const template_1 = require("./template");
/**
* Name of the theme; used at definition time
*/
exports.THEME_NAME = 'appium';
/**
* This theme uses everything from `MarkdownTheme` and adds a new section for commands.
*/
class AppiumTheme extends typedoc_plugin_markdown_1.MarkdownTheme {
/**
* Creates template renderers and registers all {@linkcode Handlebars} helpers.
* @param renderer - TypeDoc renderer
*
* @todo Use declaration merging to add an instance of `AppiumPluginLogger` to `Application`,
* which we can then reference here.
*/
constructor(renderer) {
super(renderer);
_AppiumTheme_instances.add(this);
/**
* A template renderer for `CommandReflection`s
*/
_AppiumTheme_extensionTemplateRenderer.set(this, void 0);
/**
* Custom logger. This is not the same as the one created by the plugin loader.
*/
_AppiumTheme_log.set(this, void 0);
/**
* Options specific to this plugin
*/
_AppiumTheme_opts.set(this, void 0);
__classPrivateFieldSet(this, _AppiumTheme_log, new logger_1.AppiumPluginLogger(renderer.owner.logger, `${model_1.NS}:theme`), "f");
__classPrivateFieldSet(this, _AppiumTheme_extensionTemplateRenderer, __classPrivateFieldGet(this, _AppiumTheme_instances, "m", _AppiumTheme_createTemplateRenderer).call(this, template_1.AppiumThemeTemplate.Extension), "f");
__classPrivateFieldSet(this, _AppiumTheme_opts, lodash_1.default.fromPairs(Object.keys(options_1.declarations).map((name) => [[name, this.application.options.getValue(name)]])), "f");
/**
* We do not want to show breadcrumbs by default, but `MarkdownTheme` does. We cannot override
* default value of the `hideBreadcrumbs` option, but we can add a new one, which is what we've done;
* if the `forceBreadcrumbs` option is not truthy, then we will hide breadcrumbs.
*/
this.hideBreadcrumbs = !__classPrivateFieldGet(this, _AppiumTheme_opts, "f").forceBreadcrumbs;
// this ensures we can overwrite MarkdownTheme's Handlebars helpers
(0, helpers_1.registerHelpers)();
}
/**
* Special-cases `ExtensionReflection` instances to make the filename shorter and thus better
* suitable for `mkdocs`.
* @param reflection Reflection to get URL for
* @returns String URL
*/
getUrl(reflection) {
if (reflection.kindOf(model_1.AppiumPluginReflectionKind.Extension)) {
// I don't know what this replace is for, but the superclass does it, so maybe it's important.
return reflection.getAlias().replace('^_', '');
}
return super.getUrl(reflection);
}
/**
/**
* A lookup of {@linkcode ReflectionKind}s to templates. It also controls in which directory the output files live.
*
* This is part of {@linkcode MarkdownTheme} and adds a new template.
*
* If `isLeaf` is `false`, the model gets its own document.
*/
get mappings() {
return [
{
kind: [model_1.AppiumPluginReflectionKind.Extension],
isLeaf: false,
directory: this.application.options.getValue(options_1.declarations.commandsDir.name),
template: __classPrivateFieldGet(this, _AppiumTheme_extensionTemplateRenderer, "f"),
},
...super.mappings,
];
}
}
exports.AppiumTheme = AppiumTheme;
_AppiumTheme_extensionTemplateRenderer = new WeakMap(), _AppiumTheme_log = new WeakMap(), _AppiumTheme_opts = new WeakMap(), _AppiumTheme_instances = new WeakSet(), _AppiumTheme_createTemplateRenderer = function _AppiumTheme_createTemplateRenderer(template) {
const render = (0, template_1.compileTemplate)(template);
return (pageEvent) => {
__classPrivateFieldGet(this, _AppiumTheme_log, "f").verbose('Rendering template for model %s', pageEvent.model.name);
return render(pageEvent, {
allowProtoMethodsByDefault: true,
allowProtoPropertiesByDefault: true,
data: { theme: this },
});
};
};
/**
* Registers {@linkcode AppiumTheme} with TypeDoc.
* @param app TypeDoc application
*/
function configureTheme(app) {
app.renderer.defineTheme(exports.THEME_NAME, AppiumTheme);
return app;
}
exports.configureTheme = configureTheme;
//# sourceMappingURL=index.js.map