2.2.2 • Published 4 years ago

@linkorgs/html-template v2.2.2

Weekly downloads
11
License
MIT
Repository
github
Last release
4 years ago

Build Status

html-template

The simplest html template engine

Installation

npm install @linkorgs/html-template

or

yarn add @linkorgs/html-template

Usage

import { Render } from "@linkorgs/html-template"                    // ESModule
// const { Render } = require("@linkorgs/html-template")            // commonjs 
const render = new Render()
render.render(`<div>{{ return null || '@linkorgs/html-template' }}</div>`)
// output: <div>@linkorgs/html-template</div>

2.0.1 starts to support asynchronous syntax, the basic usage is as follows

import { Render } from "@linkorgs/html-template"
const render = new Render({
  mini: true
})

void async function() {
  await render.render(`
    <div>
      {{
        return (async function() {
          return await Promise.resolve('@linkorgs/html-template')
        })();
      }}
    </div>
`)
  // output: <div>@linkorgs/html-template</div>
}()

Documentation

Use new Render (options?: object) for initialization and return an instance of Render.

options

  • mini: Whether to compress html content. As with the minify attribute ofhtml-webpack-plugin, use html-minifier to compress HTML content. See List for optional values. The default values are as follows
{
  collapseWhitespace: true,
  removeComments: true,
  removeRedundantAttributes: true,
  removeScriptTypeAttributes: true,
  removeStyleLinkTypeAttributes: true,
  useShortDoctype: true
}

Note: If the value of mini isfalse, nothing will be compressed. If it is true, the above default value will be used

API

  • set (html: string): set the template string to be rendered
  • compiler (template?: string): Returns a prepared array of templates for the render function to compile
  • render (template?: string): render template string and return

Changelog

Detailed changes for each release are documented in the release notes.

LICENSE

MIT

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago