chroma-sass 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2805923b354ea2912ee2510ae926166569821f7
4
- data.tar.gz: 94bfffb798c22174513e3c47c562b4f566f02d98
3
+ metadata.gz: 08934be719ffef8dc01d76d3a5bb966b95686c88
4
+ data.tar.gz: a37acb0fd37e206f7c6a9c3cccfca648c4f871e9
5
5
  SHA512:
6
- metadata.gz: 7d842b907fd6adc6b5957f92f1d3d67da70d47d11667e4f19aae34960466789e441a84c2d609bda42aadd347f090f00b63d3256039bfd8c6fa11d24fe51d1d09
7
- data.tar.gz: 0c973e1dbeaff8632a37f7aabd5756af2f272a44e7fb68105f1371755428c958485579a3496877f5a0e464ac6bb776f7af0285bd986842015b7ba7fd53651cc9
6
+ metadata.gz: 69979ae8a1894ea04556d159d24e10f96dd9df4886e915722d0b931710c0bcec8121dc21d446199413c2ac796ed6aaa399c0257f3374c9d30f5e70619cd5f314
7
+ data.tar.gz: d093b5ca09e38354aef42f6e535ddb215a652127d9f062ed0a1be0e9a59222cee7180221973d17353bf4e2a2f17f92dd0041a59d73ae4870c18a5ed3b5b5278f
data/README.md CHANGED
@@ -10,15 +10,19 @@ Full documentation is available at [http://johnalbin.github.io/chroma/](http://j
10
10
  @import "chroma";
11
11
 
12
12
  // Define the default color scheme.
13
- $chroma: define-default-color-scheme('Descriptive color names for use in "functional" color names below.');
13
+ $chroma: define-default-color-scheme('Branding color names for use by "functional" color names below.');
14
14
 
15
15
  // Add colors to the default color scheme.
16
16
  $chroma: add-colors((
17
17
  white: #fff,
18
- grey-medium: #706e6c,
19
18
  black: #000,
20
19
  blue: #0e71b8,
21
20
  red: #c00,
21
+
22
+ // Define a primary highlight color that has the value of our "blue" color.
23
+ // Note: if blue was specified without quotes, Chroma would interpret that as
24
+ // the color keyword blue and not a reference to the "blue" color name.
25
+ primary: 'blue',
22
26
  ));
23
27
 
24
28
  // Create a "functional" color scheme that inherits from the default color scheme.
@@ -26,19 +30,20 @@ $chroma: define-color-scheme('functional', 'Colors used by functional parts of t
26
30
 
27
31
  // Add colors to the functional color scheme.
28
32
  $chroma: add-colors('functional', (
29
- // Define a primary highlight color.
30
- primary: 'blue',
31
-
32
33
  // Have the "text" color use the hex value given to the "black" color. Even
33
34
  // though the "functional" color scheme doesn't define "black", it inherits
34
35
  // from the "default" color scheme where "black" is defined.
35
36
  text: 'black',
36
37
 
37
- // Colors can inherit from colors named earlier in the call to add-colors().
38
- heading: 'text',
38
+ // You can use quoted or unquoted strings to reference other color names.
39
+ // Note: color keywords are not considered strings unless they are quoted.
40
+ heading: text,
39
41
 
40
42
  // Have the link color use the primary color.
41
- link: 'primary',
43
+ link: primary,
44
+ link-focus: (link lighten 20%), // Set the link-focus color to the "link"
45
+ // color passed through the color
46
+ // function: lighten([color], 20%)
42
47
  ));
43
48
 
44
49
  // Create an "alternate" color scheme that inherits from the "functional" color scheme.
@@ -58,13 +63,26 @@ $chroma-active-scheme: 'functional';
58
63
  // Outputs #000.
59
64
  color: color(heading);
60
65
  }
66
+
61
67
  a {
62
68
  // Outputs #0e71b8.
63
69
  color: color(link);
64
70
 
71
+ &:focus,
72
+ &:hover {
73
+ // Outputs #3ca5f0, which is lighten(#0e71b8, 20%).
74
+ color: color(link-focus);
75
+ }
76
+
65
77
  .alternate-color-section & {
66
78
  // Outputs #c00.
67
79
  color: color(alternate, link);
80
+
81
+ &:focus,
82
+ &:hover {
83
+ // Outputs #ff3333, which is lighten(#c00, 20%).
84
+ color: color(alternate, link-focus);
85
+ }
68
86
  }
69
87
  }
70
88
  }
