bem-xjst
Declarative Template Engine for the browser and server
Last updated a year ago by tadatuta .
MPL-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install bem-xjst 
SYNC missed versions from official npm registry.

bem-xjst

Declarative template engine for the browser and server with regular JS syntax.

NPM version Build Status Dependency Status devDependency Status Coverage Status

Features

Templates are extensible: they can be redefined or extended

You can redefine or extend just a particular part of output not only by simple redefinition via new templates but also using ‘modes’. E.g. it may be a tag name or its content.

block('link')({ tag: 'span' });
// The template sets tag to `span` for all `link` blocks.
// And tag mode can be redefined if any condition passed.

block('link').match((node, ctx) => ctx.url)({ tag: 'a' });
// The template sets tag to `a` only if block `link` have `url` field.
// Otherwise tag will be ‘span’ as previous template says.

Pattern matching

Templates are written using pattern matching for the values and structure of input data

block('list')({ tag: 'ul' });
block('item')({ tag: 'li' });

We can apply these two declarative-style templates templates to data:

{
  block: 'list',
  content: [
    {
      block: 'item',
      content: {
          block: 'list',
          content: [
              { block: 'item', content: 'CSS' },
              { block: 'item', content: 'HTML' }
          ]
      }
    },
    {
      block: 'item',
      content: {
          block: 'list',
          content: { block: 'item', content: 'JS' }
      }
    }
  ] 
}

The result is:

<ul class="list">
    <li class="item">
        <ul class="list">
            <li class="item">CSS</li>
            <li class="item">HTML</li>
        </ul>
    </li>
    <li class="item">
        <ul class="list">
            <li class="item">JS</li>
        </ul>
    </li>
</ul>

As you can see templates are as simple as CSS.

Automatic recursive traversing upon input data

In the example above you may have noticed that bem-xjst automaticaly traverses input data by content fields. This behaviour is default feature of bem-xjst.

Default rendering

Built-in rendering behavior is used by default, even if the user didn’t add templates. Even without templates. For example from above it will be:

<div class="list">
    <div class="item">
        <div class="list">
            <div class="item">CSS</div>
            <div class="item">HTML</div>
        </div>
    </div>
    <div class="item">
        <div class="list">
            <div class="item">JS</div>
        </div>
    </div>
</div>

That is more than half of the work ;) You will add the salt (couple of templates for tags) and the HTML-soup is very tasty!

No DSL, only JavaScript

Written in JavaScript, so the entire JavaScript infrastructure is available for checking code quality and conforming to best practices.

Since templates is a regular JavaScript code you can use automatic syntax validator from your editor and tools like JSHint/ESLint.

Runs on a server and client

You can use bem-xjst in any browser as well as in any JavaScript VM. We support Node.JS v0.10 and higher.

Tell me more

See documentation:

  1. About
  2. Quick Start
  3. API: usage, methods, signatures and etc
  4. Input data format: BEMJSON
  5. Templates syntax
  6. Templates context
  7. Runtime: processes for selecting and applying templates

Try it

Online sandbox

Online demo allows you to share code snippets, change versions and etc. Happy templating!

Install npm package

To compile bem-xjst, you need Node.js v0.10 or later, and npm.

npm install bem-xjst

Copy-paste example from quick start or see simple example from repository. Then read documentation and start experimenting with bem-xjst.

Is bem-xjst used in production?

Yes. A lot of projects in Yandex and Alfa-Bank, also in opensource projects based on bem-core and bem-components.

Benchmarks

See readme.

Runtime linter

See readme.

Static linter and migration tool for templates

See readme.

Links

Current Tags

  • 7.6.4                                ...           bemtree-html-fix-in-7.x (4 years ago)
  • 7.4.1                                ...           extend-fix-port-to-7.x (4 years ago)
  • 7.6.1                                ...           extendArgumentsPort (4 years ago)
  • 8.9.6                                ...           latest (a year ago)
  • 4.4.2-rc                                ...           match-fix-4.4.2 (4 years ago)
  • 6.7.1                                ...           memory-lick-fix-in-6.x (4 years ago)
  • 7.7.4-beta-1                                ...           more-compact-bundle-7.7.4-beta (4 years ago)
  • 7.5.0                                ...           omitOptionalEndTags-to-v7.x (4 years ago)
  • 7.7.1                                ...           optimizeBundleIn7x (4 years ago)
  • 7.6.2                                ...           positionFixIn7x (4 years ago)
  • 5.2.0                                ...           production-opt-in-5x (4 years ago)
  • 6.7.0                                ...           production-opt-in-6x (4 years ago)
  • 7.4.0                                ...           production-opt-in-7x (4 years ago)
  • 7.7.3                                ...           revert-exportApply-optimizatio (4 years ago)
  • 4.4.1                                ...           revertApplyNextFromV4x (4 years ago)
  • 7.6.3                                ...           revertPositionFixIn7x (4 years ago)
  • 6.7.2                                ...           runtime-lint-fix-6.7.2 (3 years ago)
  • 7.7.7                                ...           runtime-lint-fix-7.7.7 (3 years ago)
  • 0.3.4                                ...           stable (7 years ago)
  • 7.7.0                                ...           static-analize-in-7x (4 years ago)
  • 4.4.0                                ...           support-4.x (4 years ago)
  • 6.5.5                                ...           support-6.x (4 years ago)
  • 7.7.2                                ...           unquotedAttrs-fix (4 years ago)
  • 7.6.0                                ...           unquotedAttrsBackport (4 years ago)

