I'm using SASS to generate a @font-face mixin, however this:
=remotefont(!name, !url)
@font-face
font-family = !name
src = url(!url + ".eot")
src = local(!name), url(!url + ".ttf") format("truetype")
+remotefont("My font", "/myfont.ttf")
becomes this:
@font-face {
font-family: My font;
src: url(/myfont.ttf.eot);
src: local(My font), url(/myfont.ttf.ttf) format(truetype); }
No matter how much I try, I can't have it quote either "My font" (with "!name") or "truetype" (it removes the quotes). Any ideas on how I can do this?
1. quote($string) Function: This function adds the quotes to the unquoted string and returns the quoted string.
is the css class selector, #{} interpolation syntax it allows the using of the variables in selectors and property names $name: foo; $attr: border; p.
String Operators The single Sass string operator is concatenation. Strings can be concatenated (linked together) using the + operator. If you mix quoted and unquoted strings when concatenating, the result will be whichever is on the left side of the operator.
To make a dynamic variable is not possible in SASS as of now, since you will be adding/connecting another var that needs to be parsed once when you run the sass command. As soon as the command runs, it will throw an error for Invalid CSS, since all your declared variables will follow hoisting.
It can be made a little better using string interpolation:
!name = "asdf"
.foo
font-family = "\"#{!name}\""
But I agree that we need a better approach for dealing with quoted strings in sass. Sass has enough context to do something intelligent here and not offload the quoting logic to the user.
You can quote in your variables, use single quotes inside double quotes. This is how I do it:
!string = "'Myriad Pro', 'Lucida Sans', Helvetica, Arial, sans-serif"
.foo
:font-family= !string
This will compile correctly to:
.foo{
font-family: 'Myriad Pro', 'Lucida Sans', Helvetica, Arial, sans-serif; }
I think you can't quote the other way round (i.e. double quotes inside single quotes). Doing that will give you compile errors.
Hope that helped!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With