1

How can i preserve or escape paths in sass. We have strings like "Page\Footer\CustomBar\Logo" which are (wrongly) transformed internally to "Page\footer\customBarLogo" How can we preserve the ascii format? We tried with dart sass and ruby sass.

Page\Footer\CustomBar\Logo would be expected result.

Arkellys
  • 5,562
  • 2
  • 16
  • 40
Robert
  • 176
  • 1
  • 19

1 Answers1

0

I searched a bit I didn't found any built-in way to do what you need. It seems that backslashes are hard to manipulate with SASS. However, here is how I managed to get your path:

@function createPath($path...) {
   $finalPath: null;

   @each $el in $path {
      @if($finalPath) {
         // Do not add the slashes at the beginning of the string
         $finalPath: $finalPath + "\\";
      };

      $finalPath: $finalPath + $el;
   }

   // At this point, $finalPath = "Page\\Footer\\CustomBar\\Logo"
   @return unquote("\"#{$finalPath}\"");
}

Calling createPath('Page', 'Footer', 'CustomBar', 'Logo'); will return "Page\Footer\CustomBar\Logo".

Honestly, I can't explain how the unquote works, I found the solution thanks to this answer.

Arkellys
  • 5,562
  • 2
  • 16
  • 40
  • Thank you Arkellys for your help but that is not really a solution to our problem since we inject a data structure into our sass code with strings. Of course we could have an array for this property but then i guess it makes more sense to have two backslashes which works fine. I will see if i find some more input on that issue in the next days. Thank you. – Robert Feb 19 '19 at 17:36
  • @Rob Oh okay, I think you should edit your question with more details then. :) – Arkellys Feb 19 '19 at 17:37