Skip to content

Commit e68673b

Browse files
committed
Add indent and linefeed config options
1 parent 21facf0 commit e68673b

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

bin/psass.pl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ sub version {
6262
my @plugin_paths;
6363
my @include_paths;
6464

65+
# output styles
66+
my $indent = " ";
67+
my $linefeed = "auto";
68+
6569
# get options
6670
GetOptions (
6771
'help|h' => sub { pod2usage(1); },
6872
'watch|w' => \ $watchdog,
6973
'version|v' => \ &version,
74+
'indent=s' => \ $indent,
75+
'linefeed=s' => \ $linefeed,
7076
'precision|p=s' => \ $precision,
7177
'output-file|o=s' => \ $output_file,
7278
'output-style|t=s' => \ $output_style,
@@ -95,6 +101,18 @@ sub version {
95101
# die with message if style is unknown
96102
else { die "unknown output style: $output_style" }
97103

104+
# resolve linefeed options
105+
if ($linefeed =~ m/^a/i)
106+
{ $linefeed = undef; }
107+
elsif ($linefeed =~ m/^w/i)
108+
{ $linefeed = "\r\n"; }
109+
elsif ($linefeed =~ m/^[u]/i)
110+
{ $linefeed = "\n"; }
111+
elsif ($linefeed =~ m/^[n]/i)
112+
{ $linefeed = ""; }
113+
# die with message if linefeed type is unknown
114+
else { die "unknown linefeed type: $linefeed" }
115+
98116
# do we have output path in second arg?
99117
if (defined $ARGV[1] && $ARGV[1] ne '-')
100118
{ $output_file = $ARGV[1]; }
@@ -108,6 +126,8 @@ ()
108126
{
109127
return (
110128
dont_die => $watchdog,
129+
indent => $indent,
130+
linefeed => $linefeed,
111131
precision => $precision,
112132
output_path => $output_file,
113133
output_style => $output_style,
@@ -201,7 +221,9 @@ =head1 SYNOPSIS
201221
-v, --version print version
202222
-h, --help print this help
203223
-w, --watch start watchdog mode
204-
-p, --precision precision for float output
224+
-p, --precision=int precision for float output
225+
--indent=string set indent string used for output
226+
--linefeed=type linefeed used for output [auto|unix|win|none]
205227
-o, --output-file=file output file to write result to
206228
-t, --output-style=style output style [expanded|nested|compressed|compact]
207229
-L, --plugin-path=path plugin load path (repeatable)

lib/CSS/Sass.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ C<undef>, but never both.
283283
The default is C<SASS_STYLE_NESTED>. Set to C<SASS_STYLE_COMPRESSED> to
284284
eliminate all whitespace (for your production CSS).
285285
286+
=item C<precision>
287+
288+
Set the floating point precision for output.
289+
290+
=item C<linefeed>
291+
292+
Set the linefeed string used for css output.
293+
294+
=item C<indentation>
295+
296+
Set the indentation string used for css output.
297+
286298
=item C<source_comments>
287299
288300
Set to C<true> to get extra comments in the output, indicating what input

lib/CSS/Sass.xs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "sass2scss.h"
1818
#include "sass_context.h"
1919

20+
#define isSafeSv(sv) sv && SvOK(*sv)
2021
#define Constant(c) newCONSTSUB(stash, #c, newSViv(c))
2122

2223
#undef free
@@ -513,6 +514,8 @@ SV* init_sass_options(struct Sass_Options* sass_options, HV* perl_options)
513514
SV** include_paths_sv = hv_fetchs(perl_options, "include_paths", false);
514515
SV** plugin_paths_sv = hv_fetchs(perl_options, "plugin_paths", false);
515516
SV** precision_sv = hv_fetchs(perl_options, "precision", false);
517+
SV** linefeed_sv = hv_fetchs(perl_options, "linefeed", false);
518+
SV** indent_sv = hv_fetchs(perl_options, "indent", false);
516519
SV** source_map_root_sv = hv_fetchs(perl_options, "source_map_root", false);
517520
SV** source_map_file_sv = hv_fetchs(perl_options, "source_map_file", false);
518521
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)
528531
if (source_map_embed_sv) sass_option_set_source_map_embed (sass_options, SvTRUE(*source_map_embed_sv));
529532
if (include_paths_sv) sass_option_set_include_path (sass_options, safe_svpv(*include_paths_sv, ""));
530533
if (plugin_paths_sv) sass_option_set_plugin_path (sass_options, safe_svpv(*plugin_paths_sv, ""));
531-
if (precision_sv) sass_option_set_precision (sass_options, SvUV(*precision_sv));
532534
if (source_map_root_sv) sass_option_set_source_map_root (sass_options, safe_svpv(*source_map_root_sv, ""));
533535
if (source_map_file_sv) sass_option_set_source_map_file (sass_options, safe_svpv(*source_map_file_sv, ""));
534536

537+
// do not set anything if the option is set to undef
538+
if (isSafeSv(indent_sv)) sass_option_set_indent (sass_options, SvPV_nolen(*indent_sv));
539+
if (isSafeSv(linefeed_sv)) sass_option_set_linefeed (sass_options, SvPV_nolen(*linefeed_sv));
540+
if (isSafeSv(precision_sv)) sass_option_set_precision (sass_options, SvUV(*precision_sv));
541+
535542
if (importer_sv) { sass_option_set_importer(sass_options, sass_make_importer(sass_importer, *importer_sv)); }
536543

537544
if (sass_functions_sv) {

t/01_xs.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use strict;
77
use warnings;
88

9-
use Test::More tests => 40;
9+
use Test::More tests => 46;
1010
BEGIN { use_ok('CSS::Sass') };
1111

1212
my $r;
@@ -53,6 +53,17 @@ $r = CSS::Sass::compile_sass("\n.valid {\n color: red; }", { source_comments =>
5353
is ($r->{error_status}, 0, "source_comments=>[] no error_status and doesn't crash");
5454
is ($r->{error_message}, undef, "source_comments=>[] error_message is undef");
5555

56+
# $options->{indent}
57+
$r = CSS::Sass::compile_sass('foo { color: red; }', { indent => '-äöü-' });
58+
is ($r->{error_status}, 0, "import no error_status");
59+
is ($r->{error_message}, undef, "import error_message is undef");
60+
like ($r->{output_string}, qr/foo {\r?\n-äöü-color: red; }/, "custom indent");
61+
62+
# $options->{linefeed}
63+
$r = CSS::Sass::compile_sass('foo { color: red; }', { linefeed => "-äöü-\r" });
64+
is ($r->{error_status}, 0, "import no error_status");
65+
is ($r->{error_message}, undef, "import error_message is undef");
66+
like ($r->{output_string}, qr/foo {-äöü-\r color: red; }/, "custom linefeed");
5667

5768
# $options->{include_paths}
5869
$r = CSS::Sass::compile_sass('@import "colors"; .valid { color: $red; }', { });

t/sass-spec

Submodule sass-spec updated 272 files

0 commit comments

Comments
 (0)