Skip to content

Commit

Permalink
Update implementation for libsass 3.2.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 12, 2015
1 parent 4967ffa commit 589d490
Show file tree
Hide file tree
Showing 24 changed files with 278 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ lib/**/*.c
lib/**/*.xs
lib/**/*.pod
lib/**/*/*.pod
lib/CSS/Sass.base
lib/CSS/Sass.def
lib/CSS/Sass.exp
lib/CSS/Sass.lds
.libsass.version
*~
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "libsass"]
path = libsass
url = git://github.com/mgreter/libsass.git
url = git://github.com/sass/libsass.git
[submodule "t/sass-spec"]
path = t/sass-spec
url = git://github.com/mgreter/sass-spec.git
url = git://github.com/sass/sass-spec.git
14 changes: 7 additions & 7 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if (-d ".git") {
system "git submodule update";
open $manifest, ">", "MANIFEST" or die "MANIFEST: $!";
print $manifest "MANIFEST\n";
print $manifest ".libsass.version\n";
while (my $module = shift @modules)
{
my $cwd = getcwd;
Expand All @@ -36,17 +35,17 @@ if (-d ".git") {
}
}

if (-e "libsass/.git") {
if (-e "libsass/.git" && ! -f "libsass/VERSION") {
chdir "libsass";
my $libsass_version = `git describe --abbrev=4 --dirty --always --tags`;
chdir "..";
require File::Slurp;
chomp $libsass_version;
File::Slurp::write_file(".libsass.version", { 'binmode' => ':raw' }, $libsass_version);
File::Slurp::write_file("libsass/VERSION", { 'binmode' => ':raw' }, $libsass_version);
}
if (-f ".libsass.version") {
if (-f "libsass/VERSION") {
require File::Slurp;
$libsass_version = File::Slurp::read_file(".libsass.version", { 'binmode' => ':raw' });
$libsass_version = File::Slurp::read_file("libsass/VERSION", { 'binmode' => ':raw' });
print "using libsass version $libsass_version\n";
}

Expand Down Expand Up @@ -161,7 +160,8 @@ SUBCLASS
my $cover = $ARGV[0] && $ARGV[0] eq "cover=1" ? 1 : 0;

# create compile flags to include the libsass version (escape correctly)
my $version = qq( -DLIBSASS_VERSION=\\"\\\\\\"$libsass_version\\\\\\"\\");
my $version = ($^O ne "MSWin32") ? qq( -DLIBSASS_VERSION=\\"$libsass_version\\") :
qq( -DLIBSASS_VERSION=\\"\\\\\\"$libsass_version\\\\\\"\\");

my %config = (
module_name => 'CSS::Sass',
Expand Down Expand Up @@ -202,7 +202,7 @@ my %config = (
extra_linker_flags => ($cover ? '-lgcov -fprofile-arcs -ftest-coverage' : ''),
c_source => { 'libsass' => [ sort qw(
ast.cpp sass2scss.cpp node.cpp sass_util.cpp remove_placeholders.cpp json.cpp
base64vlq.cpp bind.cpp constants.cpp context.cpp contextualize.cpp copy_c_str.cpp
base64vlq.cpp bind.cpp constants.cpp context.cpp contextualize.cpp plugins.cpp
error_handling.cpp eval.cpp expand.cpp cencode.c functions.cpp inspect.cpp
extend.cpp file.cpp output.cpp parser.cpp prelexer.cpp emitter.cpp position.cpp
sass.cpp sass_interface.cpp sass_functions.cpp sass_values.cpp sass_context.cpp
Expand Down
18 changes: 17 additions & 1 deletion bin/psass.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
use CSS::Sass qw(SASS_STYLE_NESTED);
use CSS::Sass qw(SASS_STYLE_COMPRESSED);

####################################################################################################
# normalize command arguments to utf8
####################################################################################################

# get cmd arg encoding
use Encode::Locale qw();
# convert cmd args to utf8
use Encode qw(decode encode);
# now just decode every command arguments
@ARGV = map { decode(locale => $_, 1) } @ARGV;

####################################################################################################
# config variables
####################################################################################################
Expand All @@ -42,7 +53,8 @@ sub version {
printf " sass2scss: %s\n", CSS::Sass::sass2scss_version();
exit 0 };

# include paths
# paths arrays
my @plugin_paths;
my @include_paths;

# get options
Expand All @@ -57,6 +69,7 @@ sub version {
'source-map-embed|e!' => \ $source_map_embed,
'source-map-contents|s!' => \ $source_map_contents,
'no-source-map-url!' => \ $omit_source_map_url,
'plugin-path|L=s' => sub { push @plugin_paths, $_[1] },
'include-path|I=s' => sub { push @include_paths, $_[1] }
);

Expand Down Expand Up @@ -88,6 +101,7 @@ sub version {
precision => $precision,
output_path => $output_file,
output_style => $output_style,
plugin_paths => \ @plugin_paths,
include_paths => \ @include_paths,
source_comments => $source_comments,
source_map_file => $source_map_file,
Expand All @@ -104,6 +118,7 @@ sub version {
precision => $precision,
output_path => $output_file,
output_style => $output_style,
plugin_paths => \ @plugin_paths,
include_paths => \ @include_paths,
source_comments => $source_comments,
source_map_file => $source_map_file,
Expand Down Expand Up @@ -151,6 +166,7 @@ =head1 SYNOPSIS
-p, --precision precision for float output
-o, --output-file=file output file to write result to
-t, --output-style=style output style [nested|compressed]
-L, --plugin-path=path plugin load path (repeatable)
-I, --include-path=path sass include path (repeatable)
-c, --source-comments enable source debug comments
-e, --source-map-embed embed source-map in mapping url
Expand Down
23 changes: 10 additions & 13 deletions lib/CSS/Sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ CSS::Sass - Compile .scss files using libsass


# Object Oriented API w/ options
my $sass = CSS::Sass->new(include_paths => ['some/include/path'],
image_path => 'base_url',
my $sass = CSS::Sass->new(plugin_paths => ['plugins'],
include_paths => ['some/include/path'],
output_style => SASS_STYLE_COMPRESSED,
source_map_file => 'output.css.map',
source_comments => 1,
Expand Down Expand Up @@ -55,7 +55,6 @@ CSS::Sass - Compile .scss files using libsass
# Functional API w/ options
my ($css, $err, $srcmap) = sass_compile('A { color: red; }',
include_paths => ['some/include/path'],
image_path => 'base_url',
output_style => SASS_STYLE_NESTED,
source_map_file => 'output.css.map');

Expand Down Expand Up @@ -143,6 +142,10 @@ feature parity and heading towards 3.4. It can compile .scss and .sass files.
actually be created, but its content will be returned to the caller. It
will also enable sourceMappingURL comment by default. See `no_src_map_url`.

- `source_map_root`

A path (string) that is directly embedded in the source map as `sourceRoot`.

- `source_map_embed`

Embeds the complete source-map content into the sourceMappingURL, by using
Expand All @@ -164,17 +167,11 @@ feature parity and heading towards 3.4. It can compile .scss and .sass files.
This is an arrayref that holds the list a of paths to search (in addition to
the current directory) when following Sass `@import` directives.

- `image_path`

This is a string that holds the base URL. This is only used in the
(non-standard) `image-url()` Sass function. For example, if `image_path`
is set to `'file:///tmp/a/b/c'`, then the follwoing Sass code:

.something { background-image: image-url("my/path"); }

...will compile to this:
- `plugin_paths`

.something { background-image: url("file:///tmp/a/b/c/my/path"); }
This is an arrayref that holds a list of paths to search for third-party
plugins. It will automatically load any <dll> or <so> library within that
directory. This is currently a highly experimental libsass feature!

- `dont_die`

Expand Down
34 changes: 20 additions & 14 deletions lib/CSS/Sass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ our @EXPORT = qw(
SASS2SCSS_CONVERT_COMMENT
);

our $VERSION = "v3.1.1";
our $VERSION = "v3.2.0";

require XSLoader;
XSLoader::load('CSS::Sass', $VERSION);
Expand All @@ -59,6 +59,7 @@ require CSS::Sass::Type;
sub new {
my ($class, %options) = @_;
# Ensure initial sub structures on options
$options{plugin_paths} = [] unless exists $options{plugin_paths};
$options{include_paths} = [] unless exists $options{include_paths};
$options{sass_functions} = {} unless exists $options{sass_functions};
# Create and return new object with options
Expand Down Expand Up @@ -86,6 +87,10 @@ sub sass_compile {
!$options{include_paths} ? ()
: (include_paths => join($^O eq 'MSWin32' ? ';' : ':',
@{$options{include_paths}})),
# Override plugin_paths with a ':' separated list
!$options{plugin_paths} ? ()
: (plugin_paths => join($^O eq 'MSWin32' ? ';' : ':',
@{$options{plugin_paths}})),
});
wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string}
}
Expand All @@ -102,6 +107,10 @@ sub sass_compile_file {
!$options{include_paths} ? ()
: (include_paths => join($^O eq 'MSWin32' ? ';' : ':',
@{$options{include_paths}})),
# Override plugin_paths with a ':' separated list
!$options{plugin_paths} ? ()
: (plugin_paths => join($^O eq 'MSWin32' ? ';' : ':',
@{$options{plugin_paths}})),
});
wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string}
}
Expand Down Expand Up @@ -151,8 +160,8 @@ CSS::Sass - Compile .scss files using libsass
# Object Oriented API w/ options
my $sass = CSS::Sass->new(include_paths => ['some/include/path'],
image_path => 'base_url',
my $sass = CSS::Sass->new(plugin_paths => ['plugins'],
include_paths => ['some/include/path'],
output_style => SASS_STYLE_COMPRESSED,
source_map_file => 'output.css.map',
source_comments => 1,
Expand Down Expand Up @@ -182,7 +191,6 @@ CSS::Sass - Compile .scss files using libsass
# Functional API w/ options
my ($css, $err, $srcmap) = sass_compile('A { color: red; }',
include_paths => ['some/include/path'],
image_path => 'base_url',
output_style => SASS_STYLE_NESTED,
source_map_file => 'output.css.map');
Expand Down Expand Up @@ -286,6 +294,10 @@ Setting this option enables the source-map generating. The file will not
actually be created, but its content will be returned to the caller. It
will also enable sourceMappingURL comment by default. See C<no_src_map_url>.
=item C<source_map_root>
A path (string) that is directly embedded in the source map as C<sourceRoot>.
=item C<source_map_embed>
Embeds the complete source-map content into the sourceMappingURL, by using
Expand All @@ -307,17 +319,11 @@ Setting this options makes C<source_map_embed> useless.
This is an arrayref that holds the list a of paths to search (in addition to
the current directory) when following Sass C<@import> directives.
=item C<image_path>
This is a string that holds the base URL. This is only used in the
(non-standard) C<image-url()> Sass function. For example, if C<image_path>
is set to C<'file:///tmp/a/b/c'>, then the follwoing Sass code:
.something { background-image: image-url("my/path"); }
...will compile to this:
=item C<plugin_paths>
.something { background-image: url("file:///tmp/a/b/c/my/path"); }
This is an arrayref that holds a list of paths to search for third-party
plugins. It will automatically load any <dll> or <so> library within that
directory. This is currently a highly experimental libsass feature!
=item C<dont_die>
Expand Down
Loading

0 comments on commit 589d490

Please sign in to comment.