seba:static-html-compiler

v1.0.0Published 6 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

meteor-static-html-compiler

A tool that allows you to compile static HTML templates so you could import them from a module.

Installation

meteor add urigo:static-html-compiler

If you are looking for a package with a working implementation of this tool you should check static-templates.

Example

1import {
2  MainHtmlCompiler, // body, head
3  TemplateHtmlCompiler, // templates
4  StaticHtmlCompiler,
5  utils,
6} from 'meteor/urigo:static-html-compiler';
7
8class TemplateCacheCompiler extends TemplateHtmlCompiler {
9  compileContents(file, contents) {
10    const template = utils.clean(contents);
11    return `module.exports = "${template}"`;
12  }
13}
14
15Plugin.registerCompiler({
16  extensions: ['html']
17}, () => new StaticHtmlCompiler(new MainHtmlCompiler, new TemplateCacheCompiler));
18

API

StaticHtmlCompiler

Compiles a html file to a string by default

constructor(MainHtmlCompiler?, TemplateHtmlCompiler?)

It is possible to change the way StaticHtmlCompiler works by providing custom MainHtmlCompiler and TemplateHtmlCompiler.

MainHtmlCompiler

Handles files that contain <head/> or <body/> tag.

TemplateHtmlCompiler

Handles files that do not contain <head/> and <body/> tags.

compileContents(file, contents: string): string

Returns contents of a ES6 module that will be later compiled from a string to JavaScript code.

utils

clean (html: string): string

Cleans up HTML.

minify (html: string): string

Minifies HTML.