@@ -16,9 +16,22 @@ require Exporter;
16
16
our @ISA = qw( Exporter) ;
17
17
18
18
our @EXPORT_OK = qw(
19
+ quote
20
+ unquote
19
21
sass2scss
22
+ import_sv
20
23
sass_compile
21
24
sass_compile_file
25
+ SASS_COMMA
26
+ SASS_SPACE
27
+ SASS_ERROR
28
+ SASS_NULL
29
+ SASS_BOOLEAN
30
+ SASS_NUMBER
31
+ SASS_STRING
32
+ SASS_COLOR
33
+ SASS_LIST
34
+ SASS_MAP
22
35
) ;
23
36
24
37
our @EXPORT = qw(
@@ -107,12 +120,31 @@ sub compile_file {
107
120
108
121
sub sass_function_callback {
109
122
my $cb = shift ;
110
- my $ret = eval { $cb -> (map { CSS::Sass::Type-> new_from_xs_rep($_ ) } @_ ) };
111
- return CSS::Sass::Type::Error-> new(" $@ " )-> xs_rep if $@ ;
112
- return CSS::Sass::Type::String-> new(' ' )-> xs_rep if !defined $ret ;
113
- return CSS::Sass::Type::Error-> new(" Perl Sass function returned something that wasn't a CSS::Sass::Type" )-> xs_rep
114
- unless ref $ret && $ret -> isa(" CSS::Sass::Type" );
115
- $ret -> xs_rep;
123
+ my $ret = eval { $cb -> (@_ ) };
124
+ use Data::Dumper;
125
+
126
+
127
+ unless (UNIVERSAL::isa($ret , " CSS::Sass::Type" )) {
128
+ if (UNIVERSAL::isa($ret , " HASH" )) {
129
+ bless $ret , " CSS::Sass::Type::Map"
130
+ } elsif (UNIVERSAL::isa($ret , " ARRAY" )) {
131
+ bless $ret , " CSS::Sass::Type::List"
132
+ } elsif (UNIVERSAL::isa($ret , " REF" )) {
133
+ die " got refg" ;
134
+ }
135
+ } else {
136
+ # we are a sass type, sweet
137
+ # warn "pass only by $ret";
138
+ }
139
+
140
+ # warn Dumper $ret;
141
+
142
+ return CSS::Sass::Type::Error-> new(" $@ " ) if $@ ;
143
+
144
+ # return CSS::Sass::Type::Error->new("Perl Sass function returned something that wasn't a CSS::Sass::Type")
145
+ # unless ref $ret && $ret->isa("CSS::Sass::Type");
146
+
147
+ $ret ;
116
148
}
117
149
118
150
1;
@@ -185,11 +217,18 @@ CSS::Sass - Compile .scss files using libsass
185
217
# convert indented syntax
186
218
my $scss = sass2scss($sass);
187
219
220
+ # Import quoting functions
221
+ use CSS::Sass qw(quote unquote);
222
+
223
+ # Exchange quoted strings
224
+ my $string = unquote($from_sass);
225
+ my $to_sass = quote($string, '"');
226
+
188
227
=head1 DESCRIPTION
189
228
190
229
CSS::Sass provides a perl interface to libsass, a fairly complete Sass
191
- compiler written in C++. It is currently somewhere around ruby sass 3.2
192
- feature parity. It can compile .scss and .sass files.
230
+ compiler written in C++. It is currently somewhere around ruby sass 3.2/3.3
231
+ feature parity and heading towards 3.4 . It can compile .scss and .sass files.
193
232
194
233
=head1 OBJECT ORIENTED INTERFACE
195
234
@@ -238,10 +277,9 @@ Allows you to inspect or change the options after a call to C<new>.
238
277
239
278
=item C<($css, $err, $srcmap) = sass_compile(source_code, options) >
240
279
241
- This compiles the Sass string that is passed in the first parameter. It
242
- returns both the CSS and the error in list context and just the CSS in
243
- scalar context. One of the returned values will always be C<undef > , but
244
- never both.
280
+ Compiles the given Sass source code. It returns CSS, error and source map in
281
+ list context or just the CSS in scalar context. Either CSS or error will be
282
+ C<undef > , but never both.
245
283
246
284
=back
247
285
@@ -305,12 +343,12 @@ This is a hash of Sass functions implemented in Perl. The key for each
305
343
function should be the function's Sass signature and the value should be a
306
344
Perl subroutine reference. This subroutine will be called whenever the
307
345
function is used in the Sass being compiled. The arguments to the subroutine
308
- are L<CSS::Sass::Type> objects and the return value I< must > also be one of
309
- those types. It may also return C< undef > which is just a shortcut for
310
- CSS::Sass::Type::String ->new('') .
346
+ are L<CSS::Sass::Type> objects, which map to native perl types if possible.
347
+ You can return either L<CSS::Sass::Type> objects or supported native perl data
348
+ structures. C< undef > is an equivalent of CSS::Sass::Type::Null ->new.
311
349
312
350
The function is called with an C<eval > statement so you may use "die" to
313
- throw errors back to libsass.
351
+ throw errors back to libsass ( C< CSS::Sass::Type::Error > ) .
314
352
315
353
A simple example:
316
354
@@ -319,6 +357,7 @@ A simple example:
319
357
my ($str) = @_;
320
358
die '$str should be a string' unless $str->isa("CSS::Sass::Type::String");
321
359
return CSS::Sass::Type::String->new($str->value . " hello");
360
+ # equivalent to return $str->value . " hello";
322
361
}
323
362
}
324
363
@@ -330,10 +369,54 @@ Then the ouput would be:
330
369
331
370
some_rule: Well, hello;
332
371
372
+ =item C<Sass_Value > Types
373
+
374
+ Sass knowns various C<Sass_Value > types. We export the constants for completeness.
375
+ Each type is mapped to a package inside the C<CSS::Sass::Type > namespace.
376
+
377
+ # Value types
378
+ SASS_ERROR
379
+ SASS_NULL
380
+ SASS_BOOLEAN
381
+ SASS_NUMBER
382
+ SASS_STRING
383
+ SASS_COLOR
384
+ SASS_LIST
385
+ SASS_MAP
386
+ # List styles
387
+ SASS_COMMA
388
+ SASS_SPACE
389
+
390
+ =item Autodetection for value types returned by custom function
391
+
392
+ Many C<Sass_Value > types can be mapped directly to perl data structures.
393
+ C<maps > and C<lists > map directly to C<hashes > and C<arrays > . Scalars are
394
+ mapped to C<string > , C<number > or C<null > . You can directly return these
395
+ native data types from your custom functions or use the datastructures
396
+ to access maps and lists.
397
+
398
+ undef; # same as CSS::Sass::Type::Null->new;
399
+ 42; # same as CSS::Sass::Type::Number->new(42);
400
+ "foobar"; # same as CSS::Sass::Type::String->new("foobar");
401
+ [ 'foo', 'bar' ]; # same as CSS::Sass::Type::List->new('foo', 'bar');
402
+ { key => 'value' }; # same as CSS::Sass::Type::Map->new(key => 'value');
403
+
404
+ We bless native return values from custom functions into the correct package.
405
+
406
+ # sub get-map { return { key: "value" } };
407
+ .class { content: map-get(get-map(), key); }
408
+
409
+ # sub get-list { return [ 'foo', 42, 'bar' ] };
410
+ .class { content: nth(get-list(), 2); }
411
+
412
+
413
+
333
414
=back
334
415
335
416
=head1 MISCELLANEOUS
336
417
418
+ =over 4
419
+
337
420
=item C<SASS2SCSS_PRETTIFY_0 >
338
421
339
422
Write everything on one line (minimized)
@@ -387,12 +470,12 @@ L<The CSS::Sass Home Page|https://github.com/sass/perl-libsass>
387
470
388
471
=head1 AUTHOR
389
472
390
- David Caldwell E<lt> [email protected] E<gt>
473
+ David Caldwell E<lt> [email protected] E<gt>
391
474
Marcel Greter E<lt> [email protected] E<gt>
392
475
393
476
=head1 COPYRIGHT AND LICENSE
394
477
395
- Copyright (C) 2013 by David Caldwell
478
+ Copyright (C) 2013 by David Caldwell
396
479
Copyright (C) 2014 by Marcel Greter
397
480
398
481
This library is free software; you can redistribute it and/or modify
0 commit comments