Commit 471a0759 by Adeel

Importer: Ability to return value.

Feature suggested by @jhnns.
parent 9ec016f0
......@@ -176,12 +176,18 @@ function getOptions(options) {
if (importer) {
options.importer = function(file, prev, key) {
importer(file, prev, function(data) {
var done = function(data) {
binding.importedCallback({
index: key,
objectLiteral: data
});
});
};
var result = importer(file, prev, done);
if (result) {
done(result);
}
};
}
......
......@@ -133,7 +133,7 @@ describe('api', function() {
});
});
it('should override imports with custom importer with data', function(done) {
it('should override imports with custom importer with "data" as input and uses callback', function(done) {
var src = read(fixture('include-files/index.scss'), 'utf8');
sass.render({
......@@ -151,7 +151,7 @@ describe('api', function() {
});
});
it('should override imports with custom importer with file', function(done) {
it('should override imports with custom importer with "file" as input and uses callback', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
success: function(result) {
......@@ -166,6 +166,40 @@ describe('api', function() {
}
});
});
it('should override imports with custom importer with "data" as input and returns value', function(done) {
var src = read(fixture('include-files/index.scss'), 'utf8');
sass.render({
data: src,
success: function(result) {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
},
importer: function(url, prev) {
return {
file: prev + url,
contents: 'div {color: yellow;}'
};
}
});
});
it('should override imports with custom importer with "file" as input and returns value', function(done) {
sass.render({
file: fixture('include-files/index.scss'),
success: function(result) {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
},
importer: function(url, prev) {
return {
file: prev + url,
contents: 'div {color: yellow;}'
};
}
});
});
});
describe('.renderSync(options)', function() {
......@@ -206,7 +240,7 @@ describe('api', function() {
done();
});
it('should override imports with custom importer with data', function(done) {
it('should override imports with custom importer with "data" as input and uses callback', function(done) {
var src = read(fixture('include-files/index.scss'), 'utf8');
var result = sass.renderSync({
......@@ -223,7 +257,7 @@ describe('api', function() {
done();
});
it('should override imports with custom importer with file', function(done) {
it('should override imports with custom importer with "file" as input and uses callback', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function(url, prev, finish) {
......@@ -237,6 +271,38 @@ describe('api', function() {
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
it('should override imports with custom importer with "data" as input and returns value', function(done) {
var src = read(fixture('include-files/index.scss'), 'utf8');
var result = sass.renderSync({
data: src,
importer: function(url, prev) {
return {
file: prev + url,
contents: 'div {color: yellow;}'
};
}
});
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
it('should override imports with custom importer with "file" as input and returns value', function(done) {
var result = sass.renderSync({
file: fixture('include-files/index.scss'),
importer: function(url, prev) {
return {
file: prev + url,
contents: 'div {color: yellow;}'
};
}
});
assert.equal(result.css.trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
done();
});
});
describe('.render({stats: {}})', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment