Skip to content
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

Handle Sass values #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Handle Sass values #4

wants to merge 1 commit into from

Conversation

xzyfer
Copy link
Member

@xzyfer xzyfer commented Jul 24, 2018

Currently we coerce all values into quoted Sass Strings.

This PR coerces the JSON value into the appropriate Sass value type.
If the value type cannot be determined we fallback to a quoted
Sass String to avoid errors.

This differs from prior work in that no attempt is made to
mangle JSON arrays and maps into a JSON string value.

Fixes #3

Currently we coerce all values into quoted Sass Strings.

This PR coerces the JSON value into the appropriate Sass value type.
If the value type cannot be determined we fallback to a quoted
Sass String to avoid errors.

This differs from [prior work][1] in that no attempt is made to
mangle JSON arrays and maps into a JSON string value.

[1]: pmowrer/node-sass-json-importer#5

Fixes #3
@jonscottclark
Copy link

jonscottclark commented Dec 13, 2018

Really nice! Removes the need for any sanitization of inputs after grabbing them from the map. I was relying on sassdash's _.to-number and coercing the result a pixel value.. yuck. This is much better.

Quick test and things look great.

Input:

{
  "color": "#f00",
  "size": "24px",
  "font": "1.5em",
  "darkColor": "darken(#f00, 15%)"
}
@import "config.json";

$color: map-get($config, "color");
$size: map-get($config, "size");
$font: map-get($config, "font");
$darkColor: map-get($config, "darkColor");

body {
  padding: $size + 2px;
  color: lighten($color, 10%);
  font-size: $font * 1.5;
  background-color: $darkColor;
}

Output

body {
  padding: 26px;
  color: #ff3333;
  font-size: 2.25em;
  background-color: #b30000;
}

@jonscottclark
Copy link

jonscottclark commented Dec 13, 2018

@xzyfer The only thing I can think that's missing from this is handling booleans.

Input

{
  "bool": false
}
@import "config.json";

$bool: map-get($config, "bool");

body {
  @if $bool {
    padding: 0px;
  } @else {
    padding: 123px;
  }
  &:before {
    content: $bool;
  }
}

Output

body {
  padding: 0px;
}
body:before {
  content: "false";
}

The @if statement is true since it's just being evaluated as a string.

@xzyfer
Copy link
Member Author

xzyfer commented Dec 13, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants