Commit 9ce6de02 by Adeel

API: Simplifies API functions.

* Removes deprecated functions.
* Introduces breaking change.
* Reponds to #547.
parent 4bea0703
...@@ -201,41 +201,6 @@ function getOptions(options) { ...@@ -201,41 +201,6 @@ function getOptions(options) {
var binding = require(getBinding()); var binding = require(getBinding());
/** /**
* Render (deprecated)
*
* @param {String} css
* @param {Function} cb
* @param {Object} options
* @api private
*/
function deprecatedRender(css, cb, options) {
options = getOptions(options);
options.data = css;
options.error = cb;
options.success = function(css) {
cb(null, css);
};
binding.render(options);
}
/**
* Render sync (deprecated)
*
* @param {String} css
* @param {Object} options
* @api private
*/
function deprecatedRenderSync(css, options) {
options = getOptions(options);
options.data = css;
return binding.renderSync(options);
}
/**
* Render * Render
* *
* @param {Object} options * @param {Object} options
...@@ -243,12 +208,8 @@ function deprecatedRenderSync(css, options) { ...@@ -243,12 +208,8 @@ function deprecatedRenderSync(css, options) {
*/ */
module.exports.render = function(options) { module.exports.render = function(options) {
if (typeof arguments[0] === 'string') {
return deprecatedRender.apply(this, arguments);
}
options = getOptions(options); options = getOptions(options);
options.file ? binding.renderFile(options) : binding.render(options); options.data ? binding.render(options) : binding.renderFile(options);
}; };
/** /**
...@@ -259,14 +220,10 @@ module.exports.render = function(options) { ...@@ -259,14 +220,10 @@ module.exports.render = function(options) {
*/ */
module.exports.renderSync = function(options) { module.exports.renderSync = function(options) {
if (typeof arguments[0] === 'string') {
return deprecatedRenderSync.apply(this, arguments);
}
var output; var output;
options = getOptions(options); options = getOptions(options);
output = options.file ? binding.renderFileSync(options) : binding.renderSync(options); output = options.data ? binding.renderSync(options) : binding.renderFileSync(options);
endStats(options, JSON.parse(options.stats.sourceMap)); endStats(options, JSON.parse(options.stats.sourceMap));
return output; return output;
...@@ -334,4 +291,8 @@ module.exports.middleware = function() { ...@@ -334,4 +291,8 @@ module.exports.middleware = function() {
'The middleware has been moved to', 'The middleware has been moved to',
'https://github.com/sass/node-sass-middleware' 'https://github.com/sass/node-sass-middleware'
].join(' ')); ].join(' '));
endStats(options, options.stats.sourceMap);
return output;
}; };
...@@ -99,6 +99,8 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx ...@@ -99,6 +99,8 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
sass_option_set_importer(sass_options, sass_make_importer(sass_importer, ctx_w)); sass_option_set_importer(sass_options, sass_make_importer(sass_importer, ctx_w));
} }
sass_option_set_input_path(sass_options, CreateString(options->Get(NanNew("file"))));
sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile"))));
sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile")))); sass_option_set_output_path(sass_options, CreateString(options->Get(NanNew("outFile"))));
sass_option_set_image_path(sass_options, CreateString(options->Get(NanNew("imagePath")))); sass_option_set_image_path(sass_options, CreateString(options->Get(NanNew("imagePath"))));
sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value()); sass_option_set_output_style(sass_options, (Sass_Output_Style)options->Get(NanNew("style"))->Int32Value());
......
...@@ -6,69 +6,6 @@ var assert = require('assert'), ...@@ -6,69 +6,6 @@ var assert = require('assert'),
fixture = path.join.bind(null, __dirname, 'fixtures'), fixture = path.join.bind(null, __dirname, 'fixtures'),
resolveFixture = path.resolve.bind(null, __dirname, 'fixtures'); resolveFixture = path.resolve.bind(null, __dirname, 'fixtures');
describe('api (deprecated)', function() {
describe('.render(src, fn)', function() {
it('should compile sass to css', function(done) {
var src = read(fixture('simple/index.scss'), 'utf8');
var expected = read(fixture('simple/expected.css'), 'utf8').trim();
sass.render(src, function(err, css) {
assert(!err);
assert.equal(css.trim(), expected.replace(/\r\n/g, '\n'));
done();
});
});
it('should compile sass to css using indented syntax', function(done) {
var src = read(fixture('indent/index.sass'), 'utf8');
var expected = read(fixture('indent/expected.css'), 'utf8').trim();
sass.render(src, function(err, css) {
assert(!err);
assert.equal(css.trim(), expected.replace(/\r\n/g, '\n'));
done();
}, {
indentedSyntax: true
});
});
it('should throw error for bad input', function(done) {
sass.render('#navbar width 80%;', function(err) {
assert(err);
done();
});
});
});
describe('.renderSync(src)', function() {
it('should compile sass to css', function(done) {
var src = read(fixture('simple/index.scss'), 'utf8');
var expected = read(fixture('simple/expected.css'), 'utf8').trim();
var css = sass.renderSync(src).trim();
assert.equal(css, expected.replace(/\r\n/g, '\n'));
done();
});
it('should compile sass to css using indented syntax', function(done) {
var src = read(fixture('indent/index.sass'), 'utf8');
var expected = read(fixture('indent/expected.css'), 'utf8').trim();
var css = sass.renderSync(src, {indentedSyntax: true}).trim();
assert.equal(css, expected.replace(/\r\n/g, '\n'));
done();
});
it('should throw error for bad input', function(done) {
assert.throws(function() {
sass.renderSync('#navbar width 80%;');
});
done();
});
});
});
describe('api', function() { describe('api', function() {
describe('.render(options)', function() { describe('.render(options)', function() {
it('should compile sass to css', function(done) { it('should compile sass to css', function(done) {
...@@ -233,100 +170,6 @@ describe('api', function() { ...@@ -233,100 +170,6 @@ describe('api', function() {
}); });
}); });
describe('.renderFile(options)', function() {
it('should compile sass to css', function(done) {
var src = read(fixture('simple/index.scss'), 'utf8');
var dest = fixture('simple/build.css');
var expected = read(fixture('simple/expected.css'), 'utf8').trim();
sass.renderFile({
data: src,
outFile: dest,
success: function() {
assert.equal(read(dest, 'utf8').trim(), expected.replace(/\r\n/g, '\n'));
fs.unlinkSync(dest);
done();
}
});
});
it('should compile sass to css using indented syntax', function(done) {
var src = read(fixture('indent/index.sass'), 'utf8');
var dest = fixture('indent/build.css');
var expected = read(fixture('indent/expected.css'), 'utf8').trim();
sass.renderFile({
data: src,
outFile: dest,
indentedSyntax: true,
success: function() {
assert.equal(read(dest, 'utf8').trim(), expected.replace(/\r\n/g, '\n'));
fs.unlinkSync(dest);
done();
}
});
});
it('should save source map to default name', function(done) {
var src = fixture('source-map/index.scss');
var dest = fixture('source-map/build.css');
var name = 'build.css.map';
sass.renderFile({
file: src,
outFile: dest,
sourceMap: true,
success: function(file, map) {
assert.equal(path.basename(map), name);
assert(read(dest, 'utf8').indexOf('sourceMappingURL=' + name) !== -1);
fs.unlinkSync(map);
fs.unlinkSync(dest);
done();
}
});
});
it('should save source map to specified name', function(done) {
var src = fixture('source-map/index.scss');
var dest = fixture('source-map/build.css');
var name = 'foo.css.map';
sass.renderFile({
file: src,
outFile: dest,
sourceMap: name,
success: function(file, map) {
assert.equal(path.basename(map), name);
assert(read(dest, 'utf8').indexOf('sourceMappingURL=' + name) !== -1);
fs.unlinkSync(map);
fs.unlinkSync(dest);
done();
}
});
});
it('should save source paths relative to the source map file', function(done) {
var src = fixture('include-files/index.scss');
var dest = fixture('include-files/build.css');
var obj;
sass.renderFile({
file: src,
outFile: dest,
sourceMap: true,
success: function(file, map) {
obj = JSON.parse(read(map, 'utf8'));
assert.equal(obj.sources[0], 'index.scss');
assert.equal(obj.sources[1], 'foo.scss');
assert.equal(obj.sources[2], 'bar.scss');
fs.unlinkSync(map);
fs.unlinkSync(dest);
done();
}
});
});
});
describe('.render({stats: {}})', function() { describe('.render({stats: {}})', function() {
var start = Date.now(); var start = Date.now();
var stats = {}; var stats = {};
...@@ -519,11 +362,4 @@ describe('api', function() { ...@@ -519,11 +362,4 @@ describe('api', function() {
done(); done();
}); });
}); });
describe('.middleware()', function() {
it('should throw error on require', function(done) {
assert.throws(sass.middleware());
done();
});
});
}); });
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