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
...@@ -16,4 +16,6 @@ npm-debug.log ...@@ -16,4 +16,6 @@ npm-debug.log
build build
vagrant vagrant
.lock-wscript .lock-wscript
\ No newline at end of file .DS_Store
.sass-cache
...@@ -51,6 +51,10 @@ The API for using node-sass has changed, so that now there is only one variable ...@@ -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'`. `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!] [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 ### Examples
```javascript ```javascript
...@@ -120,7 +124,7 @@ Check out the project: ...@@ -120,7 +124,7 @@ Check out the project:
Replace the prebuild binary with your newly generated one Replace the prebuild binary with your newly generated one
cp build/Release/binding.node precompiled/*your-platform*/binding.node cp build/Release/binding.node precompiled/*your-platform*/binding.node
## Command Line Interface ## Command Line Interface
The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section. The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section.
......
...@@ -63,6 +63,7 @@ Handle<Value> OldRender(const Arguments& args) { ...@@ -63,6 +63,7 @@ Handle<Value> OldRender(const Arguments& args) {
strcpy(ctx->options.include_paths, *bstr); strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED; // ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[3]->Int32Value(); ctx->options.output_style = args[3]->Int32Value();
ctx->options.source_comments = args[4]->Int32Value();
ctx_w->ctx = ctx; ctx_w->ctx = ctx;
ctx_w->callback = Persistent<Function>::New(callback); ctx_w->callback = Persistent<Function>::New(callback);
ctx_w->request.data = ctx_w; ctx_w->request.data = ctx_w;
...@@ -120,6 +121,7 @@ Handle<Value> Render(const Arguments& args) { ...@@ -120,6 +121,7 @@ Handle<Value> Render(const Arguments& args) {
strcpy(ctx->options.include_paths, *bstr); strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED; // ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[4]->Int32Value(); ctx->options.output_style = args[4]->Int32Value();
ctx->options.source_comments = args[5]->Int32Value();
ctx_w->ctx = ctx; ctx_w->ctx = ctx;
ctx_w->callback = Persistent<Function>::New(callback); ctx_w->callback = Persistent<Function>::New(callback);
ctx_w->errorCallback = Persistent<Function>::New(errorCallback); ctx_w->errorCallback = Persistent<Function>::New(errorCallback);
...@@ -144,6 +146,7 @@ Handle<Value> RenderSync(const Arguments& args) { ...@@ -144,6 +146,7 @@ Handle<Value> RenderSync(const Arguments& args) {
ctx->options.include_paths = new char[strlen(*bstr)+1]; ctx->options.include_paths = new char[strlen(*bstr)+1];
strcpy(ctx->options.include_paths, *bstr); strcpy(ctx->options.include_paths, *bstr);
ctx->options.output_style = args[2]->Int32Value(); ctx->options.output_style = args[2]->Int32Value();
ctx->options.source_comments = args[3]->Int32Value();
sass_compile(ctx); sass_compile(ctx);
...@@ -223,6 +226,7 @@ Handle<Value> RenderFile(const Arguments& args) { ...@@ -223,6 +226,7 @@ Handle<Value> RenderFile(const Arguments& args) {
strcpy(ctx->options.include_paths, *bstr); strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED; // ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[4]->Int32Value(); ctx->options.output_style = args[4]->Int32Value();
ctx->options.source_comments = args[5]->Int32Value();
ctx_w->ctx = ctx; ctx_w->ctx = ctx;
ctx_w->callback = Persistent<Function>::New(callback); ctx_w->callback = Persistent<Function>::New(callback);
ctx_w->errorCallback = Persistent<Function>::New(errorCallback); ctx_w->errorCallback = Persistent<Function>::New(errorCallback);
...@@ -247,6 +251,7 @@ Handle<Value> RenderFileSync(const Arguments& args) { ...@@ -247,6 +251,7 @@ Handle<Value> RenderFileSync(const Arguments& args) {
ctx->options.include_paths = new char[strlen(*bstr)+1]; ctx->options.include_paths = new char[strlen(*bstr)+1];
strcpy(ctx->options.include_paths, *bstr); strcpy(ctx->options.include_paths, *bstr);
ctx->options.output_style = args[2]->Int32Value(); ctx->options.output_style = args[2]->Int32Value();
ctx->options.source_comments = args[3]->Int32Value();
sass_compile_file(ctx); sass_compile_file(ctx);
......
var spawn = require('child_process').spawn; 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 = { ...@@ -21,26 +21,35 @@ var SASS_OUTPUT_STYLE = {
compressed: 3 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 prepareOptions = function(options) {
var paths, style; var paths, style;
options = typeof options !== 'object' ? {} : options; options = typeof options !== 'object' ? {} : options;
paths = options.include_paths || options.includePaths || []; paths = options.include_paths || options.includePaths || [];
style = SASS_OUTPUT_STYLE[options.output_style || options.outputStyle] || 0; style = SASS_OUTPUT_STYLE[options.output_style || options.outputStyle] || 0;
comments = SASS_SOURCE_COMMENTS[options.source_comments || options.sourceComments] || 0;
return { return {
paths: paths, paths: paths,
style: style style: style,
comments: comments
}; };
} };
var deprecatedRender = function(css, callback, options) { var deprecatedRender = function(css, callback, options) {
options = prepareOptions(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) { var deprecatedRenderSync = function(css, options) {
options = prepareOptions(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) { exports.render = function(options) {
...@@ -54,7 +63,7 @@ exports.render = function(options) { ...@@ -54,7 +63,7 @@ exports.render = function(options) {
options.error = options.error || function(){}; options.error = options.error || function(){};
if (options.file !== undefined && options.file !== null) { 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! //Assume data is present if file is not. binding/libsass will tell the user otherwise!
...@@ -71,7 +80,7 @@ exports.renderSync = function(options) { ...@@ -71,7 +80,7 @@ exports.renderSync = function(options) {
newOptions = prepareOptions(options); newOptions = prepareOptions(options);
if (options.file !== undefined && options.file !== null) { 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! //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 sass = require('../sass');
var assert = require('assert'); var assert = require('assert');
var badSampleFilename = 'sample.scss';
var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
var scssStr = '#navbar {\ var scssStr = '#navbar {\
width: 80%;\ width: 80%;\
...@@ -33,10 +36,6 @@ var expectedRender = '#navbar {\n\ ...@@ -33,10 +36,6 @@ var expectedRender = '#navbar {\n\
#navbar li a {\n\ #navbar li a {\n\
font-weight: bold; }\n'; font-weight: bold; }\n';
var badSampleFilename = 'sample.scss';
var sampleFilename = require('path').resolve(__dirname, 'sample.scss');
describe("DEPRECATED: compile scss", function() { describe("DEPRECATED: compile scss", function() {
it("should compile with render", function(done) { it("should compile with render", function(done) {
sass.render(scssStr, function(err, css) { sass.render(scssStr, function(err, css) {
...@@ -111,7 +110,7 @@ describe("compile file", function() { ...@@ -111,7 +110,7 @@ describe("compile file", function() {
sass.render({ sass.render({
file: sampleFilename, file: sampleFilename,
success: function (css) { success: function (css) {
done(assert.ok(css)); done(assert.equal(css, expectedRender));
}, },
error: function (error) { error: function (error) {
done(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