diff --git a/bin/psass.pl b/bin/psass.pl index 57a242a..fc92f77 100644 --- a/bin/psass.pl +++ b/bin/psass.pl @@ -62,11 +62,17 @@ sub version { my @plugin_paths; my @include_paths; +# output styles +my $indent = " "; +my $linefeed = "auto"; + # get options GetOptions ( 'help|h' => sub { pod2usage(1); }, 'watch|w' => \ $watchdog, 'version|v' => \ &version, + 'indent=s' => \ $indent, + 'linefeed=s' => \ $linefeed, 'precision|p=s' => \ $precision, 'output-file|o=s' => \ $output_file, 'output-style|t=s' => \ $output_style, @@ -95,6 +101,18 @@ sub version { # die with message if style is unknown else { die "unknown output style: $output_style" } +# resolve linefeed options +if ($linefeed =~ m/^a/i) +{ $linefeed = undef; } +elsif ($linefeed =~ m/^w/i) +{ $linefeed = "\r\n"; } +elsif ($linefeed =~ m/^[u]/i) +{ $linefeed = "\n"; } +elsif ($linefeed =~ m/^[n]/i) +{ $linefeed = ""; } +# die with message if linefeed type is unknown +else { die "unknown linefeed type: $linefeed" } + # do we have output path in second arg? if (defined $ARGV[1] && $ARGV[1] ne '-') { $output_file = $ARGV[1]; } @@ -108,6 +126,8 @@ () { return ( dont_die => $watchdog, + indent => $indent, + linefeed => $linefeed, precision => $precision, output_path => $output_file, output_style => $output_style, @@ -201,7 +221,9 @@ =head1 SYNOPSIS -v, --version print version -h, --help print this help -w, --watch start watchdog mode - -p, --precision precision for float output + -p, --precision=int precision for float output + --indent=string set indent string used for output + --linefeed=type linefeed used for output [auto|unix|win|none] -o, --output-file=file output file to write result to -t, --output-style=style output style [expanded|nested|compressed|compact] -L, --plugin-path=path plugin load path (repeatable) diff --git a/lib/CSS/Sass.pm b/lib/CSS/Sass.pm index 326703e..8c1b55f 100644 --- a/lib/CSS/Sass.pm +++ b/lib/CSS/Sass.pm @@ -283,6 +283,18 @@ C, but never both. The default is C. Set to C to eliminate all whitespace (for your production CSS). +=item C + +Set the floating point precision for output. + +=item C + +Set the linefeed string used for css output. + +=item C + +Set the indentation string used for css output. + =item C Set to C to get extra comments in the output, indicating what input diff --git a/lib/CSS/Sass.xs b/lib/CSS/Sass.xs index dd1cf61..6236298 100644 --- a/lib/CSS/Sass.xs +++ b/lib/CSS/Sass.xs @@ -17,6 +17,7 @@ #include "sass2scss.h" #include "sass_context.h" +#define isSafeSv(sv) sv && SvOK(*sv) #define Constant(c) newCONSTSUB(stash, #c, newSViv(c)) #undef free @@ -513,6 +514,8 @@ SV* init_sass_options(struct Sass_Options* sass_options, HV* perl_options) SV** include_paths_sv = hv_fetchs(perl_options, "include_paths", false); SV** plugin_paths_sv = hv_fetchs(perl_options, "plugin_paths", false); SV** precision_sv = hv_fetchs(perl_options, "precision", false); + SV** linefeed_sv = hv_fetchs(perl_options, "linefeed", false); + SV** indent_sv = hv_fetchs(perl_options, "indent", false); SV** source_map_root_sv = hv_fetchs(perl_options, "source_map_root", false); SV** source_map_file_sv = hv_fetchs(perl_options, "source_map_file", false); SV** sass_functions_sv = hv_fetchs(perl_options, "sass_functions", false); @@ -528,10 +531,14 @@ SV* init_sass_options(struct Sass_Options* sass_options, HV* perl_options) if (source_map_embed_sv) sass_option_set_source_map_embed (sass_options, SvTRUE(*source_map_embed_sv)); if (include_paths_sv) sass_option_set_include_path (sass_options, safe_svpv(*include_paths_sv, "")); if (plugin_paths_sv) sass_option_set_plugin_path (sass_options, safe_svpv(*plugin_paths_sv, "")); - if (precision_sv) sass_option_set_precision (sass_options, SvUV(*precision_sv)); if (source_map_root_sv) sass_option_set_source_map_root (sass_options, safe_svpv(*source_map_root_sv, "")); if (source_map_file_sv) sass_option_set_source_map_file (sass_options, safe_svpv(*source_map_file_sv, "")); + // do not set anything if the option is set to undef + if (isSafeSv(indent_sv)) sass_option_set_indent (sass_options, SvPV_nolen(*indent_sv)); + if (isSafeSv(linefeed_sv)) sass_option_set_linefeed (sass_options, SvPV_nolen(*linefeed_sv)); + if (isSafeSv(precision_sv)) sass_option_set_precision (sass_options, SvUV(*precision_sv)); + if (importer_sv) { sass_option_set_importer(sass_options, sass_make_importer(sass_importer, *importer_sv)); } if (sass_functions_sv) { diff --git a/libsass b/libsass index dea27e5..948854a 160000 --- a/libsass +++ b/libsass @@ -1 +1 @@ -Subproject commit dea27e5e3cc61a0d9f00ffa3f598a1080c6502d6 +Subproject commit 948854a3169dabc6a82349f4e15f7e910a704d8c diff --git a/t/01_xs.t b/t/01_xs.t index f77769f..e5e8261 100644 --- a/t/01_xs.t +++ b/t/01_xs.t @@ -6,7 +6,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 46; BEGIN { use_ok('CSS::Sass') }; my $r; @@ -53,6 +53,17 @@ $r = CSS::Sass::compile_sass("\n.valid {\n color: red; }", { source_comments => is ($r->{error_status}, 0, "source_comments=>[] no error_status and doesn't crash"); is ($r->{error_message}, undef, "source_comments=>[] error_message is undef"); +# $options->{indent} +$r = CSS::Sass::compile_sass('foo { color: red; }', { indent => '-äöü-' }); +is ($r->{error_status}, 0, "import no error_status"); +is ($r->{error_message}, undef, "import error_message is undef"); +like ($r->{output_string}, qr/foo {\r?\n-äöü-color: red; }/, "import imported red"); + +# $options->{linefeed} +$r = CSS::Sass::compile_sass('foo { color: red; }', { linefeed => "-äöü-\r" }); +is ($r->{error_status}, 0, "import no error_status"); +is ($r->{error_message}, undef, "import error_message is undef"); +like ($r->{output_string}, qr/foo {-äöü-\r color: red; }/, "import imported red"); # $options->{include_paths} $r = CSS::Sass::compile_sass('@import "colors"; .valid { color: $red; }', { }); diff --git a/t/sass-spec b/t/sass-spec index 4b5b1cf..9391485 160000 --- a/t/sass-spec +++ b/t/sass-spec @@ -1 +1 @@ -Subproject commit 4b5b1cf3ae940964a52a1b8f06560f7a3aaf6d16 +Subproject commit 9391485cd8edd4ae067e1574969a60eb1c61447a