|
1 | | -var palettes = require('./palette'); |
| 1 | +var palettes = require('./palettes'); |
2 | 2 | var typography = require('./typography'); |
3 | | -var sass = require('node-sass'); |
4 | | -var sassUtils = require('node-sass-utils')(sass); |
5 | | - |
6 | | -function hexToRgb(hex) { |
7 | | - if (typeof hex !== 'string') { |
8 | | - throw new TypeError('Expected a string'); |
9 | | - } |
10 | | - hex = hex.replace(/^#/, ''); |
11 | | - if (hex.length === 3) { |
12 | | - hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; |
13 | | - } |
14 | | - var num = parseInt(hex, 16); |
15 | | - return { r: num >> 16, g: num >> 8 & 255, b: num & 255}; |
16 | | -} |
| 3 | +var getPaletteFromSass = require('./../build-utilities/compiled/getPaletteFromSass'); |
| 4 | +var typographyUtils = require('./../build-utilities/compiled/typography'); |
17 | 5 |
|
18 | 6 | module.exports = { |
19 | | - 'get-palette($name)': function(name) { |
20 | | - // Get the variable name from sass function (when it is invoked) |
21 | | - // For that we need to take its value before |
22 | | - var paletteName = name.getValue(); |
23 | | - // Take the palette with the given name from object palettes |
24 | | - var palette = palettes[paletteName]; |
25 | | - // Get all key from the palette |
26 | | - var keys = Object.keys(palette); |
27 | | - // Create a sass Map object |
28 | | - var map = sass.types.Map(keys.length); |
29 | | - // Get the Sass Color class |
30 | | - var ColorClass = sass.types.Color; |
31 | | - // Iterate every key |
32 | | - var convertedColor; |
33 | | - keys.forEach(function(key, i) { |
34 | | - // Convert the value of the given key on the object palette into rgb format |
35 | | - convertedColor = hexToRgb(palette[key]); |
36 | | - // Create a new Sass color instance |
37 | | - var color = new ColorClass(convertedColor.r, convertedColor.g, convertedColor.b); |
38 | | - // Set the key value in the sass Map |
39 | | - map.setKey(i, sass.types.String(key)); |
40 | | - map.setValue(i, color); |
41 | | - }); |
42 | | - return map; |
43 | | - }, |
44 | | - 'get-typography': function(name) { |
45 | | - return sassUtils.castToSass(typography); |
46 | | - }, |
47 | | - 'get-type($name)': function(name) { |
48 | | - return sassUtils.castToSass(typography[name.getValue()]); |
49 | | - } |
| 7 | + 'get-palette($name)': getPaletteFromSass(palettes), |
| 8 | + 'get-typography': typographyUtils.getTypography(typography), |
| 9 | + 'get-type($name)': typographyUtils.getType(typography) |
50 | 10 | }; |
| 11 | + |
0 commit comments