Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 86e5666

Browse files
author
Andrew Nesbitt
committed
Merge pull request #339 from johnobe/fix259
Adding support for passing a precision option to libsass
2 parents 6087c16 + 47291aa commit 86e5666

File tree

6 files changed

+28
-0
lines changed

6 files changed

+28
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ The API for using node-sass has changed, so that now there is only one variable
7575
`outputStyle` is a `String` to determine how the final CSS should be rendered. Its value should be one of `'nested'` or `'compressed'`.
7676
[`'expanded'` and `'compact'` are not currently supported by [libsass]]
7777

78+
#### precision
79+
`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.
80+
7881
#### sourceComments
7982
`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'`.
8083
The `map` option will create the source map file in your CSS destination.

binding.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ void ExtractOptions(Local<Value> optionsValue, void* cptr, sass_context_wrapper*
5454
if (source_comments == SASS_SOURCE_COMMENTS_MAP) {
5555
ctx->source_map_file = CreateString(options->Get(NanSymbol("sourceMap")));
5656
}
57+
ctx->options.precision = options->Get(NanSymbol("precision"))->Int32Value();
5758
} else {
5859
sass_context* ctx = (sass_context*) cptr;
5960
ctx->source_string = CreateString(options->Get(NanSymbol("data")));
6061
ctx->options.image_path = CreateString(options->Get(NanSymbol("imagePath")));
6162
ctx->options.output_style = options->Get(NanSymbol("style"))->Int32Value();
6263
ctx->options.source_comments = source_comments = options->Get(NanSymbol("comments"))->Int32Value();
6364
ctx->options.include_paths = CreateString(options->Get(NanSymbol("paths")));
65+
ctx->options.precision = options->Get(NanSymbol("precision"))->Int32Value();
6466
}
6567
}
6668

lib/cli.js

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ var optimist = require('optimist')
2525
describe: 'Path to prepend when using the image-url(…) helper',
2626
'default': ''
2727
})
28+
.options('precision', {
29+
describe: 'The amount of precision allowed in decimal numbers',
30+
'default': 5
31+
})
2832
.options('watch', {
2933
describe: 'Watch a directory or file',
3034
alias: 'w'
@@ -131,6 +135,8 @@ exports = module.exports = function(args) {
131135
}
132136
}
133137

138+
options.precision = argv.precision;
139+
134140
if (argv.w) {
135141

136142
var watchDir = argv.w;

lib/render.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function render(options, emitter) {
1111
outputStyle: options.outputStyle,
1212
sourceComments: options.sourceComments,
1313
sourceMap: options.sourceMap,
14+
precision: options.precision,
1415
success: function(css, sourceMap) {
1516

1617
var todo = 1;

sass.js

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var prepareOptions = function (options) {
6464
comments: SASS_SOURCE_COMMENTS[sourceComments] || 0,
6565
stats: stats,
6666
sourceMap: options.sourceMap,
67+
precision: parseInt(options.precision) || 5,
6768
success: function onSuccess(css, sourceMap) {
6869
finishStats(stats, sourceMap);
6970
success && success(css, sourceMap);

test/test.js

+15
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,18 @@ describe('render to file', function() {
261261
});
262262

263263
});
264+
265+
describe('precision support', function() {
266+
it('should render when precision is specified', function(done) {
267+
sass.render({
268+
data: '.test { margin: 1.23456789 px; }',
269+
precision: 10,
270+
success: function(css) {
271+
done(assert.equal(css, '.test {\n margin: 1.23456789 px; }\n'));
272+
},
273+
error: function(error) {
274+
done(error);
275+
}
276+
});
277+
});
278+
});

0 commit comments

Comments
 (0)