sejs

0.2.1 • Public • Published

sEJS npm Version Build Status Coverage Status

Embedded JavaScript templates without the bells and whistles.

Why

sEJS spun out of an endeavor to understand how JavaScript templating (in the vein of ERB or PHP) works. It is:

Usage

var tmpl = '<% if (foo) { %>' +
           '<%= foo.bar %>, <%= foo.baz %>!' +
           '<% } %>';
var data = {
  foo: {
    bar: 'Hello',
    baz: 'World'
  }
};
 
sejs(tmpl)(data); //=> 'Hello, World!'

Place JavaScript between <% and %> tags. To print a variable, use <%= for the opening tag.

API

sejs(tmpl)(data)

Returns a String, the result of rendering tmpl using values from data.

  • tmpl — The template String.
  • data — An Object literal of values.

Installation

Install via npm:

$ npm i --save sejs

Install via bower:

$ bower i --save yuanqing/sejs

To use sEJS in the browser, include the minified script in your HTML:

<body>
  <!-- ... -->
  <script src="path/to/sejs.min.js"></script> 
  <script>
    // sejs available here
  </script> 
</body>

Changelog

  • 0.2.0
    • sejs(tmpl)(data) replaces sejs.render(tmpl, data)
    • Remove sejs.renderFile(tmplFile, data, cb)
    • Add bower.json
    • Add a minified version of the module
  • 0.1.0
    • Initial release

License

MIT license

Package Sidebar

Install

npm i sejs

Weekly Downloads

0

Version

0.2.1

License

MIT

Last publish

Collaborators

  • yuanqing