Giter Club home page Giter Club logo

sass-color-guide's Introduction

sass-color-guide

Given a bunch of Sass colors, generates a visual representation.

This representation can then be used in style guides.

Ultimately, this tool will come in handy to auto generate part of a style guide based on colors defined in a _colors.scss file.

Looks like this with the right CSS:

Sample input

Colors

/* ==========================================================================
  Color variables
   ========================================================================== */

// Background and text colors (neutral)
$very-light-color:             #fff     !default;
$very-subtle-color:            #f5f5f5  !default;
$subtle-color:                 #DDD     !default;
$light-medium-color:           #D7C9D6  !default;
$light-color:                  lighten($light-medium-color, 10%)  !default;
$muted-color:                  #998197 !default;

$medium-color:                 #3e3744 !default; // rather dark
$dark-color:                   #3F2B3F !default;
$very-dark-color:              #000 !default;

// Divider colors

$divider-color:                $light-medium-color !default;

// Colors with meaning e.g. red for error

$success-color:                 #5C9F45;
$success-color-alt:             #8fae1f;
$error-color:                   #DB4614;
$help-color:                    #643ABF;
$highlight-color:               #F9F3AC;

Output HTML

Generate this:

<div id="component-colors">
	<div class="colors">
	
	    <!-- Loop for every color if the color is white add a box shadow -->
	
	    <div>
	        <div class="color-example" style="background: #FFF; box-shadow: 0 0 0 1px #DDD"></div>
	        <p>$very-light-color: #FFF</p>
	    </div>
	    
	    <!-- Else dump color value and add color name -->
	
	    <div>
	        <div class="color-example" style="background: #f5f6f7;"></div>
	        <p>$light-color: #f5f6f7</p>
	    </div>
	    
	</div>
</div>

SCSS for output HTML

/* Component: colors 
   ========================================================================== */

#component-colors {
  .colors {
    @include clearfix;
  }
  .colors > div {
    width: 150px;
    font-size: 11px;
    float: left;
    text-align: center;
  }
  .color-example {
    width: 50px;
    height: 50px;
    margin: 0 auto;
    line-height: 0;
    font-size: 0;
    display: block;
    padding: 0 0 8px;
  }
}

Some hints

Start off to read the file:

var text = fs.readFileSync('colors.scss', 'utf8');

Parts of the code

Regex

A regex should look for colors, it should for variables and their respective colors, so it should match 2 groups:

^          // start of line
(\$.*)     // capture variable e.g. $very-light-color
:          // followed by colon
\s         // followed by any amount of whitespace
(\S*)      // any non whitespace character
!?.*;$     // 0 or more ! characters

Unfinished regex, does most of the job but not perfectly yet:

^(\$.*):\s*(#\S*|([a-z]*\(\$\S*\,\s*[0-9]*)%\))\s*

These colors should be saved to an array: (@Ruben How to save regex output to array?)

['very-light-color', '#FFF'],
['light-color', '#DDD'],

If the color uses a color function in Sass it should be parsed but this is a bit extensive for v1.

This array should then be written out in HTML form:

Write this to DOM:

<!-- start of template-->
<div id="component-colors">
	<div class="colors">
<!-- end start -->

Then write this to DOM:

? How to read from an array ?

<!-- Loop for every color if the color is white add a box shadow -->

<div>
    <div class="color-example" style="background: #FFF; box-shadow: 0 0 0 1px #DDD"></div>
    <p>$very-light-color: #FFF</p>
</div>

<!-- Else dump color value and add color name -->

<div>
    <div class="color-example" style="background: #f5f6f7;"></div>
    <p>$light-color: #f5f6f7</p>
</div>

The loop should use ? Use a JS templating language for this part ?

Then write this:

	</div>
</div>

sass-color-guide's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

palimadra

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.