Skip to content

SassyExport is a lightweight Compass extension that allows you to export an encoded Sass map into an external JSON file. - added direct to js object ability

License

Notifications You must be signed in to change notification settings

johnjenkins/SassyExport

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SassyExport Gem Version

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

Installation

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

Documentation

Setup

Our file structure,

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

Sass,

// ./sass/style.scss

@import "SassyExport";

$map: (
	hello: world,
);

// SassyExport : convert passed map to json and write to path/to/filename.json
// ----------------------------------------------------------------------------------------------------
// @param $path [string] : directory path and filename
// @param $map [map] : map to convert to json
// @param $pretty [bool] : pretty print json
// @param $debug [bool] : print debug string with path
// ----------------------------------------------------------------------------------------------------
// @return $string | write json to path

@include SassyExport("/json/hello.json", $map, true);

Result

New JSON file is created at ./json/hello.json. As you can see, $path is relative to where your config.rb is located. Simply calling @include SassyExport("/hello.json", $map) will write to your directory root.

{
	"hello": "world"
}

Breakdown

The SassyExport() mixin takes a directory/filename.json $path, and a Sass $map as arguments. There is also an optional argument $pretty which defaults to false, but will print pretty JSON (nicely indented) if set to true.

It converts the $map into a JSON map through Ruby, and then 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.

Also Check Out

About

SassyExport is a lightweight Compass extension that allows you to export an encoded Sass map into an external JSON file. - added direct to js object ability

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 87.2%
  • CSS 12.8%