Commit 1d397cce by Andrew Nesbitt

Merge pull request #116 from fourseven/master

Add in support for debug information in the output css files.
parents 6a0e4d30 dd6fcd0f
......@@ -17,3 +17,5 @@ npm-debug.log
build
vagrant
.lock-wscript
.DS_Store
.sass-cache
......@@ -51,6 +51,10 @@ The API for using node-sass has changed, so that now there is only one variable
`outputStyle` is a `String` to determine how the final CSS should be rendered. Its value should be one of `'nested', 'expanded', 'compact', 'compressed'`.
[Important: currently the argument `outputStyle` has some problem which may cause the output css becomes nothing because of the libsass, so you should not use it now!]
#### sourceComments
`sourceComments` is a `String` to determine what debug information is included in the output file. Its value should be one of `'none', 'normal', 'map'`. The default is `'none'`.
[Important: `souceComments` is only supported when using the `file` option, and does nothing when using `data` flag.]
### Examples
```javascript
......
......@@ -63,6 +63,7 @@ Handle<Value> OldRender(const Arguments& args) {
strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[3]->Int32Value();
ctx->options.source_comments = args[4]->Int32Value();
ctx_w->ctx = ctx;
ctx_w->callback = Persistent<Function>::New(callback);
ctx_w->request.data = ctx_w;
......@@ -120,6 +121,7 @@ Handle<Value> Render(const Arguments& args) {
strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[4]->Int32Value();
ctx->options.source_comments = args[5]->Int32Value();
ctx_w->ctx = ctx;
ctx_w->callback = Persistent<Function>::New(callback);
ctx_w->errorCallback = Persistent<Function>::New(errorCallback);
......@@ -144,6 +146,7 @@ Handle<Value> RenderSync(const Arguments& args) {
ctx->options.include_paths = new char[strlen(*bstr)+1];
strcpy(ctx->options.include_paths, *bstr);
ctx->options.output_style = args[2]->Int32Value();
ctx->options.source_comments = args[3]->Int32Value();
sass_compile(ctx);
......@@ -223,6 +226,7 @@ Handle<Value> RenderFile(const Arguments& args) {
strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[4]->Int32Value();
ctx->options.source_comments = args[5]->Int32Value();
ctx_w->ctx = ctx;
ctx_w->callback = Persistent<Function>::New(callback);
ctx_w->errorCallback = Persistent<Function>::New(errorCallback);
......@@ -247,6 +251,7 @@ Handle<Value> RenderFileSync(const Arguments& args) {
ctx->options.include_paths = new char[strlen(*bstr)+1];
strcpy(ctx->options.include_paths, *bstr);
ctx->options.output_style = args[2]->Int32Value();
ctx->options.source_comments = args[3]->Int32Value();
sass_compile_file(ctx);
......
var spawn = require('child_process').spawn;
if (process.platform === 'darwin') {
spawn('node-gyp', ['rebuild']);
}
spawn('node-gyp', ['rebuild']);
......@@ -21,26 +21,35 @@ var SASS_OUTPUT_STYLE = {
compressed: 3
};
var SASS_SOURCE_COMMENTS = {
none: 0,
// This is called default in libsass, but is a reserved keyword here
normal: 1,
map: 2
};
var prepareOptions = function(options) {
var paths, style;
options = typeof options !== 'object' ? {} : options;
paths = options.include_paths || options.includePaths || [];
style = SASS_OUTPUT_STYLE[options.output_style || options.outputStyle] || 0;
comments = SASS_SOURCE_COMMENTS[options.source_comments || options.sourceComments] || 0;
return {
paths: paths,
style: style
style: style,
comments: comments
};
}
};
var deprecatedRender = function(css, callback, options) {
options = prepareOptions(options);
return binding.oldRender(css, callback, options.paths.join(':'), options.style);
return binding.oldRender(css, callback, options.paths.join(':'), options.style, options.comments);
};
var deprecatedRenderSync = function(css, options) {
options = prepareOptions(options);
return binding.renderSync(css, options.paths.join(':'), options.style);
return binding.renderSync(css, options.paths.join(':'), options.style, options.comments);
};
exports.render = function(options) {
......@@ -54,7 +63,7 @@ exports.render = function(options) {
options.error = options.error || function(){};
if (options.file !== undefined && options.file !== null) {
return binding.renderFile(options.file, options.success, options.error, newOptions.paths.join(':'), newOptions.style);
return binding.renderFile(options.file, options.success, options.error, newOptions.paths.join(':'), newOptions.style, newOptions.comments);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
......@@ -71,7 +80,7 @@ exports.renderSync = function(options) {
newOptions = prepareOptions(options);
if (options.file !== undefined && options.file !== null) {
return binding.renderFileSync(options.file, newOptions.paths.join(':'), newOptions.style);
return binding.renderFileSync(options.file, newOptions.paths.join(':'), newOptions.style, newOptions.comments);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
......
/*jshint multistr:true */
var sass = require('../sass');
var assert = require('assert');
var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
var scssStr = '#navbar {\
width: 80%;\
height: 23px; }\
#navbar ul {\
list-style-type: none; }\
#navbar li {\
float: left;\
a {\
font-weight: bold; }}\
@mixin keyAnimation($name, $attr, $value) {\
@-webkit-keyframes #{$name} {\
0% { #{$attr}: $value; }\
}\
}';
var expectedCommentsScssStr = '/* line 1, ' + sampleFilename + ' */\n\
#navbar {\n\
width: 80%;\n\
height: 23px; }\n\
\n\
/* line 5, ' + sampleFilename + ' */\n\
#navbar ul {\n\
list-style-type: none; }\n\
\n\
/* line 8, ' + sampleFilename + ' */\n\
#navbar li {\n\
float: left; }\n\
/* line 10, ' + sampleFilename + ' */\n\
#navbar li a {\n\
font-weight: bold; }\n';
var expectedDebugScssStr = '@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\000031}}\n\
#navbar {\n\
width: 80%;\n\
height: 23px; }\n\
\n\
@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\000035}}\n\
#navbar ul {\n\
list-style-type: none; }\n\
\n\
@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\000038}}\n\
#navbar li {\n\
float: left; }\n\
@media -sass-debug-info{filename{font-family:file\:' + sampleFilename + '}line{font-family:\\0000310}}\n\
#navbar li a {\n\
font-weight: bold; }\n';
describe("compile file with source comments", function() {
it("should compile with render and comment outputs", function(done) {
sass.render({
file: sampleFilename,
source_comments: 'normal',
success: function (css) {
done(assert.equal(css, expectedCommentsScssStr));
},
error: function (error) {
done(error);
}
});
});
it("should compile with render and source map outputs", function(done) {
sass.render({
file: sampleFilename,
source_comments: 'map',
success: function (css) {
done(assert.equal(css, expectedDebugScssStr));
},
error: function (error) {
done(error);
}
});
});
});
/*jshint multistr:true */
var sass = require('../sass');
var assert = require('assert');
var badSampleFilename = 'sample.scss';
var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
var scssStr = '#navbar {\
width: 80%;\
......@@ -33,10 +36,6 @@ var expectedRender = '#navbar {\n\
#navbar li a {\n\
font-weight: bold; }\n';
var badSampleFilename = 'sample.scss';
var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
describe("DEPRECATED: compile scss", function() {
it("should compile with render", function(done) {
sass.render(scssStr, function(err, css) {
......@@ -111,7 +110,7 @@ describe("compile file", function() {
sass.render({
file: sampleFilename,
success: function (css) {
done(assert.ok(css));
done(assert.equal(css, expectedRender));
},
error: function (error) {
done(error);
......
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