Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore parts of sass file for parsing

Tags:

css

sass

liquid

I'm trying to get SASS to ignore part of my .scss code while parsing.

It's for a shopify theme that I'm making. My scss files are compiled into .css.liquid files so that I can put shopify's templating language liquid into the css too.

I want the compiled css.liquid to look like this:

.header--logo {
  background: url({{ 'header-logo.png' | asset_url }}) 0 0 no-repeat;
}

In LESS I used to do this:

.header--logo {
  background: ~"{{ 'header-logo.png' | asset_url }}" 0 0 no-repeat;
}

Does SASS also have an easy way to do the same?

Thanks!

like image 490
Harold Avatar asked Aug 05 '14 10:08

Harold


People also ask

What is @import in Sass?

Sass Importing Files The @import directive allows you to include the content of one file in another. The CSS @import directive has a major drawback due to performance issues; it creates an extra HTTP request each time you call it.

What is silent comment in Sass?

Nothing in a single-line comment is emitted as CSS; as far as Sass is concerned, they may as well not exist. They're also called silent comments, because they don't produce any CSS. Multi-line comments start with /* and end at the next */ .

How do I run a variable from another file in SCSS?

To use variables across multiple files in SASS is carried out by @import rule of SASS. @import rule which import Sass and CSS stylesheets for providing variables, @mixins and functions. Such that combine all stylesheets together for compiled css. It also imports URL such as frameworks like Bootstrap etc..

How do I watch a SCSS file?

Open up Terminal and type the command cd desktop/project . This will bring you to the correct working directory on your desktop. Once you're in the project directory, write the command sass --watch scss:css to begin auto-compiling your Sass to CSS—provided you've already created the “scss” directory.


1 Answers

Sass doesn't provide an escape-all-the-declaration feature.

To pass a CSS value as-is, without being parsed with Sass, put it into quotes and use the unquote() function to remove the quotes:

.header--logo {
  background: unquote("url({{ 'header-logo.png' | asset_url }}) 0 0 no-repeat");
}

If you use that very often, you can make it a tad easier with a helper function:

@function i($str) {
  @return unquote($str);
}

.header--logo {
  background: i("url({{ 'header-logo.png' | asset_url }}) 0 0 no-repeat");
}

Alternatively, you can "igonre" a part of the value rather than the whole value. You'll need interpolation to do this, i. e. #{unquote('...')}. Example usage:

.header--logo {
  background: url(#{unquote("{{ 'header-logo.png' | asset_url }}")}) 0 0 no-repeat;
}

Demo of all approaches: http://sassmeister.com/gist/4920a805f0451192ec9b

like image 110
Andrey Mikhaylov - lolmaus Avatar answered Sep 29 '22 18:09

Andrey Mikhaylov - lolmaus