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

Support other value types + unquote colors and CSS lengths #2

Merged
merged 6 commits into from
May 8, 2017
Merged

Support other value types + unquote colors and CSS lengths #2

merged 6 commits into from
May 8, 2017

Conversation

VitorLuizC
Copy link
Contributor

@VitorLuizC VitorLuizC commented Dec 30, 2016

  • Inject booleans, numbers, null values as literals.
    Parsing
    {
      lineHeight: 1.5,
      theme: null,
      responsive: false
    }
    Inject into SASS
    $lineHeight: 1.5;
    $theme: null;
    $responsive: false
  • Inject Array as SASS-List.
    Parsing
    {
      colors: ['red', 'green', 'blue']
    }
    Inject into SASS
    $colors: (red, green, blue);
  • Inject Object as SASS-Map
    Parsing
    {
      font: { family: 'sans-serif', size: '1.6em', color: 'rgb(50, 50, 50)' }
    }
    Inject into SASS
    $font: ('family': 'sans-serif', size: 1.6em, color: rgb(50, 50, 50));
  • Inject color and length values without quotes
    Parsing
    {
      theme: 'rgb(128, 0, 128)',
      maxSize: '1250px'
    }
    Inject into SASS
    $theme: rgb(128, 0, 128);
    $maxSize: 1250px;

@thaerlabs
Copy link

+1 to merge this

@VitorLuizC
Copy link
Contributor Author

I've maded a module to parse to sass values and there's a way to use it with gulp.

const gulp = require('gulp');
const parse = require('parse-sass-value');
const header = require('gulp-header');
const vars = object => header(
  Object
    .keys(object)
    .map(key => `$${key}: ${parse(object[key])};`)
    .join('\n')
);

gulp.task('build', () => {
  gulp.src('./index.scss')
    .pipe(vars({ theme: 'flat-green' }))
    .pipe(gulp.dest('./'));
});

Replaced parse function to parse-sass-value module and Stream hell to
gulp-header. It's better to keep just "inject sass vars" responsability.
@pmrotule
Copy link

pmrotule commented May 5, 2017

In the usage example, it shows that the plugin can pass integers but it doesn't. It throws this error value.match is not a function since match() won't work with numbers:

Object.keys(vars).map((key) => {
  let value = vars[key];
  if ( !value.match(regexp) ) value = `"${value}"`; //<-- ERROR
  sassVars.push(`$${key}: ${value};`);
});

+1 to merge this

@giowe giowe merged commit 9fb24a4 into giowe:master May 8, 2017
@giowe
Copy link
Owner

giowe commented May 8, 2017

Tnx! sorry for the delay but I'm currently working on other projects and I missed it!

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.

None yet

4 participants