1.1.0 • Published 9 years ago

mustache-stream v1.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

mustache-stream Build Status js-standard-style

Mustache template renderer for streaming JavaScript objects.

Installation

$ npm install mustache-stream

Test:

$ npm test

API

mustacheStream(template, options)

  • template

Can be either a string or a function, if it's a function this will be called each time; thus providing the ability to dynamically load templates which is useful for testing.

  • options

An optional object with the following options: transform, prepend, append.

  • transform

A function that supplies the current object in the stream which can be modified synchronously. Also the $index key (the nth object in the stream) is provided.

  • prepend

A string value which will be added to the beginning of the (whole) stream.

  • append

A string value added to the end of the stream.

Mustache templates options and logic are exactly as in the Mustache module.

Example

See test.js and template.mustache for details.

// assume object stream is here
.pipe(mustacheStream(template, {
  transform: function (values) {
    values.$index++
    values.accessDate = new Date().toString()
    return values
  },
  prepend: '<html><body style="font-family: sans-serif"><h1>Repos</h1><ul>',
  append: '</ul><p><b>License:</b> MIT</p></body></html>'
}))

License

MIT

1.1.0

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.1

9 years ago