1.3.10 • Published 11 months ago

handlebars-laboratory v1.3.10

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Handlebars Laboratory

Handlebars laboratory, service for handlebars template.

npm link

Content

Reference

handlebars document

handlebars github link

html-pdf-node github link

puppeteer github link

Install

$ npm i handlebars-laboratory

Document

init

Before compile template, you must use init to install handlebars helper.

const handlebarsCompiler = require('handlebars-laboratory');
handlebarsCompiler.init({
  RESOURCE_HOST: '', // resource url host
});

What is 'RESOURCE_HOST'?

RESOURCE_HOST is use for image url that, our data url is relative path, so we need to set a host for images resoure host to split a final url by helper 'formatUrl'. If you not need, you can set ''.

installHelpers

For install custom helpers.

const handlebarsCompiler = require('handlebars-laboratory');
const helpers = [{ name: '...', fn: (...) => {...} }];
handlebarsCompiler.installHelpers(helpers);

checkPrefabs

It will check the prefabs(partials) from the xml template. For example, the follow xml will be check and return 'my-prefab'. It can help you to init components dynamically.

<section>
  {{> my-prefab}}
</section>
const handlebarsCompiler = require('handlebars-laboratory');
handlebarsCompiler.checkPrefabs(xml); // return ['my-prefab']

installPrefabs

You should install handlebars prefabs(partials) there.

const handlebarsCompiler = require('handlebars-laboratory');
const prefabs = [{ name: 'my-prefab', content: '<p>{{add a b}}</p>' }];
handlebarsCompiler.installPrefabs(prefabs);

compile

Function to compile template by data.

const xml = '';
const data = {};
const handlebarsCompiler = require('handlebars-laboratory');
const html = handlebarsCompiler.compile(xml, data);

For example:

const html = handlebarsCompiler.compile(xml, { a: 1, b: 2 });

Result Html:

<section>
  <p>3</p>
</section>

BaseHelper

  • array
    • isArray
    • toArray
    • at
    • includes
    • indexOf
    • join
    • unique
    • reverse
    • size
    • link
    • find
    • findIndex
    • filter
    • map
  • date
    • moment
    • timestamp
    • date
  • enum
  • format
    • formatPhone
    • formatUrl
    • formatPrice
  • logical
    • or
    • and
    • eq
    • not
    • gt
    • gte
    • lt
    • lte
    • jug
    • reg
    • match
  • number
    • isNumber
    • toNumber
    • toFixed
    • add
    • minus
    • multiply
    • divide
    • modulo
    • pow
    • abs
    • ceil
    • floor
    • random
    • max
    • min
  • object
    • isObject
    • keys
    • values
    • entries
    • has
    • set
    • clone
    • fromEntries
  • string
    • isString
    • toString
    • substring
    • concat
    • split
    • trim
    • padStart
    • padEnd
  • utils
    • throw
    • parse
    • stringify
1.3.10

11 months ago

1.3.9

11 months ago

1.3.8

1 year ago

1.3.7

1 year ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago