Skip to content

Commit 6455908

Browse files
committed
Update for libsass 3.2.0 release
1 parent e68673b commit 6455908

File tree

13 files changed

+265
-68
lines changed

13 files changed

+265
-68
lines changed

Build.PL

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,12 @@ my %config = (
211211
extend.cpp file.cpp output.cpp parser.cpp prelexer.cpp emitter.cpp position.cpp
212212
sass.cpp sass_interface.cpp sass_functions.cpp sass_values.cpp sass_context.cpp
213213
source_map.cpp to_c.cpp to_string.cpp units.cpp utf8_string.cpp util.cpp cssize.cpp
214-
contextualize_eval.cpp listize.cpp
214+
contextualize_eval.cpp listize.cpp lexer.cpp
215215
) ]
216216
},
217217
config => { ld => 'c++' }, # Need to link with a C++ linker since libsass is C++ (even though the .xs file is not)
218218
);
219219

220-
$config{'requires'}->{'Win32::Unicode::File'} = 0 if ($^O eq "MSWin32");
221-
222220
my $builder = Module::Build::Custom->new(%config);
223221

224222
$builder->create_build_script();

Changes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
CSS::Sass (3.2.0)
2+
3+
* Update to latest libsass release (3.2.0)
4+
* Add options for remaining output styles
5+
* Add indent and linefeed config options
6+
* Add benchmark option to command line tool
7+
* Add watcher option to recompile on changes
8+
* Refactor for libsass context option initializing
9+
* Expose `resolve_file` function on the C-API
10+
* Add experimental API for multiple importers
11+
* Add highly experimental API for custom headers
12+
113
CSS::Sass (3.1.0)
214

315
* Updates to latest libsass version (3.1.0)

