• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server

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

More Repositories

1

bem-react

A set of tools for developing user interfaces using the BEM methodology in React
TypeScript
440
star
2

yandex-ui

Yandex UI Kit build on React and bem-react
TypeScript
352
star
3

bem-components

Set of components for sites development
JavaScript
332
star
4

project-stub

deps
JavaScript
313
star
5

bem-core

BEM Core Library
JavaScript
275
star
6

html-differ

Сompares two HTML
JavaScript
211
star
7

bem-bl

Base BEM library
JavaScript
197
star
8

bem-sdk

BEM SDK packages
JavaScript
88
star
9

next-global-css

A preset for nextjs allowing using 3d party libraries with global css
JavaScript
86
star
10

themekit

Build system of design-tokens for any platforms
TypeScript
73
star
11

bh

BH template engine
JavaScript
68
star
12

bem-express

BEM project-stub with BEMTREE and express
JavaScript
43
star
13

bh-php

PHP port of https://github.com/bem/bh. It's cool thing but better use this:
PHP
33
star
14

bem-react-boilerplate

DEPRECATED! A bare minimum frontend boilerplate based on create-react-app and bem-react-core.
TypeScript
31
star
15

sssr

Master class for BEMup
JavaScript
30
star
16

bem-react-components

Components library for develop with React and BEM methodology
JavaScript
29
star
17

bem-mvc

Yet another MVC for i-bem
JavaScript
29
star
18

web-platform

React SDK for building modern, accessible and cross-platforms interfaces
TypeScript
28
star
19

gulp-bem

Usefull gulp modules and plugins to work with BEM methodology
JavaScript
25
star
20

webpack-bem-loader

Webpack BEM loader
JavaScript
24
star
21

bem-history

BEM wrap for History API
JavaScript
22
star
22

bem-identity

BEM brand identity
20
star
23

bem-calendar

calendar based on bem-components
JavaScript
16
star
24

storybook-to-figma

The tool for importing Storybook components to Figma
TypeScript
15
star
25

yandex-ui-icons

TypeScript
13
star
26

yandex-ui-themer

A simple way to create your theme for @yandex/ui with Themekit
TypeScript
12
star
27

babel-plugin-bem-import

BEM import resolver
JavaScript
9
star
28

eslint-plugin-bem-xjst

ESLint environments for bem-xjst
JavaScript
9
star
29

bem-components-php

Set of bh.php templates for bem-components library
PHP
9
star
30

figma-extractor

TypeScript
8
star
31

bem-components-dist

Prebuilt version of bem-components library
JavaScript
8
star
32

jscs-bem

jscs bem preset and some tasty rules
JavaScript
6
star
33

bem-forum

BEM forum on top of github issues
JavaScript
6
star
34

bem-core-dist

Prebuilt version of bem-core library
JavaScript
6
star
35

bem-core-php

bh.php templates for bem-core
PHP
5
star
36

babel-plugin-bem

Babel plugin BEM
JavaScript
5
star
37

ts-docgen-next

Webpack loader for generating documentation from typescript files.
TypeScript
4
star
38

jsd

JSDoc parser
JavaScript
4
star
39

cra-template-yandex-ui

TypeScript
2
star
40

bem-jsdoc3-plugin

Plugin for http://usejsdoc.org/ for documenting bem enteties
JavaScript
2
star
41

es5-shims

es5 shims moved from bem-core
JavaScript
2
star
42

webpack-bem-plugin

JavaScript
1
star
43

design-system

TypeScript
1
star
44

webpack-bem-i18n-loader

JavaScript
1
star
45

bem-jsd

Wrapper for use JSD with BEM plugins
JavaScript
1
star