From 88f235ed2bd4e7101bec9e9435ca2a13143fe30c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 1 Jun 2016 22:08:16 +0100 Subject: 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. --- bin/make_css | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'bin') 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. -- cgit v1.2.3