178 Versions

  • 8.9.6                                ...           a year ago
  • 8.9.5                                ...           2 years ago
  • 7.8.1                                ...           2 years ago
  • 8.9.4                                ...           2 years ago
  • 7.8.0                                ...           2 years ago
  • 8.9.3                                ...           3 years ago
  • 8.9.2                                ...           3 years ago
  • 8.9.2-rc.2                                ...           3 years ago
  • 8.9.2-rc.1                                ...           3 years ago
  • 7.7.7                                ...           3 years ago
  • 6.7.2                                ...           3 years ago
  • 8.9.2-rc.0                                ...           3 years ago
  • 8.9.1                                ...           3 years ago
  • 8.9.0                                ...           3 years ago
  • 8.9.0-rc.2                                ...           3 years ago
  • 8.8.8                                ...           3 years ago
  • 8.9.0-rc.1                                ...           3 years ago
  • 8.8.8-rc.1                                ...           3 years ago
  • 8.8.7                                ...           3 years ago
  • 8.8.7-rc.0                                ...           3 years ago
  • 8.8.6                                ...           3 years ago
  • 8.9.0-rc.0                                ...           3 years ago
  • 8.8.5                                ...           3 years ago
  • 8.8.4                                ...           3 years ago
  • 8.8.3                                ...           3 years ago
  • 8.8.2                                ...           3 years ago
  • 8.8.1                                ...           3 years ago
  • 8.8.0                                ...           3 years ago
  • 7.7.6                                ...           3 years ago
  • 7.7.5                                ...           3 years ago
  • 8.7.1                                ...           3 years ago
  • 8.7.0                                ...           3 years ago
  • 8.6.13                                ...           3 years ago
  • 8.6.12                                ...           3 years ago
  • 6.7.1                                ...           4 years ago
  • 7.7.4                                ...           4 years ago
  • 8.6.11                                ...           4 years ago
  • 8.6.10                                ...           4 years ago
  • 8.6.9                                ...           4 years ago
  • 8.6.8                                ...           4 years ago
  • 7.7.4-beta-7                                ...           4 years ago
  • 7.7.4-beta-6                                ...           4 years ago
  • 7.7.4-beta-5                                ...           4 years ago
  • 7.7.4-beta-4                                ...           4 years ago
  • 7.7.4-beta-3                                ...           4 years ago
  • 7.7.4-beta-2                                ...           4 years ago
  • 7.7.4-beta-1                                ...           4 years ago
  • 4.4.2-rc                                ...           4 years ago
  • 8.6.7                                ...           4 years ago
  • 8.6.6                                ...           4 years ago
  • 7.7.3                                ...           4 years ago
  • 8.6.5                                ...           4 years ago
  • 7.7.2                                ...           4 years ago
  • 8.6.4                                ...           4 years ago
  • 8.6.3                                ...           4 years ago
  • 8.6.2                                ...           4 years ago
  • 7.7.1                                ...           4 years ago
  • 8.6.1                                ...           4 years ago
  • 7.7.0                                ...           4 years ago
  • 8.6.0                                ...           4 years ago
  • 8.5.2                                ...           4 years ago
  • 7.6.4                                ...           4 years ago
  • 7.6.3                                ...           4 years ago
  • 7.6.2                                ...           4 years ago
  • 8.5.1                                ...           4 years ago
  • 8.5.0                                ...           4 years ago
  • 8.4.2                                ...           4 years ago
  • 7.6.1                                ...           4 years ago
  • 8.4.1                                ...           4 years ago
  • 7.6.0 [deprecated]           ...           4 years ago
  • 8.4.0 [deprecated]           ...           4 years ago
  • 4.4.1                                ...           4 years ago
  • 7.5.0 [deprecated]           ...           4 years ago
  • 7.4.1 [deprecated]           ...           4 years ago
  • 8.3.1 [deprecated]           ...           4 years ago
  • 8.3.0 [deprecated]           ...           4 years ago
  • 7.4.0 [deprecated]           ...           4 years ago
  • 6.7.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 8.2.0 [deprecated]           ...           4 years ago
  • 8.1.0 [deprecated]           ...           4 years ago
  • 8.0.0 [deprecated]           ...           4 years ago
  • 7.3.1 [deprecated]           ...           4 years ago
  • 7.3.0 [deprecated]           ...           4 years ago
  • 7.2.0 [deprecated]           ...           4 years ago
  • 6.6.0 [deprecated]           ...           4 years ago
  • 7.1.0 [deprecated]           ...           4 years ago
  • 7.0.4 [deprecated]           ...           4 years ago
  • 4.4.0 [deprecated]           ...           4 years ago
  • 6.5.5 [deprecated]           ...           4 years ago
  • 7.0.3 [deprecated]           ...           4 years ago
  • 6.5.4 [deprecated]           ...           4 years ago
  • 7.0.2 [deprecated]           ...           4 years ago
  • 7.0.1 [deprecated]           ...           4 years ago
  • 6.5.3 [deprecated]           ...           4 years ago
  • 4.3.7 [deprecated]           ...           4 years ago
  • 4.3.6 [deprecated]           ...           4 years ago
  • 4.3.5 [deprecated]           ...           4 years ago
  • 7.0.0 [deprecated]           ...           4 years ago
  • 6.5.2 [deprecated]           ...           4 years ago
  • 6.5.1 [deprecated]           ...           5 years ago
  • 6.5.0 [deprecated]           ...           5 years ago
  • 6.4.3 [deprecated]           ...           5 years ago
  • 6.4.2 [deprecated]           ...           5 years ago
  • 6.4.1 [deprecated]           ...           5 years ago
  • 6.4.0 [deprecated]           ...           5 years ago
  • 6.3.1 [deprecated]           ...           5 years ago
  • 6.3.0 [deprecated]           ...           5 years ago
  • 6.2.1 [deprecated]           ...           5 years ago
  • 6.2.0 [deprecated]           ...           5 years ago
  • 6.1.1 [deprecated]           ...           5 years ago
  • 6.1.0 [deprecated]           ...           5 years ago
  • 6.0.1 [deprecated]           ...           5 years ago
  • 6.0.0 [deprecated]           ...           5 years ago
  • 5.1.0                                ...           5 years ago
  • 4.3.4 [deprecated]           ...           5 years ago
  • 5.0.0 [deprecated]           ...           5 years ago
  • 4.3.3                                ...           5 years ago
  • 4.3.2 [deprecated]           ...           5 years ago
  • 4.3.1 [deprecated]           ...           5 years ago
  • 4.3.0 [deprecated]           ...           5 years ago
  • 4.2.7 [deprecated]           ...           5 years ago
  • 4.2.6 [deprecated]           ...           5 years ago
  • 4.2.5 [deprecated]           ...           5 years ago
  • 4.2.4 [deprecated]           ...           5 years ago
  • 4.2.3 [deprecated]           ...           5 years ago
  • 4.2.2 [deprecated]           ...           5 years ago
  • 4.2.1 [deprecated]           ...           5 years ago
  • 4.2.0 [deprecated]           ...           5 years ago
  • 4.1.0 [deprecated]           ...           5 years ago
  • 4.0.2 [deprecated]           ...           5 years ago
  • 4.0.1 [deprecated]           ...           5 years ago
  • 1.2.1 [deprecated]           ...           5 years ago
  • 1.2.0 [deprecated]           ...           5 years ago
  • 4.0.0 [deprecated]           ...           5 years ago
  • 3.1.1 [deprecated]           ...           5 years ago
  • 3.1.0 [deprecated]           ...           5 years ago
  • 1.0.4 [deprecated]           ...           5 years ago
  • 3.0.1 [deprecated]           ...           5 years ago
  • 3.0.0 [deprecated]           ...           5 years ago
  • 2.0.1 [deprecated]           ...           5 years ago
  • 1.0.3 [deprecated]           ...           5 years ago
  • 1.0.2 [deprecated]           ...           5 years ago
  • 1.0.0 [deprecated]           ...           6 years ago
  • 0.9.0 [deprecated]           ...           6 years ago
  • 0.8.3 [deprecated]           ...           6 years ago
  • 0.8.2 [deprecated]           ...           6 years ago
  • 0.8.1 [deprecated]           ...           6 years ago
  • 0.8.0 [deprecated]           ...           6 years ago
  • 0.7.1 [deprecated]           ...           6 years ago
  • 0.7.0 [deprecated]           ...           6 years ago
  • 0.6.1 [deprecated]           ...           7 years ago
  • 0.6.0 [deprecated]           ...           7 years ago
  • 0.5.0 [deprecated]           ...           7 years ago
  • 0.4.0 [deprecated]           ...           7 years ago
  • 0.3.6 [deprecated]           ...           7 years ago
  • 0.3.5 [deprecated]           ...           7 years ago
  • 0.3.4 [deprecated]           ...           7 years ago
  • 0.3.3 [deprecated]           ...           7 years ago
  • 0.3.2 [deprecated]           ...           7 years ago
  • 0.3.1 [deprecated]           ...           7 years ago
  • 0.3.0 [deprecated]           ...           7 years ago
  • 0.2.5 [deprecated]           ...           7 years ago
  • 0.2.4 [deprecated]           ...           7 years ago
  • 0.2.3 [deprecated]           ...           7 years ago
  • 0.2.2 [deprecated]           ...           7 years ago
  • 0.2.1 [deprecated]           ...           8 years ago
  • 0.2.0 [deprecated]           ...           8 years ago
  • 0.1.5 [deprecated]           ...           8 years ago
  • 0.1.4 [deprecated]           ...           8 years ago
  • 0.1.2 [deprecated]           ...           8 years ago
  • 0.1.1 [deprecated]           ...           8 years ago
  • 0.1.0 [deprecated]           ...           8 years ago
  • 0.0.6 [deprecated]           ...           8 years ago
  • 0.0.5 [deprecated]           ...           8 years ago
  • 0.0.4 [deprecated]           ...           8 years ago
  • 0.0.3 [deprecated]           ...           8 years ago
  • 0.0.2 [deprecated]           ...           8 years ago

Copyright 2014 - 2017 © taobao.org |