• This repository has been archived on 05/Mar/2021
  • Stars
    star
    169
  • Rank 217,598 (Top 5 %)
  • Language SCSS
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[UNMAINTAINED] A Sass API for JSON.

SassyJSON NPM version Gem Version

⚠️ SassyJSON was an experimental project. It is not meant to be used in production. If you need to transit JSON data from and to your Sass layer, have a look into Eyeglass and Sassport.

SassyJSON is a Sass-powered API for JSON. It provides you the classic json-encode and json-decode directly from your Sass files. We'll leave you the only judges of the point of this.

Install

SassyJSON is available on npm or as a Ruby Gem.

Git

git clone https://github.com/KittyGiraudel/SassyJSON.git && cd SassyJSON

npm

npm install sassyjson --save-dev

Compass extension

  1. gem install SassyJSON
  2. Add require 'SassyJSON' to your config.rb
  3. Import it in your stylesheets with @import 'SassyJSON'

Sass

If you only want to play around the code without cloning the repo or using npm, you can find a single file containing the whole API in the dist folder.

Also, SassyJSON is available at Sassmeister.

Example

Encoding Sass to JSON

Sass

$map: ((a: (1 2 ( b : 1 )), b: ( #444444, false, ( a: 1, b: test ) ), c: (2 3 4 string)));

@include json-encode($map);

CSS

/*! json-encode: '{"a": [1, 2, {"b": 1}], "b": ["#444444", false, {"a": 1, "b": "test"}], "c": [2, 3, 4, "string"]}' */

body::before {
  display:block;
  width:0;height:0;
  overflow:hidden;
  content: '{"a": [1, 2, {"b": 1}], "b": ["#444444", false, {"a": 1, "b": "test"}], "c": [2, 3, 4, "string"]}';
}

head {
  font-family: '{"a": [1, 2, {"b": 1}], "b": ["#444444", false, {"a": 1, "b": "test"}], "c": [2, 3, 4, "string"]}';
}

@media -json-encode {
  json {
    json: '{"a": [1, 2, {"b": 1}], "b": ["#444444", false, {"a": 1, "b": "test"}], "c": [2, 3, 4, "string"]}';
  }
}

If you want to restrict the output to only one of the three drivers (comment, media query or regular output) you can pass a flag as the second parameter with one of the four following keywords: all, comment, media or regular. Default is all.

Decoding JSON to Sass

$json-decode: json-decode('{"a": [1, 2, {"b": 1}], "b": ["#444444", false, {"a": 1, "b": "test"}], "c": [2, 3, 4, "string"]}');
// ("a": 1 2 ("b": 1), "b": #444444 false ("a": 1, "b": "test"), "c": 2 3 4 "string")

Importing and decoding a JSON file

To importe and decode an external .json file directly into a Sass variable:

@import 'SassyJSON'; // Import SassyJSON first!
@import 'relative/path/to/file.json?variable-name';
// Do something with $variable-name

Important:

  • the path to the JSON file is relative to importing file
  • the get parameter is the variable name to use it in Sass

Requirements

All you need is a clean version of Sass 3.3. Otherwise it's just pure Sass madness.

Development

You need

  • NodeJS
  • Ruby
  • Sass 3.3 via gem install sass --pre
  • grunt-cli via npm install -g grunt-cli

How to

  1. Fork this repository
  2. Run npm install
  3. grunt dev
  4. Make your changes + write tests
  5. Commit + Pull request

Credits

More Repositories

1

sass-boilerplate

A boilerplate for Sass projects using the 7-1 architecture pattern from Sass Guidelines.
SCSS
3,318
star
2

a11y-dialog

A very lightweight and flexible accessible modal dialog script.
JavaScript
2,364
star
3

SJSJ

Simplified JavaScript Jargon
HTML
2,268
star
4

sass-guidelines

Guidelines for writing sane, maintainable and scalable Sass.
HTML
909
star
5

awesome-sass

A curated list of awesome Sass.
749
star
6

selectors-explained

A CSS selector to plain English translator.
JavaScript
205
star
7

react-a11y-dialog

A React component for a11y-dialog
TypeScript
171
star
8

jekyll-boilerplate

A cleaned up version of the initial Jekyll setup for quick use.
HTML
145
star
9

CRUD.js

A CRUD JavaScript class.
JavaScript
140
star
10

sass-compatibility

Sass compatibility issues between different engines.
SCSS
129
star
11

Countdown.js

[UNMAINTAINED] A little JavaScript cutstomizable countdown
JavaScript
103
star
12

site

Sources for kittygiraudel.com
Liquid
101
star
13

focusable-selectors

A micro-lib exporting an array of CSS selectors for focusable HTML elements.
JavaScript
72
star
14

SassyCast

[UNMAINTAINED] Type conversion functions for Sass.
SCSS
72
star
15

SassySort

[UNMAINTAINED] Several ways to sort values in Sass using popular sorting algorithms.
SCSS
61
star
16

ImagePreloader

A lightweight JavaScript implementation of an image preloader relying on Promises.
JavaScript
61
star
17

SassyStrings

[UNMAINTAINED] A collection of Sass functions to manipulate strings.
SCSS
59
star
18

react-menu-button

A React component wrapper around inclusive-menu-button.
JavaScript
51
star
19

ama

Ask me anything!
43
star
20

SassyTester

[UNMAINTAINED] A minimalistic function tester in Sass.
SCSS
42
star
21

dotfiles

My configuration files
Shell
40
star
22

react-a11y-disclosure

A small React hook to build accessible disclosure widgets.
JavaScript
34
star
23

jekyll-styleguide

This project is an experiment about how we can create a living styleguide in Jekyll.
HTML
32
star
24

react-a11y-footnotes

A reusable React implementation of accessible footnotes.
JavaScript
32
star
25

eleventy-plugin-footnotes

An 11ty plugin to render accessible footnotes with Liquid
JavaScript
30
star
26

SassyMatrix

[UNMAINTAINED] All you ever wanted to deal with matrices in Sass.
SCSS
28
star
27

github-release-search

Tiny CLI to search for terms in GitHub releases
JavaScript
27
star
28

node-legofy

Node.js version of Legofy.
JavaScript
25
star
29

SassyGradients

[UNMAINTAINED] Sass helpers to manipulate gradients.
SCSS
24
star
30

inline-styler

A teeny tiny JavaScript library to easily manipulate the style attribute of an element.
JavaScript
22
star
31

SassyBitwise

[UNMAINTAINED] Bitwise operators in Sass.
SCSS
18
star
32

dhand

A React hook to guess the dominant hand of the user.
JavaScript
16
star
33

scrabble-helper

A CLI helper for Scrabble.
JavaScript
15
star
34

sass-semver

[UNMAINTAINED] A Sass implementation of node-semver.
SCSS
13
star
35

SassyIteratorsGenerators

[UNMAINTAINED] Iterators and generators implementation in Sass.
SCSS
13
star
36

map-dater

An interactive command line utility to estimate the age of an undated world map.
JavaScript
13
star
37

SassyLogger

[UNMAINTAINED] A logger for Sass.
SCSS
13
star
38

hangman.js

Redux powered hangman game.
JavaScript
11
star
39

circularray

A fast circular array implementation in JavaScript
JavaScript
11
star
40

advent-of-code

TypeScript
6
star
41

dependency-checker

A simple CLI script to check dependencies from a package.json
JavaScript
6
star
42

sanity-micro-client

JavaScript
5
star
43

css3-pratique

CSS 3, Pratique du Design Web
4
star
44

sudoku-solver

JavaScript
4
star
45

PHP-hangman-game

[UNMAINTAINED] A little OOPHP hangman game.
PHP
3
star
46

cypress-5570

JavaScript
2
star
47

teachable-backup

Node.js script to download all content from a Teachable school
JavaScript
1
star