bin/psass.pl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
# init options
4343
my $watchdog;
44+
my $benchmark;
4445
my $precision;
4546
my $output_file;
4647
my $output_style;
@@ -69,8 +70,9 @@ sub version {
6970
# get options
7071
GetOptions (
7172
'help|h' => sub { pod2usage(1); },
72-
'watch|w' => \ $watchdog,
73+
'watch|w!' => \ $watchdog,
7374
'version|v' => \ &version,
75+
'benchmark|b!' => \ $benchmark,
7476
'indent=s' => \ $indent,
7577
'linefeed=s' => \ $linefeed,
7678
'precision|p=s' => \ $precision,
@@ -117,6 +119,9 @@ sub version {
117119
if (defined $ARGV[1] && $ARGV[1] ne '-')
118120
{ $output_file = $ARGV[1]; }
119121

122+
# check if the benchmark module is available
123+
if ($benchmark && ! eval "use Benchmark; 1" )
124+
{ die "Error loading Benchmark module\n", $@; }
120125

121126
####################################################################################################
122127
# get sass standard option list
@@ -154,6 +159,9 @@ ()
154159
# variables
155160
my ($css, $err, $stats);
156161

162+
# get benchmark stamp before compiling
163+
my $t0 = $benchmark ? Benchmark->new : 0;
164+
157165
# open filehandle if path is given
158166
if (defined $ARGV[0] && $ARGV[0] ne '-')
159167
{
@@ -169,6 +177,11 @@ ()
169177
);
170178
}
171179

180+
# get benchmark stamp after compiling
181+
my $t1 = $benchmark ? Benchmark->new : 0;
182+
# only print benchmark result when module is available
183+
if ($benchmark) { print timestr(timediff($t1, $t0)), "\n"; }
184+
172185
# process return status values
173186
if (defined $css)
174187
{
@@ -233,6 +246,7 @@ =head1 SYNOPSIS
233246
-s, --source-map-contents include original contents
234247
-m, --source-map-file=file create and write source-map to file
235248
--no-source-map-url omit sourceMappingUrl from output
249+
--benchmark print benchmark for compilation time
236250
237251
=head1 OPTIONS
238252

lib/CSS/Sass.pm

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ require XSLoader;
5656
XSLoader::load('CSS::Sass', $VERSION);
5757
require CSS::Sass::Type;
5858

59-
sub new {
59+
sub new
60+
{
6061
my ($class, %options) = @_;
6162
# Ensure initial sub structures on options
6263
$options{plugin_paths} = [] unless exists $options{plugin_paths};
@@ -66,64 +67,100 @@ sub new {
6667
bless { options => \%options }, $class;
6768
};
6869

69-
sub options {
70+
sub options
71+
{
7072
shift->{options}
7173
}
7274

73-
sub last_error {
75+
sub last_error
76+
{
7477
my ($self) = @_;
7578
$self->{last_error}
7679
}
7780

78-
sub sass_compile {
81+
my @path_types = (
82+
'plugin_paths',
83+
'include_paths'
84+
);
85+
86+
# directory delimiter according to platform
87+
my $dir_delim = $^O eq 'MSWin32' ? ';' : ':';
88+
89+
# normalize option hash
90+
my $normalize_options = sub
91+
{
92+
my ($options) = @_;
93+
# gather all functions
94+
# they need to be hashes
95+
my %functions =
96+
(
97+
%{$options->{'functions'} || {}},
98+
%{$options->{'sass_functions'} || {}}
99+
);
100+
# create functions array
101+
# help the c code a little
102+
my @functions = map { [
103+
$_, $functions{$_}
104+
] } keys %functions;
105+
# gather all importers
106+
# they need to be arrays
107+
my @importers =
108+
map {
109+
ref($_) eq "ARRAY" ?
110+
$_ : [ $_, 0 ];
111+
}
112+
grep { defined }
113+
(
114+
$options->{'importer'},
115+
@{$options->{'importers'} || []},
116+
@{$options->{'sass_importers'} || []}
117+
);
118+
# gather all paths strings
119+
foreach my $type (@path_types)
120+
{
121+
$options->{$type} = join $dir_delim,
122+
map { split $dir_delim, $_ }
123+
@{$options->{$type} || []};
124+
}
125+
# now normalize the original hash
126+
$options->{'functions'} = \@functions;
127+
$options->{'importers'} = \@importers;
128+
# remove importer from options
129+
# it is now included in importers
130+
delete $options->{'importer'};
131+
# return pointer
132+
return $options;
133+
};
134+
135+
sub sass_compile
136+
{
79137
my ($sass_code, %options) = @_;
80138
no warnings 'uninitialized';
81-
my $r = compile_sass($sass_code, { %options,
82-
# Override sass_functions with the arrayref of arrayrefs that the XS expects.
83-
!$options{sass_functions} ? ()
84-
: (sass_functions => [ map { [ $_ => $options{sass_functions}->{$_} ]
85-
} keys %{$options{sass_functions}} ]),
86-
# Override include_paths with a ':' separated list
87-
!$options{include_paths} ? ()
88-
: (include_paths => join($^O eq 'MSWin32' ? ';' : ':',
89-
@{$options{include_paths}})),
90-
# Override plugin_paths with a ':' separated list
91-
!$options{plugin_paths} ? ()
92-
: (plugin_paths => join($^O eq 'MSWin32' ? ';' : ':',
93-
@{$options{plugin_paths}})),
94-
});
139+
$normalize_options->(\%options);
140+
my $r = compile_sass($sass_code, \%options);
95141
wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string}
96142
}
97143

98-
sub sass_compile_file {
144+
sub sass_compile_file
145+
{
99146
my ($input_path, %options) = @_;
100147
no warnings 'uninitialized';
101-
my $r = compile_sass_file($input_path, { %options,
102-
# Override sass_functions with the arrayref of arrayrefs that the XS expects.
103-
!$options{sass_functions} ? ()
104-
: (sass_functions => [ map { [ $_ => $options{sass_functions}->{$_} ]
105-
} keys %{$options{sass_functions}} ]),
106-
# Override include_paths with a ':' separated list
107-
!$options{include_paths} ? ()
108-
: (include_paths => join($^O eq 'MSWin32' ? ';' : ':',
109-
@{$options{include_paths}})),
110-
# Override plugin_paths with a ':' separated list
111-
!$options{plugin_paths} ? ()
112-
: (plugin_paths => join($^O eq 'MSWin32' ? ';' : ':',
113-
@{$options{plugin_paths}})),
114-
});
148+
$normalize_options->(\%options);
149+
my $r = compile_sass_file($input_path, \%options);
115150
wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string}
116151
}
117152

118-
sub compile {
153+
sub compile
154+
{
119155
my ($self, $sass_code) = @_;
120156
my ($compiled, $stats);
121157
($compiled, $self->{last_error}, $stats) = sass_compile($sass_code, %{$self->options});
122158
croak $self->{last_error} if $self->{last_error} && !$self->options->{dont_die};
123159
wantarray ? ($compiled, $stats) : $compiled
124160
}
125161

126-
sub compile_file {
162+
sub compile_file
163+
{
127164
my ($self, $sass_file) = @_;
128165
my ($compiled, $stats);
129166
($compiled, $self->{last_error}, $stats) = sass_compile_file($sass_file, %{$self->options});
@@ -494,7 +531,7 @@ L<The CSS::Sass Home Page|https://github.com/sass/perl-libsass>
494531
495532
=head1 AUTHOR
496533
497-
David Caldwell E<lt>[email protected]E<gt>
534+
David Caldwell E<lt>[email protected]E<gt>
498535
Marcel Greter E<lt>[email protected]E<gt>
499536
500537
=head1 LICENSE

0 commit comments

Comments
 (0)