Files
meteor/packages/caching-html-compiler
Sashko Stubailo ec33215a7f Static HTML package and templating refactor
1. Make a package called `static-html` that just compiles `<head>` and `<body>` tags inside `.html` files. Much like templating but without the templates.
2. Refactor `templating` to avoid duplicating code.

Split out code that would be shared between `templating` and `static-html` into a new `templating-tools` package. These tools could also be used to simplify implementation of other build plugins, like `simple:markdown-templating`.

This also has the added benefit of moving as much code as humanly possible out of the `templating` package, so that it can be reused in other packages.

1. `templating-tools` package and its README
2. `static-html` package and its README
3. `caching-html-compiler` is not new code; it is just code factored out of the batch plugin version of `templating`, but the README and some comments are new.

1. `tools/tests/static-html.js` tests static html and error handling
2. `templating-tools/html-scanner-tests.js` tests `scanHtmlForTags` and `compileTagsWithSpacebars` together.

All unit tests pass on this branch.
2015-07-31 10:40:23 -07:00
..

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:

  1. templating
  2. static-html
  3. 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

  1. 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.
  2. tagScannerFunc A function that takes a string representing a template file as input, and returns an array of Tag objects. See the README for templating-tools for more information about the Tag object.
  3. tagHandlerFunc A function that takes an array of Tag objects (the output of the previous argument) and returns an object with js, body, head, and bodyAttr properties, which will be added to the app through the build plugin API.

Example

Here is some example code from the templating package:

Plugin.registerCompiler({
  extensions: ['html'],
  archMatching: 'web',
  isTemplate: true
}, () => new CachingHtmlCompiler(
  "templating",
  TemplatingTools.scanHtmlForTags,
  TemplatingTools.compileTagsWithSpacebars
));