Commit 86e5666a by Andrew Nesbitt

Merge pull request #339 from johnobe/fix259

Adding support for passing a precision option to libsass
parents 6087c16d 47291aad
......@@ -75,6 +75,9 @@ 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'` or `'compressed'`.
[`'expanded'` and `'compact'` are not currently supported by [libsass]]
#### precision
`precision` is a `Number` that will be used to determine how many digits after the decimal will be allowed. For instance, if you had a decimal number of `1.23456789` and a precision of `5`, the result will be `1.23457` in the final CSS.
#### 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'`.
The `map` option will create the source map file in your CSS destination.
......
......@@ -54,6 +54,7 @@ void ExtractOptions(Local<Value> optionsValue, void* cptr, sass_context_wrapper*
if (source_comments == SASS_SOURCE_COMMENTS_MAP) {
ctx->source_map_file = CreateString(options->Get(NanSymbol("sourceMap")));
}
ctx->options.precision = options->Get(NanSymbol("precision"))->Int32Value();
} else {
sass_context* ctx = (sass_context*) cptr;
ctx->source_string = CreateString(options->Get(NanSymbol("data")));
......@@ -61,6 +62,7 @@ void ExtractOptions(Local<Value> optionsValue, void* cptr, sass_context_wrapper*
ctx->options.output_style = options->Get(NanSymbol("style"))->Int32Value();
ctx->options.source_comments = source_comments = options->Get(NanSymbol("comments"))->Int32Value();
ctx->options.include_paths = CreateString(options->Get(NanSymbol("paths")));
ctx->options.precision = options->Get(NanSymbol("precision"))->Int32Value();
}
}
......
......@@ -25,6 +25,10 @@ var optimist = require('optimist')
describe: 'Path to prepend when using the image-url(…) helper',
'default': ''
})
.options('precision', {
describe: 'The amount of precision allowed in decimal numbers',
'default': 5
})
.options('watch', {
describe: 'Watch a directory or file',
alias: 'w'
......@@ -131,6 +135,8 @@ exports = module.exports = function(args) {
}
}
options.precision = argv.precision;
if (argv.w) {
var watchDir = argv.w;
......
......@@ -11,6 +11,7 @@ function render(options, emitter) {
outputStyle: options.outputStyle,
sourceComments: options.sourceComments,
sourceMap: options.sourceMap,
precision: options.precision,
success: function(css, sourceMap) {
var todo = 1;
......
......@@ -64,6 +64,7 @@ var prepareOptions = function (options) {
comments: SASS_SOURCE_COMMENTS[sourceComments] || 0,
stats: stats,
sourceMap: options.sourceMap,
precision: parseInt(options.precision) || 5,
success: function onSuccess(css, sourceMap) {
finishStats(stats, sourceMap);
success && success(css, sourceMap);
......
......@@ -261,3 +261,18 @@ describe('render to file', function() {
});
});
describe('precision support', function() {
it('should render when precision is specified', function(done) {
sass.render({
data: '.test { margin: 1.23456789 px; }',
precision: 10,
success: function(css) {
done(assert.equal(css, '.test {\n margin: 1.23456789 px; }\n'));
},
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