Skip to content
This repository was archived by the owner on Mar 25, 2018. It is now read-only.

Feat: Pass in any bemxjst version #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gulp-bem-xjst

> Compile [bemhtml](http://en.bem.info/technology/bemhtml/v2/reference/) templates into JavaScript
> Compiles [BEMHTML](http://en.bem.info/technology/bemhtml/v2/reference/) and BEMTREE templates into JavaScript.

[![NPM Status][npm-img]][npm]
[![Travis Status][test-img]][travis]
Expand All @@ -20,7 +20,7 @@

* [Node.js 4+](https://nodejs.org/en/)

## Install
## Installation

```sh
$ npm install gulp-bem-xjst
Expand All @@ -29,12 +29,13 @@ $ npm install gulp-bem-xjst
## Usage

```js
var gulp = require('gulp');
var bemhtml = require('gulp-bem-xjst').bemhtml;
const gulp = require('gulp');
const bemxjst = require('bemxjst');
const bemhtml = require('gulp-bem-xjst').bemhtml;

gulp.task('default', function () {
return gulp.src('page.bemhtml')
.pipe(bemhtml())
.pipe(bemhtml({ bemxjst }))
.pipe(gulp.dest('dist'));
});
```
Expand All @@ -45,17 +46,17 @@ $ node -p "require('./dist/page.bemhtml.js').apply({block: 'page'});"

## API

bem-xjst engines accesible via properties `bemhtml` and `bemtree`:
```
var engine = require('gulp-bem-xjst')[engine];
`bem-xjst` engines accesible via properties `bemhtml` and `bemtree`:
```js
const engine = require('gulp-bem-xjst')[engine];
```

### Plugin options

* *String* **exportName** — Engine handler's variable name. Default — `BEMHTML`.
* *String* **engine** — Engine's name. Default — `BEMHTML`.
* *String* **engine** — engine's name: `bemhtml` or `bemtree`. Default — `bemhtml`.
* *String* **extension** — extension for file. Default — `.${engine}.js`.
* *Module* **bemxjst** — custom `bem-xjst` version. The last `v8.x` by default.

### License
## License

[MIT](./LICENSE)
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ var pluginName = path.basename(__dirname);
/**
* bem-xjst templates compiler.
*
* @param {{extension: string}} options - Options for generator.
* @param {String|Function} engine - 'bemhtml' either 'bemtree' or any xjst-like engine function.
* @returns {Stream}
* @param {{extension: string, bemxjst: *}} options - Options for generator.
* @param {String|Function} engine - either 'bemhtml', or 'bemtree', or any xjst-like engine function.
* @returns {TransformStream.<File, File>}
*/
module.exports = function(options, engine) {
options = options || {};

var module = options.bemxjst || bemxjst;

engine || (engine = options.engine || 'bemhtml');

assert(typeof engine === 'string' || typeof (engine && engine.generate) === 'function', 'Invalid engine');

var engineName;
if (typeof engine === 'string') {
engineName = engine;
engine = bemxjst[engine];
engine = module[engine];
} else {
engineName = (engine.engineName || engine.name || Object(engine.runtime).name).toLowerCase() || 'xjst';
}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "3.0.0",
"description": "bem-xjst templates compiler",
"keywords": [
"gulp",
"plugin",
"gulpplugin",
"bem",
"bemhtml",
"bemtree",
"bem-xjst",
Expand Down Expand Up @@ -33,7 +36,7 @@
"lint": "eslint ."
},
"dependencies": {
"bem-xjst": "^8.4.0",
"bem-xjst": "8.x",
"is-stream": "^1.1.0",
"node-eval": "^1.1.0",
"plugin-error": "^0.1.2",
Expand Down