Git Product home page Git Product logo

gulp-json-sass's Introduction

Gulp-json-sass

Gulp plugin for turning JSON files into files of scss/sass variable definitions.

Issues should be reported on the issue tracker.

This JSON file can also be read by your Javascript. This will make it easier to keep your JS code used for layout and your CSS code in sync.

Supports all JSON objects, including nested objects, arrays and keys which are not legal key names (variable names that begin with a number will be prefixed; variable names containing illegal characters will have those characters escaped.)

Ignores (passes through) files with a extensions other than .json.

Installation

npm install --save gulp-json-sass

Example

In this example gulpfile, a JSON file is turned into a file of sass variables, concatenated with a sass file, and compiled using gulp-ruby-sass.

var jsonSass = require('gulp-json-sass'),
    gulp = require('gulp'),
    concat = require('gulp-concat'),
    sass = require('gulp-ruby-sass');

gulp.task('sass', function() {
  return gulp
    .src(['example.json', 'example.sass'])
    .pipe(jsonSass({
      sass: true
    }))
    .pipe(concat('output.sass'))
    .pipe(sass())
    .pipe(gulp.dest('out/'));
});

API

jsonSass(options)

Returns: stream

options

Type: object

delim

Type: string
Default: -

String used to delimit nested objects. For example, if delim is '-', then

{
  "someObject" : {
    "someKey" : 123
  }
}

will be converted into (in scss mode):

$someObject-someKey: 123;

Note that keys can contain the delimiter. No attempt is made to ensure that variable names are unique.

Sass

Type: boolean
Default: false

If truthy, output valid sass variables. If false, output scss variables.

ignoreJsonErrors

Type: boolean
Default: false

If true, malformed JSON does not result in the plugin emitting an error.

escapeIllegalCharacters

Type: boolean
Default: true

If true, escapes illegal characters in variable names with a backslash (\). See http://stackoverflow.com/questions/17191265/legal-characters-for-sass-and-scss-variable-names

The following characters are escaped: !"#$%&'()*+,./:;<=>?@[]^{|}~ and white space.

prefixFirstNumericCharacter

Type: boolean
Default: true

If true, top-level keys that begin with a number will be prefixed with options.firstCharacter, but not keys of nested objects. For example,

{
  "1maca" : {
    "2maca" : "asdf"
  },
  "3maca" : "rena"
}

Will result in, in scss mode, with options.firstCharacter and options.delim left as the defaults:

$_1maca-2maca: asdf;
$_3maca: rena;
firstCharacter

Type: string
Default: _

What string to use to prefix numeric top-level keys.

License

MIT.

gulp-json-sass's People

Contributors

halerankin avatar jblandry avatar rbalicki2 avatar

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.