Code Monkey home page Code Monkey logo

sass-maps-to-json's Introduction

Convert Sass Colour Maps to Json for Fractal NPM version

This library will convert a SASS/SCSS color map into a JSON file for the sole purpose of being used for a Fractal styleguide.

The format of the color map can only include HEX values, lighten/darken, and references to other variables are not supported.

Install

$ npm install --save sass-maps-to-json -D

This script can be used as part of a gulp task, or standalone as a script you run from the command line.

Parameters

Name Type Description
src string A string containing a path to the input file.
dest string JSON file destination

Usage - Option 1 - Gulp task

Example (as a gulp task):

var gulp = require('gulp');
var sassMapToJson = require('sass-maps-to-json');
gulp.task('sassToJson', function() {
   var settings = {
      "src": "sass/settings/_colors.scss",
      "dest": "colors.config.json"
    };
   sassMapToJson(settings);
});  

Usage - Option 2 - NPM task

Create a js file in your project (convertsass.js in this example)

var sassMapToJson = require('sass-maps-to-json');
   var settings = {
      "src": "sass/settings/_colors.scss",
      "dest": "colors.config.json"
};  
sassMapToJson(settings);

Then in your package.json file create a script that will execute this:

  "scripts": {
    "convert-sass": "node convertsass.js"
  },
Input:
$palette: (
    red: (
        light: #fff2f1,
        mid: #ff7369,
        dark: #c90d00
    ),
    blue: (
        lightest: #5e7298,
        light: #404d69
    ),
    black: #000,
    white: #fff,
    grey: #333
)!default;
Output:
{
  "context": {
    "colors": {
      "Red": {
        "swatches": [
          {
            "name": "light",
            "groupcollated": "(red, light)",
            "hex": "#fff2f1"
          },
          {
            "name": "mid",
            "groupcollated": "(red, mid)",
            "hex": "#ff7369"
          },
          {
            "name": "dark",
            "groupcollated": "(red, dark)",
            "hex": "#c90d00"
          }
        ]
      },
      "Blue": {
        "swatches": [
          {
            "name": "lightest",
            "groupcollated": "(blue, lightest)",
            "hex": "#5e7298"
          },
          {
            "name": "light",
            "groupcollated": "(blue, light)",
            "hex": "#404d69"
          }
        ]
      },
      "Other": {
        "swatches": [
          {
            "name": "black",
            "hex": "#000"
          },
          {
            "name": "white",
            "hex": "#fff"
          },
          {
            "name": "grey",
            "hex": "#333"
          }
        ]
      }
    }
  }
}

Fractal Usage

The drive for this script was to create as much of a "live" styleguide as possible, and we use Fractal to generate a static site in our build process from our up to date sass files. Fractal uses handlebars.js as a template engine.

I have included an example in the fractal_examples directory of this project which should help get you up and running. The file will output a section with named title for each group containing the colour name, and hex value

Changelog

v1.1.0 - 08-Aug-2018

  • Updated output. Swatch now outputs name and groupcollated as well as the hex value

v1.0.1 - 07-Aug-2018

  • Docs update

v1.0.0 - 06-Aug-2018

  • initial release

sass-maps-to-json's People

Contributors

ryan-bendel avatar ryanbendel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

octokas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.