-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cd5bcd
commit 1b69619
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |