{"id":18264861,"url":"https://github.com/bem/bem-xjst","last_synced_at":"2025-04-07T09:17:34.678Z","repository":{"id":48711334,"uuid":"10028367","full_name":"bem/bem-xjst","owner":"bem","description":"bem-xjst (eXtensible JavaScript Templates): declarative template engine for the browser and server","archived":false,"fork":false,"pushed_at":"2021-07-13T14:00:06.000Z","size":2492,"stargazers_count":116,"open_issues_count":50,"forks_count":48,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-31T08:09:27.565Z","etag":null,"topics":["bem","declarative","html-builder","javascript","pattern-matching","template-engine","view"],"latest_commit_sha":null,"homepage":"https://bem.github.io/bem-xjst","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bem.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-13T09:22:05.000Z","updated_at":"2024-10-03T01:21:54.000Z","dependencies_parsed_at":"2022-09-07T17:35:22.736Z","dependency_job_id":null,"html_url":"https://github.com/bem/bem-xjst","commit_stats":null,"previous_names":[],"tags_count":170,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem%2Fbem-xjst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem%2Fbem-xjst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem%2Fbem-xjst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bem%2Fbem-xjst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bem","download_url":"https://codeload.github.com/bem/bem-xjst/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247622986,"owners_count":20968575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bem","declarative","html-builder","javascript","pattern-matching","template-engine","view"],"created_at":"2024-11-05T11:16:20.327Z","updated_at":"2025-04-07T09:17:34.649Z","avatar_url":"https://github.com/bem.png","language":"JavaScript","readme":"# bem-xjst\n\nDeclarative template engine for the browser and server with regular JS syntax.\n\n[![NPM version](http://img.shields.io/npm/v/bem-xjst.svg?style=flat)](http://www.npmjs.org/package/bem-xjst)\n[![Build Status](http://img.shields.io/travis/bem/bem-xjst/master.svg)](https://travis-ci.org/bem/bem-xjst)\n[![Dependency Status](https://david-dm.org/bem/bem-xjst.svg)](https://david-dm.org/bem/bem-xjst)\n[![devDependency Status](https://david-dm.org/bem/bem-xjst/dev-status.svg)](https://david-dm.org/bem/bem-xjst#info=devDependencies)\n[![Coverage Status](https://coveralls.io/repos/github/bem/bem-xjst/badge.svg?branch=coverage-badge)](https://coveralls.io/github/bem/bem-xjst?branch=coverage-badge)\n\n## Features\n\n### Templates are extensible: they can be redefined or extended\n\nYou can redefine or extend just a particular part of output not only by simple\nredefinition via new templates but also using ‘modes’. E.g. it may be a tag name\nor its content.\n\n```js\nblock('link')({ tag: 'span' });\n// The template sets tag to `span` for all `link` blocks.\n// And tag mode can be redefined if any condition passed.\n\nblock('link').match((node, ctx) =\u003e ctx.url)({ tag: 'a' });\n// The template sets tag to `a` only if block `link` have `url` field.\n// Otherwise tag will be ‘span’ as previous template says.\n```\n\n### Pattern matching\n\nTemplates are written using [pattern matching](/docs/en/7-runtime.md#how-templates-are-selected-and-applied) for the values and structure of input data\n\n```js\nblock('list')({ tag: 'ul' });\nblock('item')({ tag: 'li' });\n```\n\nWe can apply these two declarative-style templates templates to data:\n```js\n{\n  block: 'list',\n  content: [\n    {\n      block: 'item',\n      content: {\n          block: 'list',\n          content: [\n              { block: 'item', content: 'CSS' },\n              { block: 'item', content: 'HTML' }\n          ]\n      }\n    },\n    {\n      block: 'item',\n      content: {\n          block: 'list',\n          content: { block: 'item', content: 'JS' }\n      }\n    }\n  ] \n}\n```\n\nThe result is:\n\n```html\n\u003cul class=\"list\"\u003e\n    \u003cli class=\"item\"\u003e\n        \u003cul class=\"list\"\u003e\n            \u003cli class=\"item\"\u003eCSS\u003c/li\u003e\n            \u003cli class=\"item\"\u003eHTML\u003c/li\u003e\n        \u003c/ul\u003e\n    \u003c/li\u003e\n    \u003cli class=\"item\"\u003e\n        \u003cul class=\"list\"\u003e\n            \u003cli class=\"item\"\u003eJS\u003c/li\u003e\n        \u003c/ul\u003e\n    \u003c/li\u003e\n\u003c/ul\u003e\n```\n\nAs you can see templates are as simple as CSS.\n\n### Automatic recursive traversing upon input data\n\nIn 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.\n\n### Default rendering\n\nBuilt-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:\n\n```html\n\u003cdiv class=\"list\"\u003e\n    \u003cdiv class=\"item\"\u003e\n        \u003cdiv class=\"list\"\u003e\n            \u003cdiv class=\"item\"\u003eCSS\u003c/div\u003e\n            \u003cdiv class=\"item\"\u003eHTML\u003c/div\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n    \u003cdiv class=\"item\"\u003e\n        \u003cdiv class=\"list\"\u003e\n            \u003cdiv class=\"item\"\u003eJS\u003c/div\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\nThat is more than half of the work ;) You will add the salt (couple of templates for tags) and the HTML-soup is very tasty!\n\n\n### No DSL, only JavaScript\n\nWritten in JavaScript, so the entire JavaScript infrastructure is available for checking code quality and conforming to best practices.\n\nSince templates is a regular JavaScript code you can use automatic syntax validator from your editor and tools like JSHint/ESLint.\n\n### Runs on a server and client\n\nYou can use bem-xjst in any browser as well as in any JavaScript VM. We support Node.JS v0.10 and higher.\n\n\n## Tell me more\n\nSee documentation:\n\n1. [About](/docs/en/1-about.md)\n2. [Quick Start](/docs/en/2-quick-start.md)\n3. [API: usage, methods, signatures and etc](/docs/en/3-api.md)\n4. [Input data format](/docs/en/4-data.md): BEMJSON\n5. [Templates syntax](/docs/en/5-templates-syntax.md)\n6. [Templates context](/docs/en/6-templates-context.md)\n7. [Runtime](/docs/en/7-runtime.md): processes for selecting and applying templates\n\n\n## Try it\n\n### Online sandbox\n\n[Online demo](https://bem.github.io/bem-xjst/) allows you to share code snippets, change versions and etc. Happy templating!\n\n\n### Install npm package\n\nTo compile bem-xjst, you need [Node.js](https://nodejs.org/) v0.10 or later, and [npm](https://www.npmjs.com/).\n\n```bash\nnpm install bem-xjst\n```\n\nCopy-paste [example from quick start](https://github.com/bem/bem-xjst/blob/master/docs/en/2-quick-start.md#basic-example) or see [simple example](https://github.com/bem/bem-xjst/tree/master/examples/simple-page) from repository. Then read [documentation](https://github.com/bem/bem-xjst/blob/master/docs/en/) and start experimenting with bem-xjst.\n\n\n## Is bem-xjst used in production?\n\nYes. A lot of projects in [Yandex](https://company.yandex.com/) and Alfa-Bank, also in opensource projects based on [bem-core](https://github.com/bem/bem-core) and [bem-components](https://github.com/bem/bem-components).\n\n## Benchmarks\n\nSee [readme](https://github.com/bem/bem-xjst/tree/master/bench).\n\n## Runtime linter\n\nSee [readme](https://github.com/bem/bem-xjst/tree/master/runtime-lint).\n\n## Static linter and migration tool for templates\n\nSee [readme](https://github.com/bem/bem-xjst/tree/master/migration).\n\n## Links\n\n * [Documentation](https://en.bem.info/platform/bem-xjst/)\n * [Changelog](CHANGELOG.md) and [releases notes](https://github.com/bem/bem-xjst/releases)\n * [Contributing guide](https://github.com/bem/bem-xjst/blob/master/CONTRIBUTING.md)\n * [Online demo](https://bem.github.io/bem-xjst/) (you can share code snippets)\n * Twitter account: [@bemxjst](https://twitter.com/bemxjst)\n * [Migration guides](https://github.com/bem/bem-xjst/wiki/Migration-guides) for all major versions\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbem%2Fbem-xjst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbem%2Fbem-xjst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbem%2Fbem-xjst/lists"}