Last active
January 1, 2016 08:29
-
-
Save kelly/8118725 to your computer and use it in GitHub Desktop.
Store your colors, or other variables in json. This will convert to sass variables.
usage: "coffee sassyJSON.coffee --input file.json"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require 'underscore' | |
beautify = require('js-beautify').css | |
stdio = require 'stdio' | |
fs = require 'fs' | |
opts = stdio.getopt | |
'input': | |
description: 'input', | |
mandatory: true, | |
args: 1, | |
'output': | |
description: 'output', | |
args: 1 | |
parseVars = (obj) -> | |
str = '' | |
_.each obj, (val, key, list) -> | |
if typeof val == 'string' | |
str += sassify key, val | |
else | |
str += sassifyMixin(key, parseVars(val)) | |
str | |
sassify = (key, val) -> | |
"$#{key}: #{val};" | |
sassifyMixin = (key, str) -> | |
"@mixin #{key} { #{str} }" | |
sassyJSON = (opts) -> | |
file = fs.readFileSync opts.input | |
json = JSON.parse(file) | |
sass = parseVars json | |
res = beautify(sass, indent_size: 2) | |
if opts.output | |
fs.writeFile opts.output, res, (err) -> | |
if err then console.log err | |
else | |
console.log res | |
sassyJSON(opts) | |
module.exports = sassyJSON |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment