asyncbars

0.2.0 • Public • Published

Asyncbars

Build Status

Asynchronous templating engine using Handlebars syntax.

Example

Query your database right from the template!

index.coffee:

Asyncbars = require 'asyncbars'

renderer = Asyncbars.createRenderer
  eachPost: ->
    Posts.find {}, (err, posts) =>
      if err
        Promise.reject(err)
      else
        Promise.all posts.map (post) =>
          # render body of the helper for each post
          # set context variable `title`
          @cb yes, title: post.title
        .then (strs) -> strs.join('')
  title: -> @ctx.title

nodes = Asyncbars.parseFile 'view.hbs'

renderer.render(nodes).then(console.log)

view.hbs:

<ul>
  {{#eachPost}}
    <li>{{title}}</li>
  {{/eachPost}}
</ul>

Example output:

<ul>
  <li>Foo</li>
  <li>Bar</li>
</ul>

See test/ for more examples.

Todos:

  • [x] Allow quoting helper arguments: {{helper "arg" opt="value"}}
  • [ ] Allow to {{include file.hbs}}
  • [ ] Allow other helpers as helper arguments: {{#if {{isEnabled}} }} class="enabled" {{/if}}

Package Sidebar

Install

npm i asyncbars

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • phaux