Skip to content

Commit

Permalink
Implement precision option
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 18, 2014
1 parent 79b74c9 commit 9604b09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/CSS/Sass.xs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ compile_sass(input_string, options)
SV **output_style_sv = hv_fetch_key(options, "output_style", false);
SV **source_comments_sv = hv_fetch_key(options, "source_comments", false);
SV **include_paths_sv = hv_fetch_key(options, "include_paths", false);
SV **precision_sv = hv_fetch_key(options, "precision", false);
SV **image_path_sv = hv_fetch_key(options, "image_path", false);
SV **source_map_file_sv = hv_fetch_key(options, "source_map_file", false);
SV **sass_functions_sv = hv_fetch_key(options, "sass_functions", false);
Expand All @@ -195,6 +196,8 @@ compile_sass(input_string, options)
ctx->options.source_comments = SvUV(*source_comments_sv);
if (include_paths_sv)
ctx->options.include_paths = safe_svpv(*include_paths_sv, "");
if (precision_sv)
ctx->options.precision = SvUV(*precision_sv);
if (image_path_sv)
ctx->options.image_path = safe_svpv(*image_path_sv, "");
if (source_map_file_sv)
Expand Down Expand Up @@ -262,6 +265,7 @@ compile_sass_file(input_path, options)
SV **output_style_sv = hv_fetch_key(options, "output_style", false);
SV **source_comments_sv = hv_fetch_key(options, "source_comments", false);
SV **include_paths_sv = hv_fetch_key(options, "include_paths", false);
SV **precision_sv = hv_fetch_key(options, "precision", false);
SV **image_path_sv = hv_fetch_key(options, "image_path", false);
SV **source_map_file_sv = hv_fetch_key(options, "source_map_file", false);
SV **sass_functions_sv = hv_fetch_key(options, "sass_functions", false);
Expand All @@ -273,6 +277,8 @@ compile_sass_file(input_path, options)
ctx->options.source_comments = SvUV(*source_comments_sv);
if (include_paths_sv)
ctx->options.include_paths = safe_svpv(*include_paths_sv, "");
if (precision_sv)
ctx->options.precision = SvUV(*precision_sv);
if (image_path_sv)
ctx->options.image_path = safe_svpv(*image_path_sv, "");
if (source_map_file_sv)
Expand Down
2 changes: 1 addition & 1 deletion libsass
12 changes: 11 additions & 1 deletion t/01_xs.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use strict;
use warnings;

use Test::More tests => 42;
use Test::More tests => 48;
BEGIN { use_ok('CSS::Sass') };

my $r;
Expand Down Expand Up @@ -90,3 +90,13 @@ like ($r->{output_string}, qr@url\("/a/b/c/path"\)@, "image_path works");
$r = CSS::Sass::compile_sass('.valid { color: image-url("path"); }', { image_path => { wrong_type => 1 } });
is ($r->{error_status}, 0, "image_path w/ bad type no error_status and doesn't crash");
is ($r->{error_message}, undef, "image_path w/ bad type error_message is undef");

$r = CSS::Sass::compile_sass('.valid { width: #{(1/3)}; }', { include_paths => 't/inc' });
is ($r->{error_status}, 0, "import no error_status");
is ($r->{error_message}, undef, "import error_message is undef");
like ($r->{output_string}, qr/0\.33333;/, "default float precision is 5");

$r = CSS::Sass::compile_sass('.valid { width: #{(1/3)}; }', { include_paths => 't/inc', precision => 10 });
is ($r->{error_status}, 0, "import no error_status");
is ($r->{error_message}, undef, "import error_message is undef");
like ($r->{output_string}, qr/0\.3333333333;/, "float precision of 10");

1 comment on commit 9604b09

@mgreter
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libsass pushed a commit that exposes a new precision option: sass/libsass#287

Please sign in to comment.