0

There's some ruby-on-rails project with a lot of scss files. Images stored in cloudinary.com cdn. Inside source scss files there's such construction:

.test {
  background-image: cloudinary-url("somepic.png",$width:10,$height:10);
}

Then we try to compile all scss files into one large scss. Cloudinary gem should substitute correct url during deploy.

This all worked before update, with old node, gulp-sass and node-sass libraries, but now we have to use new versions. And now it does not work.

Here's the error: Function cloudinary-url doesn't support keyword arguments

The function cloudinary-url really is not defined during compile. The goal is to somehow skip processing of undefined functions. So that in compiled scss file we should have the same background-image: cloudinary-url("somepic.png",$width:10,$height:10); as we have in source files. How to do that?

Kasheftin
  • 7,509
  • 11
  • 41
  • 68

1 Answers1

1

If I understand correctly, you're compiling the sass using Node and later include the result in a Rails app. Maybe what you need is to define a custom function in the node-sass configuration of your Node application. Something like (untested!):

functions: {
  "cloudinary-url": function( publicId, sassOptions) {
    var options = {}
    var i, l, key, value;

    for (i = 0, l = sassOptions.getLength(); i < l; i++) {
      key = sassOptions.getKey(i);
      value = sassOptions.getValue(i);
      options[key] = value
    }
    return new sass.types.String(cloudinary.url(publicId.getValue(), options));
  }
}

Include and configure the Cloudinary Node SDK in your Node app that compiles the sass. See also node-sass samples.

If however you wish to pass the cloudinary-url as is to the Rails app, I suggest adding it as a comment and replacing it in post-processing (e.g. by using gulp-replace).

.test {
  background-image: url(dummy.jpg); //cloudinary-url("somepic.png",$width:10,$height:10);
}

... and in gulp, after compiling the sass ...

.pipe(replace('url(dummy.jpg); //', ''))
tocker
  • 1,752
  • 1
  • 11
  • 9