SassyExport
SassyExport is a lightweight plugin for SassyJSON that allows you to export an encoded Sass map into an external JSON file. Use it anyway you like.
Installation
gem install SassyExport
- Add
require "SassyExport"
to yourconfig.rb
- Import into your stylesheet with
@import "SassyExport";
Documentation
Setup
// ./sass/SassyExport.scss
@mixin json_export($path, $filename, $map) {
@at-root {
%json_export {
content: "#{SassyJSON_export(unquote($path), unquote($filename), unquote(json_encode($map)))}";
}
}
}
// ./sass/style.scss
@import "SassyExport";
$map: (
hello: world,
);
@include json_export("../json", "hello", $map);
Result
New JSON file is created in ./json/hello.json
{"hello": "world"}
The json_export()
mixin takes a directory $path
, $filename
, and a Sass $map
as arguments. It then converts the $map
into a JSON map with SassyJSON's json_encode()
function, then Ruby creates a new file (or updates an existing file), and writes the contents of the json string to it. I'm no Ruby expert, so if you belive that you could improve the small amount of code here, feel free to.
Enjoy.