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

Adding support for passing a precision option to libsass #339

Merged
merged 2 commits into from
Jun 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ 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")));
ctx->options.image_path = CreateString(options->Get(NanSymbol("imagePath")));
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();
}
}

Expand Down
6 changes: 6 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -131,6 +135,8 @@ exports = module.exports = function(args) {
}
}

options.precision = argv.precision;

if (argv.w) {

var watchDir = argv.w;
Expand Down
1 change: 1 addition & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
});