Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #108] expose use #111

Merged
merged 1 commit into from
Jan 15, 2016
Merged
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
25 changes: 24 additions & 1 deletion api.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* [comments](#comments)
* [globals](#globals)
* [includes](#includes)
* [use](#use)
* [useNib](#usenib)
* [importPaths](#importPaths)

#### target

Expand Down Expand Up @@ -175,6 +177,14 @@ Oбработка `url()` внутри файлов `.styl` и `.css`.

**Важно!** Опция работает только для файлов с расширением `.styl`.

### use

Тип: `Function | Function[]`. По умолчанию: `[]`.

Подключение плагинов или одного плагина для Stylus [через use()](https://github.com/stylus/stylus/blob/dev/docs/js.md#usefn)

**Важно!** Опция работает только для файлов с расширением `.styl`.

### useNib

Тип: `Boolean`. По умолчанию: `false`.
Expand All @@ -183,13 +193,23 @@ Oбработка `url()` внутри файлов `.styl` и `.css`.

**Важно!** Опция работает только для файлов с расширением `.styl`.

### importPaths

Тип: `String[]`. По умолчанию: `[]`.

Подключение `.styl` файлов или директорий c `index.styl` [через import()](https://github.com/stylus/stylus/blob/dev/docs/js.md#importpath)

**Важно!** Опция работает только для файлов с расширением `.styl`.

--------------------------------------

## Пример использования технологии

```js
var stylusTech = require('enb-stylus/techs/stylus'),
FileProvideTech = require('enb/techs/file-provider'),
nib = require('nib'),
rupture = require('rupture'),
bemTechs = require('enb-bem-techs');

module.exports = function(config) {
Expand All @@ -203,7 +223,10 @@ module.exports = function(config) {
]);

// Создаем CSS-файлы
node.addTech([stylusTech, { /* опции */ }]);
node.addTech([stylusTech, {
use: [nib(), rupture()],
importPaths: [nib.path + '/nib']
}]);
node.addTarget('?.css');
});
};
Expand Down
22 changes: 19 additions & 3 deletions techs/stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ var path = require('path'),
* Important: Available for Stylus only.
* @param {String[]} [options.globals=[]] Imports `.styl` files with global variables,
* functions and mixins to the top.
* @param {String[]} [options.importPaths=[]] Adds additional path to import
* @param {String[]} [options.includes=[]] Adds additional path to resolve a path in @import
* and url().<br/>
* [Stylus: include]{@link http://bit.ly/1IpsoTh}
* <br/>
* Important: Available for Stylus only.
* @param {Function[]} [options.use=[]] Allows to use plugins for Stylus.<br/>
* @param {Boolean} [options.useNib=false] Allows to use Nib library for Stylus.<br/>
* Important: Available for Stylus only.
*
Expand Down Expand Up @@ -100,9 +102,11 @@ module.exports = buildFlow.create()
.defineOption('autoprefixer', false)
.defineOption('compress', false)
.defineOption('prefix', '')
.defineOption('importPaths', [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Напиши в документацию и про эту опцию тоже.

.defineOption('includes', [])
.defineOption('globals', [])
.defineOption('useNib', false)
.defineOption('use', [])
.useFileList(['styl', 'css'])
.saveCache(function (cache) {
cache.cacheFileList(this._globalFiles);
Expand Down Expand Up @@ -286,13 +290,25 @@ module.exports = buildFlow.create()
});
}

if (!Array.isArray(this._use)) {
this._use = [this._use];
}

if (this._useNib) {
var nib = require('nib');
renderer
.use(nib())
.import(nib.path + '/nib');

this._use.push(nib());
this._importPaths.push(path.join(nib.path, 'nib'));
}

this._use.forEach(function (func) {
renderer.use(func);
});

this._importPaths.forEach(function (path) {
renderer.import(path);
});

var defer = vow.defer();

this._configureRenderer(renderer).render(function (err, css) {
Expand Down
38 changes: 38 additions & 0 deletions test/stylus-tech.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require('fs'),
path = require('path'),
deepExtend = require('deep-extend'),
vow = require('vow'),
mockFs = require('mock-fs'),
mockFsHelper = require(path.join(__dirname, 'lib', 'mock-fs-helper')),
MockNode = require('mock-enb/lib/mock-node'),
Expand Down Expand Up @@ -300,6 +301,43 @@ describe('stylus-tech', function () {
});
});

describe('use', function () {
var nibPlugin = require('nib');

it('must use nib plugin as a part of plugins list', function () {
var scheme = {
blocks: {
'block.styl': 'body { size: 5em 10em; }'
}
},
expected = [
'body{',
'width:5em;',
'height:10em;',
'}'
].join('');

return build(scheme, { use: [nibPlugin()] }).then(function (actual) {
actual.must.equal(expected);
});
});

it('must use single nib plugin identically as a part of plugins list', function () {
var scheme = {
blocks: {
'block.styl': 'body { size: 5em 10em; }'
}
};

return vow.all([
build(scheme, { use: nibPlugin() }),
build(scheme, { use: [nibPlugin()] })
]).then(function (values) {
values[0].must.equal(values[1]);
});
});
});

describe('compress', function () {
it('must compressed result css', function () {
var scheme = {
Expand Down