Skip to content

Commit

Permalink
type mw.template
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Mar 30, 2021
1 parent 3cd5bcd commit 1b69619
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions mw/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "./Map";
import "./message";
import "./notification";
import "./storage";
import "./template";
import "./Title";
import "./Uri";
import "./user";
Expand Down
70 changes: 70 additions & 0 deletions mw/template.d.ts
Original file line number Diff line number Diff line change
@@ -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 {};

0 comments on commit 1b69619

Please sign in to comment.