-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed hugo:vars casting #10718
Fixed hugo:vars casting #10718
Conversation
Thanks for this. I don't doubt that you describe a real problem, but I'm a little fearful about pulling parts of the Sass spec into Hugo (how do we know it's complete and how do we maintain it?) I was rather hoping that Sass'
|
You're welcome. I gave it another look and you are not completely wrong either. It seems like that all the variables passed to the Sass compiler are passed as string and interpreted like that even pixel values or numbers. So when using Sass specific functions like darken(), etc. it will throw an error because the variable is of type string. When the Sass file then is converted to Css the values will be casted with the correct type. That is why you can use them in Css functions like calc(). Your fear about implementing this directly in hugo is justified. Just as a clarification the specs come directly from Css and not Sass. Basically I took all the color specs from here https://developer.mozilla.org/en-US/docs/Web/CSS/color_value other than the experimental one. And all the identifiers for dimensions from here https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Values_and_Units#dimensions. This should only change when new features are added directly to Css. Whit this PR you are also able to pass rgb(), hsl() and hwb() and use them in Sass functions. You could even pass a calc(x + y) directly from the config file if you wish. I added this so it would cover everything. |
Thanks. I will take another look at this tomorrow -- as long as this is well defined and pretty stable, I guess it's something we can live with. |
You're welcome. |
Variables passed via the hugo:vars function where passed as type string. This caused problems when using the variables in sass functions because these expect a specific type. Now we check if the passed variables have to be quoted and therefore are of type string or if they should not be quoted and let the type interpretation up to the sass compiler. Fixes gohugoio#10632
4556a8a
to
5ae57fd
Compare
Instead of maintaing a list of all CSS units and functions this commit: * Uses 3 regexps to detect typed CSS values (e.g. `24px`) + properly handle numeric Go types. * These regexps may have some false positives -- e.g. strings that needs to be quoted. * For that rare case, you can mark the string with e.g. `"32xxx" | css.Quoted` * For the opposite case: `"32" | css.Unquoted` Updates gohugoio#10632
b872d71
to
3db1a6d
Compare
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hey there
This one took me a bit to figure out. I thought the problem was the Sass Compiler or the godartsass package but it turned out to be a problem on how we created the varsstylesheet map that is then passed to the compiler to import. All variables were quoted and therefore sass would interpret them as string. Now we pass some of these variables without quotes so that the sass compiler can do the correct type casting.
In the cssValues.go file I added all the identifier for the different css values. Now we can use them in functions and even pass functions like calc(), rgb(), etc.
I added a new test to check the type casting. All tests are passed other than the TestTransformErrors() function. I checked this with a clean clone of hugo and the error is still present there.
Fixes #10632