aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-06-01 22:08:16 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-06-01 22:09:26 +0100
commit88f235ed2bd4e7101bec9e9435ca2a13143fe30c (patch)
treee3ae13d1a35ab19669e201f97cd7c21cb6632c9c /bin
parent7118fe5e033d6af9ac8eae6c69278791d5e8547d (diff)
Add inline-image Sass function.
The move to libsass missed out one function call, that inline images as data URIs, which wasn't spotted as it didn't error.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/make_css14
1 files changed, 14 insertions, 0 deletions
diff --git a/bin/make_css b/bin/make_css
index 29f2e8523..a98dc6bba 100755
--- a/bin/make_css
+++ b/bin/make_css
@@ -16,6 +16,8 @@ use File::ChangeNotify;
use File::Find::Rule;
use File::Slurp;
use Getopt::Long;
+use MIME::Base64;
+use MIME::Types;
use Path::Tiny;
use Pod::Usage;
@@ -29,9 +31,21 @@ GetOptions(
) or pod2usage(2);
pod2usage(1) if $help;
+my $mime_types = MIME::Types->new;
+
my $sass = CSS::Sass->new(
output_style => SASS_STYLE_COMPRESSED,
dont_die => 1,
+ sass_functions => {
+ 'inline-image($url)' => sub {
+ my ($url) = @_;
+ die '$url should be a string' unless $url->isa("CSS::Sass::Value::String");
+ # URL is given with reference to the file, which we don't have here. Assume.
+ my $data = encode_base64(path("web/cobrands/fixmystreet/$url")->slurp_raw, "");
+ my $type = $mime_types->mimeTypeOf($url);
+ return "url('data:$type;base64,$data')";
+ }
+ },
);
# Get directories from the command line, defaulting to 'web' if none.