@@ -77,10 +95,7 @@ Chroma can be installed either as a Ruby Gem, as a Bower component, or as a NPM
77
95
  ## REQUIREMENTS
78
96
 
79
97
  * Sass 3.4.0 or later
80
-
81
- Note: libsass 3.2.5 or earlier does not work with chroma-sass due to a bug in
82
- libsass. ☹ libsass 3.3.0 should fix the bug, but it has not been tested. See
83
- https://github.com/JohnAlbin/chroma/issues/10
98
+ * Or LibSass 3.2.5 or later.
84
99
 
85
100
  ## LICENSE
86
101
 
data/chroma-sass.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.homepage = 'http://github.com/JohnAlbin/chroma'
10
10
  spec.rubyforge_project =
11
11
 
12
- spec.version = '1.0.1'
13
- spec.date = '2015-09-09'
12
+ spec.version = '1.1.0'
13
+ spec.date = '2015-09-23'
14
14
  spec.licenses = ['GPL-2']
15
15
 
16
16
  spec.authors = ['John Albin Wilkins']
@@ -40,23 +40,35 @@ $chroma: _chroma-init();
40
40
  //
41
41
  // Style guide: functions.is-dangerous-color-keyword
42
42
  @function is-dangerous-color-keyword($name) {
43
+ // First, double-check if this is a keyword in a string.
44
+ @if _is-keyword-string($name) {
45
+ @return false;
46
+ }
47
+
43
48
  @if type-of($name) == 'color' {
44
- // Convert the color to a string.
45
- $name: inspect($name);
49
+ $lookup: '';
50
+ @if _is-old-libsass() {
51
+ // Forcibly convert a color keyword into a string with a "salt".
52
+ $lookup: "keyword:#{$name}";
53
+ }
54
+ @else {
55
+ // Convert the color to a string.
56
+ $lookup: inspect($name);
57
+ }
46
58
  // Check if Sass will convert the color into a hex value that we can't
47
59
  // convert back to a keyword.
48
- @if map-has-key($_chroma-dangerous-keywords, $name) {
60
+ @if map-has-key($_chroma-dangerous-keywords, $lookup) {
49
61
  @if $chroma-die-on-dangerous-keyword {
50
- @error "Sass will convert #{$name} into a hexidecimal value when it uses the \"compressed\" output style and Chroma will not be able to determine if the original name was #{map-get($_chroma-dangerous-keywords, $name)}. To prevent this error, quote the keyword like this: '#{$name}'.";
62
+ @error "Sass will convert #{$name} into a hexidecimal value when it uses the \"compressed\" output style and Chroma will not be able to determine if the original name was #{map-get($_chroma-dangerous-keywords, $lookup)}. To prevent this error, quote the keyword like this: '#{$name}'.";
51
63
  }
52
64
  @else {
53
- @return map-get($_chroma-dangerous-keywords, $name);
65
+ @return map-get($_chroma-dangerous-keywords, $lookup);
54
66
  }
55
67
  }
56
68
  // Check if Sass _has_ converted the color into a hex value that we can't
57
69
  // convert back to a keyword.
58
- @else if map-has-key($_chroma-dangerous-converted-keywords, $name) {
59
- @error "Sass has converted a #{$_chroma-spelling} keyword into the hexidecimal value, #{$name}, and Chroma was not be able to determine if the original name was #{map-get($_chroma-dangerous-converted-keywords, $name)}. To prevent this error, use quotes around the keyword.";
70
+ @else if map-has-key($_chroma-dangerous-converted-keywords, $lookup) {
71
+ @error "Sass has converted a #{$_chroma-spelling} keyword into the hexidecimal value, #{$name}, and Chroma was not be able to determine if the original name was #{map-get($_chroma-dangerous-converted-keywords, $lookup)}. To prevent this error, use quotes around the keyword.";
60
72
  }
61
73
  }
62
74
  @return false;
@@ -71,6 +83,11 @@ $chroma: _chroma-init();
71
83
  //
72
84
  // Style guide: functions.is-color-keyword
73
85
  @function is-color-keyword($name) {
86
+ // First, double-check if this is a keyword in a string.
87
+ @if _is-keyword-string($name) {
88
+ @return false;
89
+ }
90
+
74
91
  // If a real Sass color is given, it is in danger of being converted to a
75
92
  // hexadecimal value before we can read the name. And some hex values map to
76
93
  // more than one keyword (e.g. gray and grey), so the original name would be
@@ -81,11 +98,19 @@ $chroma: _chroma-init();
81
98
  // $name so we can convert it to a string.
82
99
  $is-dangerous: is-dangerous-color-keyword($name);
83
100
 
84
- // Convert the color to a string.
85
101
  @if type-of($name) == 'color' {
86
- $name: inspect($name);
102
+ $lookup: '';
103
+
104
+ @if _is-old-libsass() {
105
+ // Forcibly convert a color keyword into a string with a "salt".
106
+ $lookup: "keyword:#{$name}";
107
+ }
108
+ @else {
109
+ // Convert the color to a string.
110
+ $lookup: inspect($name);
111
+ }
87
112
 
88
- @return if(map-has-key($_chroma-css4-color-keywords, $name), map-get($_chroma-css4-color-keywords, $name), false);
113
+ @return if(map-has-key($_chroma-css4-color-keywords, $lookup), map-get($_chroma-css4-color-keywords, $lookup), false);
89
114
  }
90
115
 
91
116
  @return false;
@@ -153,13 +178,34 @@ $chroma: _chroma-init();
153
178
  // and its parent schemes. But one or more of the parent colors may be
154
179
  // defined (overridden) in $scheme too, so we need to check the full
155
180
  // reference chain.
181
+ $chain: ();
156
182
  $ref: map-get($color, 'reference');
183
+ @if $ref and map-get($color, 'function') {
184
+ $chain: append($chain, $color);
185
+ }
157
186
  @while $ref {
158
187
  $actual-scheme: chroma-has-color($ref, $scheme);
159
188
  $color: map-get(map-get($chroma, 'names'), "#{$actual-scheme}::#{$ref}");
160
189
  $ref: map-get($color, 'reference');
190
+ // Save any color that has a function unless it is the final color in the
191
+ // reference chain.
192
+ @if $ref and map-get($color, 'function') {
193
+ $chain: append($chain, $color);
194
+ }
161
195
  }
162
- @return map-get($color, 'value');
196
+ // Find the value for the last non-reference in the chain.
197
+ $value: map-get($color, 'value');
198
+ // If the reference chain contains functions, we need to recalculate all
199
+ // the values back up the chain.
200
+ @if length($chain) > 0 {
201
+ @for $i from length($chain) through 1 {
202
+ $function: map-get(nth($chain, $i), 'function');
203
+ $parameters: map-get(nth($chain, $i), 'parameters');
204
+ $parameters: set-nth($parameters, 1, $value);
205
+ $value: call($function, $parameters...);
206
+ }
207
+ }
208
+ @return $value;
163
209
  }
164
210
  }
165
211
 
@@ -271,19 +317,22 @@ $chroma: _chroma-init();
271
317
  //
272
318
  // Usage:
273
319
  // ```scss
274
- // $my-colors: add-colors('admiral', (
275
- // nav: 'link',
276
- // nav-visited: color(link-visited),
277
- // nav-focus: color(link-focus),
320
+ // $chroma: add-colors('admiral', (
321
+ // link: #0000cc,
322
+ // nav: link, // Sets this color to the same value as the "link" color.
323
+ // nav-visited: (nav darken 20%), // Takes the "nav" color and passes it
324
+ // // through darken([color], 20%)
325
+ // nav-focus: (nav lighten 10%),
278
326
  // ));
279
327
  // ```
280
328
  //
281
329
  // If you wish to add colors to the active scheme, you can just use:
282
330
  // ```scss
283
- // $my-colors: add-colors((
284
- // nav: 'link',
285
- // nav-visited: color(link-visited),
286
- // nav-focus: color(link-focus),
331
+ // $chroma: add-colors((
332
+ // link: #0000cc,
333
+ // nav: link,
334
+ // nav-visited: (link darken 20%),
335
+ // nav-focus: (link lighten 10%),
287
336
  // ));
288
337
  // ```
289
338
  //
@@ -307,28 +356,56 @@ $chroma: _chroma-init();
307
356
  // Cast the color name to a string to ensure color keywords do not cause
308
357
  // problems as map keys.
309
358
  $color-name: chroma-to-string($color-name);
359
+ $color-function: false;
360
+ $color-parameters: ();
361
+ // If the "value" is a list, its a value plus a function.
362
+ @if type-of($color-value) == 'list' {
363
+ $color-function: nth($color-value, 2);
364
+ @if not function_exists($color-function) {
365
+ @error 'The function "#{$color-function}" was not found when adding the #{$_chroma-spelling} "#{$color-name}".';
366
+ }
367
+ // Include the color value in the list of function parameters.
368
+ @for $i from 1 through length($color-value) {
369
+ @if $i != 2 {
370
+ $color-parameters: append($color-parameters, nth($color-value, $i));
371
+ }
372
+ }
373
+ $color-value: nth($color-value, 1);
374
+ }
310
375
  // If the value given is a color, just add it.
311
- @if type_of($color-value) == 'color' {
376
+ @if type-of($color-value) == 'color' and not (_is-old-libsass() and _is-keyword-string($color-value)) {
377
+ @if $color-function {
378
+ $color-value: call($color-function, $color-parameters...);
379
+ }
312
380
  $chroma: _chroma-add-name($scheme, $color-name,
313
381
  $value : $color-value,
314
382
  $reference : false,
315
- $referenced_by : ()
383
+ $referenced_by : (),
384
+ $function : $color-function,
385
+ $parameters : $color-parameters
316
386
  ) !global;
317
387
  }
318
388
  // If the value given is a reference to another color...
319
- @else if type_of($color-value) == 'string' {
389
+ @else if type-of($color-value) == 'string' or (_is-old-libsass() and _is-keyword-string($color-value)) {
320
390
  $ref: $color-value;
321
391
  // Find the referenced color.
322
392
  $scheme-of-reference: chroma-has-color($ref, $scheme);
323
393
  @if not $scheme-of-reference {
324
- @error 'The #{$_chroma-spelling} "#{$ref}" was not found.';
394
+ @error 'The #{$_chroma-spelling} "#{$ref}" was not found when adding the #{$_chroma-spelling} "#{$color-name}".';
325
395
  }
326
396
  $referenced-color: map-get(map-get($chroma, 'names'), "#{$scheme-of-reference}::#{$ref}");
327
397
  // Add the new color.
398
+ $new-value: map-get($referenced-color, 'value');
399
+ @if $color-function {
400
+ $color-parameters: set-nth($color-parameters, 1, $new-value);
401
+ $new-value: call($color-function, $color-parameters...);
402
+ }
328
403
  $chroma: _chroma-add-name($scheme, $color-name,
329
- $value : map-get($referenced-color, 'value'),
404
+ $value : $new-value,
330
405
  $reference : $ref,
331
- $referenced_by : ()
406
+ $referenced_by : (),
407
+ $function : $color-function,
408
+ $parameters : $color-parameters
332
409
  ) !global;
333
410
  // Document the new color in all the referenced_by lists.
334
411
  @while $ref {
@@ -338,7 +415,9 @@ $chroma: _chroma-init();
338
415
  $referenced_by : append(
339
416
  map-get($referenced-color, 'referenced_by'),
340
417
  $color-name
341
- )
418
+ ),
419
+ $function : map-get($referenced-color, 'function'),
420
+ $parameters : map-get($referenced-color, 'parameters')
342
421
  ) !global;
343
422
  $ref: map-get($referenced-color, 'reference');
344
423
  @if $ref {
@@ -52,13 +52,15 @@
52
52
  // variable.
53
53
  //
54
54
  // Style guide: internals._chroma-add-name
55
- @function _chroma-add-name($scheme, $name, $value: false, $reference: false, $referenced_by: ()) {
55
+ @function _chroma-add-name($scheme, $name, $value: false, $reference: false, $referenced_by: (), $function: false, $parameters: ()) {
56
56
  $names: map-merge(
57
57
  map-get($chroma, 'names'),
58
58
  ("#{$scheme}::#{$name}": (
59
59
  value : $value,
60
60
  reference : $reference,
61
61
  referenced_by : $referenced_by,
62
+ function : $function,
63
+ parameters : $parameters,
62
64
  ))
63
65
  );
64
66
 
@@ -91,3 +93,39 @@
91
93
  @return $chroma;
92
94
  }
93
95
  }
96
+
97
+ // is-old-libsass()
98
+ //
99
+ // libsass before 3.3.0 is funky, making it very hard for Chroma to do its job.
100
+ //
101
+ // - `inspect([color])` returns the original value instead of returning the
102
+ // string equivalent, so you can't cast a color to a string.
103
+ // - `type-of('[color keyword]')` thinks that these strings are colors.
104
+ // - `map-has-key()` works properly, thankfully. So:
105
+ // - `map-has-key((white: ''), white)` correctly returns `true`
106
+ // - `map-has-key(('white': ''), 'white')` correctly returns `true`
107
+ // - `map-has-key((white: ''), 'white')` correctly returns `false`
108
+ // - `map-has-key(('white': ''), white)` correctly returns `false`
109
+ // This means we can cobble together a replacement for `type-of()`. And a
110
+ // partial replacement for `inspect()` that works for everything except
111
+ // dangerous color keywords.
112
+ //
113
+ // @TODO: Remove when LibSass 3.2.5 support is dropped.
114
+ //
115
+ // Style guide: internals._is-old-libsass
116
+ @function _is-old-libsass() {
117
+ @return if(type-of('white') == 'color', true, false);
118
+ }
119
+
120
+ // _is-keyword-string($name)
121
+ //
122
+ // Normally, `type-of()` can be used to tell if a given value is a string. But
123
+ // LibSass versions before 3.3.0 think that color keywords in strings are still
124
+ // colors and not strings. This function works, regardless of LibSass bugs.
125
+ //
126
+ // @TODO: Remove when LibSass 3.2.5 support is dropped.
127
+ //
128
+ // Style guide: internals._is-keyword-string
129
+ @function _is-keyword-string($name) {
130
+ @return if(map-has-key($_chroma-css4-color-keywords-in-strings, $name), true, false);
131
+ }
@@ -419,3 +419,34 @@ $_chroma-css4-color-keywords: (
419
419
  'yellowgreen': 'yellowgreen',
420
420
  '#9acd32': 'yellowgreen',
421
421
  );
422
+
423
+ // libsass before 3.3.0 can't turn color keywords into strings of the same name,
424
+ // so we have to compare map keys using keywords plus a "salt" string.
425
+ //
426
+ // @TODO: Remove when LibSass 3.2.5 support is dropped.
427
+
428
+ $_chroma-css4-color-keywords-in-strings: ();
429
+ @if type-of('white') == 'color' {
430
+ // Convert the dangerous color keyword list.
431
+ $_new-list: ();
432
+ @each $name, $string in $_chroma-dangerous-keywords {
433
+ $_new-list: map-merge($_new-list, ("keyword:#{$name}": $string));
434
+ }
435
+ $_chroma-dangerous-keywords: $_new-list !global;
436
+
437
+ // Convert the dangerous converted color keyword list.
438
+ $_new-list: ();
439
+ @each $name, $string in $_chroma-dangerous-converted-keywords {
440
+ $_new-list: map-merge($_new-list, ("keyword:#{$name}": $string));
441
+ }
442
+ $_chroma-dangerous-converted-keywords: $_new-list !global;
443
+
444
+ // Convert the css4 color keyword list, but keep a copy around to check for
445
+ // color keywords in strings.
446
+ $_chroma-css4-color-keywords-in-strings: $_chroma-css4-color-keywords !global;
447
+ $_new-list: ();
448
+ @each $name, $string in $_chroma-css4-color-keywords {
449
+ $_new-list: map-merge($_new-list, ("keyword:#{$name}": $string));
450
+ }
451
+ $_chroma-css4-color-keywords: $_new-list !global;
452
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chroma-sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Albin Wilkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-09 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubyforge_project: 1.0.1
64
+ rubyforge_project: 1.1.0
65
65
  rubygems_version: 2.4.8
66
66
  signing_key:
67
67
  specification_version: 4