caching-html-compiler
Provides a pluggable class used to compile HTML-style templates in Meteor build plugins. This abstracts out a lot of the functionality you would need to implement the following plugins:
templating
static-html
simple:markdown-templating
It provides automatic caching and handles communicating with the build plugin APIs. The actual functions that convert HTML into compiled form are passed in as arguments into the constructor, allowing those functions to be unit tested separately from the caching and file system functionality.
new CachingHtmlCompiler(name, tagScannerFunc, tagHandlerFunc)
Constructs a new CachingHtmlCompiler that can be passed into Plugin.registerCompiler
.
Arguments
name
The name of the compiler, used when printing errors. Should probably be the same as the name of the build plugin and package it is used in.tagScannerFunc
A function that takes a string representing a template file as input, and returns an array of Tag objects. See the README fortemplating-tools
for more information about the Tag object.tagHandlerFunc
A function that takes an array of Tag objects (the output of the previous argument) and returns an object withjs
,body
,head
, andbodyAttr
properties, which will be added to the app through the build plugin API.
Example
Here is some example code from the templating
package:
1Plugin.registerCompiler({ 2 extensions: ['html'], 3 archMatching: 'web', 4 isTemplate: true 5}, () => new CachingHtmlCompiler( 6 "templating", 7 TemplatingTools.scanHtmlForTags, 8 TemplatingTools.compileTagsWithSpacebars 9));