-
Notifications
You must be signed in to change notification settings - Fork 55
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
Improve sass strings #26
Conversation
Quote strings except for valid CSS colors and number/floats with units
@@ -52,7 +57,7 @@ function parseValue(value) { | |||
} else if (_.isPlainObject(value)) { | |||
return parseMap(value); | |||
} else { | |||
return value; | |||
return parseEndValue(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseEndValue
is the worst name in the world. I should rename it to parseValue
or maybe you have a better proposal :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a parseValue
function, thats why I chose parseEndValue
... 😴 💤
I'll fixup the last commit with the previous, rebase with #25 and push force once you are OK with the PR, if you are :) |
what if you want to store font family value in json?
{ "font": "'Roboto', sans-serif" }
@import conf.json;
body { font-family: $font; } Desired output of that is this: body { font-family: 'Roboto', sans-serif; } Does your changes produce output like that ? As I looked through your changes, I think your output would be this: body { font-family: "'Roboto', sans-serif"; } |
@pmowrer I've updated the PR description above with more details. It solves #5 because parser do not break when the input is And solves #16 for the same reason before. It also solves the problem with CSS colores mentioned in the PRs. |
json arrays do not map directly to sass lists as in sass list may have commas or spaces as separator. if i have maybe we have conf.json like this
and here we are using that variables from conf.json in style.scss
and we get desired output
but what if conf.json was changed to this:
to get desired output we need to wrap all variables in |
Closed due to inactivity |
From JSON strings, output quoted Sass strings except for valid CSS colors and number/floats with valid CSS units.
See the example below, JSON/JS at left, Sass output at right:
Note that quoted numbers or floats are not unquoted in the output, because you can use numbers in JSON, but they could be unquoted just adding an
?
to the regex.For the regex matching the CSS units I've taken all the units defined in mdn and in the libsass source code.
This PR is built on the top of #25 because it includes tests for JS imports too. #25 should be merged first.
It should fix problems mentioned in #5 and #16.
cc/ @pmowrer