Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
/ sassy-export Public archive

Sassy Export is a lightweight Compass extension that allows you to export an encoded Sass map into an external JSON file.

License

Notifications You must be signed in to change notification settings

ezekg/sassy-export

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sassy Export Gem Version

Sassy Export is a lightweight Sass extension that allows you to export an encoded Sass map into an external JSON file. Use it anyway you like.

Installation

  1. gem install sassy-export
  2. Add require "sassy-export" to your config.rb
  3. Import into your stylesheet with @import "sassy-export";

Documentation

Setup

Our file structure,

root
├── sass
│   ├── style.scss
├── json
└── config.rb

Sass,

// sass/style.scss

@import "sassy-export";

$map: (
	hello: world,
);

///
/// Convert passed map to json and write to <path>/<filename>.<ext>
///
/// @param {String} $path    - Directory path and filename
/// @param {Map}    $map     - Map to convert to json
/// @param {Bool}   $pretty  - Pretty print json
/// @param {Bool}   $debug   - Print debug string with path
/// @param {Bool}   $use_env - Use ENV["PWD"] for current directory instead of Dir.pwd
///
/// @return {String} - Write file to path
///
@include sassy-export("json/test.json", $map, true, true, false);

Result

New JSON file is created at json/hello.json ($path is relative to where your config.rb is located). Simply calling @include sassy-export("hello.json", $map) will write to your working directory.

{
	"hello": "world"
}

Breakdown

The sassy-export() mixin takes a \<directory\>/\<filename\>.\<ext\> $path and a Sass $map as arguments. You can export straight to a JavaScript object by using the extension .js instead of .json for the output $path.

There are also optional arguments: $pretty which defaults to false, but will print pretty JSON (nicely indented) if set to true; and $debug which will print debug information if set to true.

It converts the $map into either a JSON map or Javascript object through Ruby, then creates a new directory/file (or updates an existing directory/file), and writes the contents of the JSON string to it.

Contributions are welcome. If you believe that you could improve the small amount of code here, feel free to.

Enjoy.

About

Sassy Export is a lightweight Compass extension that allows you to export an encoded Sass map into an external JSON file.

Resources

License

Stars

Watchers

Forks

Packages

No packages published