diff --git a/README.md b/README.md index 9e20121..12f336f 100644 --- a/README.md +++ b/README.md @@ -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] @@ -20,7 +20,7 @@ * [Node.js 4+](https://nodejs.org/en/) -## Install +## Installation ```sh $ npm install gulp-bem-xjst @@ -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')); }); ``` @@ -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) diff --git a/index.js b/index.js index 85e2859..01f528d 100644 --- a/index.js +++ b/index.js @@ -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.} */ 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'; } diff --git a/package.json b/package.json index 57433d8..cf8f480 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,10 @@ "version": "3.0.0", "description": "bem-xjst templates compiler", "keywords": [ + "gulp", + "plugin", "gulpplugin", + "bem", "bemhtml", "bemtree", "bem-xjst", @@ -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",