From 1b6961951f44a6812e8237a02be3de6c83c01022 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Wed, 31 Mar 2021 02:19:11 +0530 Subject: [PATCH] type mw.template --- mw/index.d.ts | 1 + mw/template.d.ts | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 mw/template.d.ts diff --git a/mw/index.d.ts b/mw/index.d.ts index ace338b..2de8163 100644 --- a/mw/index.d.ts +++ b/mw/index.d.ts @@ -10,6 +10,7 @@ import "./Map"; import "./message"; import "./notification"; import "./storage"; +import "./template"; import "./Title"; import "./Uri"; import "./user"; diff --git a/mw/template.d.ts b/mw/template.d.ts new file mode 100644 index 0000000..c61ca44 --- /dev/null +++ b/mw/template.d.ts @@ -0,0 +1,70 @@ +type CompiledTemplate = any; // Can this be made more specific? + +interface Compiler { + compile: ((src: string) => CompiledTemplate); +} + +declare global { + namespace mw { + /** + * Register a new compiler. + * + * A compiler is any object that implements a compile() method. The compile() method must + * return a Template interface with a method render() that returns HTML. + * + * The compiler name must correspond with the name suffix of templates that use this compiler. + * + * @param {string} name Compiler name + * @param {Object} compiler + */ + function registerCompiler(name: string, compiler: Compiler): void; + + /** + * Get the name of the associated compiler based on a template name. + * + * @param {string} templateName Name of a template (including suffix) + * @return {string} Name of a compiler + */ + function getCompilerName(templateName: string): string; + + /** + * Get a compiler via its name. + * + * @param {string} name Name of a compiler + * @return {Object} The compiler + */ + function getCompiler(name: string): Compiler; + + /** + * Register a template associated with a module. + * + * Precompiles the newly added template based on the suffix in its name. + * + * @param {string} moduleName Name of the ResourceLoader module the template is associated with + * @param {string} templateName Name of the template (including suffix) + * @param {string} templateBody Contents of the template (e.g. html markup) + * @return {Object} Compiled template + */ + function add(moduleName: string, templateName: string, templateBody: string): CompiledTemplate; + + /** + * Get a compiled template by module and template name. + * + * @param {string} moduleName Name of the module to retrieve the template from + * @param {string} templateName Name of template to be retrieved + * @return {Object} Compiled template + */ + function get(moduleName: string, templateName: string): CompiledTemplate; + + /** + * Compile a string of template markup with an engine of choice. + * + * @param {string} templateBody Template body + * @param {string} compilerName The name of a registered compiler + * @return {Object} Compiled template + */ + function compile(templateBody: string, compilerName: string): CompiledTemplate; + } +} + +export {};