Skip to content

Commit

Permalink
Fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sipayRT committed Jun 22, 2015
1 parent e764f62 commit 519e286
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
34 changes: 28 additions & 6 deletions techs/css-stylus.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,29 @@ module.exports = require('enb/lib/build-flow').create()
.defineOption('compress', false)
.defineOption('prefix', '')
.defineOption('variables')
.defineOption('infoComments', true)
.defineOption('includes')
.defineOption('includeCSS', true)
.useFileList(['css', 'styl'])
.builder(function (sourceFiles) {
var node = this.node,
filename = node.resolvePath(path.basename(this._target)),
defer = vow.defer(),
infoComments = this._infoComments,
css, renderer;

css = sourceFiles.map(function (file) {
var url = node.relativePath(file.fullname);

if (file.name.indexOf('.styl') !== -1) {
return '/* ' + url + ':begin */\n' +
'@import "' + url + '";\n' +
'/* ' + url + ':end */\n';
var pre = post = '';

if (infoComments === true) {
pre = '/* ' + url + ':begin */\n';
post = '/* ' + url + ':end */\n';
}

return pre + '@import "' + url + '";\n' + post;
} else {
return '@import "' + url + '";';
}
Expand All @@ -52,9 +61,10 @@ module.exports = require('enb/lib/build-flow').create()
compress: this._compress,
prefix: this._prefix
})
.set('include css', this._includeCSS)
.set('resolve url', true)
.set('filename', filename)
.define('url', stylus.resolver());
.define('url', stylus.url());

if (this._variables) {
var variables = this._variables;
Expand All @@ -64,6 +74,12 @@ module.exports = require('enb/lib/build-flow').create()
});
}

if (this._includes) {
this._includes.forEach(function (path) {
renderer.include(path);
});
}

this._configureRenderer(renderer)
.render(function (err, css) {
if (err) {
Expand All @@ -79,8 +95,14 @@ module.exports = require('enb/lib/build-flow').create()
.use(atImport({
transform: function (content, filename) {
var url = node.relativePath(filename),
pre = '/* ' + url + ': begin */ /**/\n',
post = '/* ' + url + ': end */ /**/\n',
pre = post = '',
res;

if (infoComments === true) {
pre = '/* ' + url + ': begin */ /**/\n';
post = '/* ' + url + ': end */ /**/\n';
}

res = pre + content + post;

return res.replace(/\n/g, '\n ');
Expand Down
2 changes: 1 addition & 1 deletion test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ addSuite('cases', readDir(fixturesDirname + '/cases', '.styl'), function (test,
node.runTechAndGetContent(
CssTech, {
includes: ['images', 'cases/import.basic'],
comments: false,
infoComments: false,
compress: test.indexOf('compress') !== -1,
prefix: test.indexOf('prefix.') !== -1 && 'prefix-',
hoist: test.indexOf('hoist.') !== -1,
Expand Down

0 comments on commit 519e286

Please sign in to comment.