npm install pixie> Tiny template engine
``js
var pixie = require('pixie')
// Parse a template
var template = pixie.parse('foo {{bar}} baz', '{{', '}}')
// => [['foo ', ' baz'], ['bar']]
// Compile (using simple default)
pixie.compile(template, { bar: 'Baaar!' })
// => 'foo Baaar! baz'
`
Pixie is a tiny template engine (321 bytes uglified and 27 SLOC) that creates templates as arrays of strings. This lets you use alternative compilers to support only the syntax you want, precompile templates, or serialize templates as JSON. See the pixie keyword on npm for more packages.
`sh`
$ npm i pixie
Parse the source into a template. This is passed off to a compile (e.g. pixie.compile or others)
- source: The template string source being parsedopen
- : Tag for opening expressionsclose
- : Tag for closing expressions
`js
// Parse with tags
pixie.parse('Hello {{world}} foo {{bar}} baz.', '{{', '}}')
// Parse with alternative tags
pixie.parse('Hello <%world%>!', '<%', '%>')
`
A simple compiler, substitutes properties from an object by name
- template: A template object that was returned from pixie.parsedata
- : An object/array that you want to insert the data into the expressions
`js
// Parse a template
var template = pixie.parse('foo {{bar}} baz {{qux}}')
// Compile template
pixie.compile(template, { bar: 'baaar', qux: 'quuux' })
// => 'foo baaar baz quuux'
`
The template structure is an array, containing two other arrays recognized as [fragments, expressions]
- Expressions: Data between the opening and closing points. In Foo {{bar}} baz {{qux}} they would be ['bar', 'qux']['Foo ', ' baz', '']
- Fragments: Data around your expressions. In the same example, the fragments would be
Compilers can choose to interpret and compile these however they choose. The pixie.compile` ones is just a simple point-n-place
MIT © Jamen Marz
---
     