backbone-boilerplate / grunt-bbb-styles

WIP Grunt BBB styles compilation.
MIT License
0 stars 2 forks source link

Configure path.sep globally #6

Open eduardoarantes opened 10 years ago

eduardoarantes commented 10 years ago

My css is like this body { letter-spacing: -0.3px; background: url("../images/outer_bg.jpg") repeat; }

after bbb-styles executes it became

body {letter-spacing: -0.3px; background: url("/app\images\outer_bg.jpg") repeat;}

See the backslash.

It fails loading on the browser

I'm using windows 8

It happens on path.join()

Is it possible to set path.sep globally for nodeJs?

regards

eduardoarantes commented 10 years ago

I've addressed this issue and other that I have faced Definitions like" @font-face {font-family: "ProximaNovaLight";src: url("fonts/proximanova-light-webfont.eot");src: url("fonts/proximanova-light-webfont.eot?iefix") format("embedded-opentype"), url("fonts/proximanova-light-webfont.woff") format("woff"), url("fonts/proximanova-light-webfont.ttf") format("truetype");font-weight: normal;font-style: normal;}

were not addressed.

In order to fix I change the code of the method as below

function additionalProcessing(css, filepath) {
  var stylesheet = cssom.parse(css);
  var url = /url\([\'"]?(.[^\'"]*)?[\'"]?\)/g;
  var dir = path.dirname(filepath);
  var rel = options.forceRelative;

  function processRules(cssRules) {
    cssRules.forEach(function(rule) {
      // Iterate over all styles and find all `url` values.
      [].slice.apply(rule.style || []).forEach(function(key) {
        var value = rule.style[key];
        var match;

        // Replace the image paths.
        while (match = url.exec(value)) {
          // Ignore base64.
         if (value.indexOf("base64") === -1) {
             value = value.replace(match[1], rel + path.join(dir, match[1]));
             rule.style[key] = value.replace(/\\/g, "/");

         }
        }
      });

      if (rule.cssRules) {
        processRules(rule.cssRules);
      }
    });
  }