sass-extras 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d3d351b6112cc349147a578edaeae7e0d333051
4
- data.tar.gz: 00396c11db0ad90bbac608934d7fd673253c5548
3
+ metadata.gz: 609d26e3692dd22169ab7d3a5d5d3220be4daedf
4
+ data.tar.gz: 007c38b893bd6ed43f70cd913df2521ab79cbca1
5
5
  SHA512:
6
- metadata.gz: 5ed28ac04dcfc39cf2e4c9b26eec33abae2ba48145b1de6383a87db12dcae72c2aa43439c5eb58494babd5745463e1b6099387ab40141ac9f212d701f2086565
7
- data.tar.gz: 12d2bac01f5ad313f2c8c69389ef1d3b8747d8515ee374a14b7267d0a30ad676880526ba59815e2984f252501f71c26b66497025100a323469d884f8abcfaa1a
6
+ metadata.gz: f1cd4307bcad889513aa8aa9dda189a5623543297cf5c417d926ee96fa2df8f42e7afd33d5b585995cb58ffa3e832e7837caae394624191ad5d63d7e308b6f65
7
+ data.tar.gz: 3c3cb8cc6e889056d5fe5d5f9edb90931f78988c1414fbc6c23f9a0e23c658260bcf2093757cf0eb778358e013e1e6b9c0cb467febd6dac4254442821379be9b
data/lib/sass/extras.rb CHANGED
@@ -3,6 +3,7 @@ require "sass/extras/version"
3
3
  require "sass/extras/contrast"
4
4
  require "sass/extras/inline_color_image"
5
5
  require "sass/extras/svg_data_urls"
6
+ require "sass/extras/variables"
6
7
  require "sass/extras/yuv"
7
8
 
8
9
  Sass::Script::Color.class_eval do
@@ -14,5 +15,6 @@ Sass::Script::Functions.module_eval do
14
15
  include Sass::Extras::Contrast::Functions
15
16
  include Sass::Extras::InlineColorImage
16
17
  include Sass::Extras::SvgDataUrls
18
+ include Sass::Extras::Variables
17
19
  include Sass::Extras::YUV::Functions
18
20
  end
@@ -28,7 +28,8 @@ module Sass
28
28
  def luminance
29
29
  # http://www.w3.org/TR/WCAG20/#relativeluminancedef
30
30
  norm_rgb = rgb.map { |value| value.to_f / 255 }
31
- Utils.sum(Utils.mul(norm_rgb.map { |v| v <= 0.03928 ? v/12.92 : ((v+0.055)/1.055) ** 2.4 }, LUMINANCE_COEFS))
31
+ relative_luminance = norm_rgb.map { |v| v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055)**2.4 }
32
+ Utils.sum(Utils.mul(relative_luminance, LUMINANCE_COEFS))
32
33
  end
33
34
  end
34
35
 
@@ -47,9 +48,9 @@ module Sass
47
48
  direction = color.brightness > 127 ? darken_method : lighten_method
48
49
  new_color = seed_color
49
50
  percentage = 0.0
50
- until conform(new_color, color, wcag20_level.value) or percentage > 100.0 do
51
+ until conform(new_color, color, wcag20_level.value) || percentage > 100.0
51
52
  amount = Sass::Script::Number.new percentage, ['%']
52
- new_color = self.send direction, seed_color, amount
53
+ new_color = send(direction, seed_color, amount)
53
54
  percentage += 0.1
54
55
  end
55
56
  new_color
@@ -123,7 +124,7 @@ module Sass
123
124
  end
124
125
 
125
126
  def self.sq(array)
126
- array.map { |e| e ** 2 }
127
+ array.map { |e| e**2 }
127
128
  end
128
129
  end
129
130
  end
@@ -0,0 +1,51 @@
1
+ module Sass
2
+ module Extras
3
+ module Variables
4
+ def self.included(base)
5
+ base.declare :variable_get, [:name]
6
+ base.declare :global_variable_get, [:name]
7
+ end
8
+
9
+ # Get the value of a variable with the given name, if it exists in the
10
+ # current scope or in the global scope.
11
+ #
12
+ # @example
13
+ # $a-false-value: false;
14
+ # variable-get(a-false-value) => false
15
+ #
16
+ # variable-get(nonexistent) => null
17
+ #
18
+ # @overload variable_get($name)
19
+ # @param $name [Sass::Script::Value::String] The name of the variable to
20
+ # check. The name should not include the `$`.
21
+ # @return [Sass::Script::Value::Bool] Whether the variable is defined in
22
+ # the current scope.
23
+ def variable_get(name)
24
+ assert_type name, :String, :name
25
+ environment.caller.var(name.value)
26
+ end
27
+
28
+ # Check whether a variable with the given name exists in the global
29
+ # scope (at the top level of the file).
30
+ #
31
+ # @example
32
+ # $a-false-value: false;
33
+ # global-variable-get(a-false-value) => false
34
+ #
35
+ # .foo {
36
+ # $some-var: false;
37
+ # global-variable-get(some-var) => null
38
+ # }
39
+ #
40
+ # @overload global_variable_get($name)
41
+ # @param $name [Sass::Script::Value::String] The name of the variable to
42
+ # check. The name should not include the `$`.
43
+ # @return [Sass::Script::Value::Bool] Whether the variable is defined in
44
+ # the global scope.
45
+ def global_variable_get(name)
46
+ assert_type name, :String, :name
47
+ environment.global_env.var(name.value)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  module Sass
2
2
  module Extras
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -13,8 +13,8 @@ module Sass
13
13
  r, g, b = rgb.map { |k| k / 255.0 }
14
14
  y = r * WR + g * WG + b * WB
15
15
  y = 1.0 if y == W_SUM
16
- u = U_MAX*(b - y)/(1 - WB)
17
- v = V_MAX*(r - y)/(1 - WR)
16
+ u = U_MAX * (b - y) / (1 - WB)
17
+ v = V_MAX * (r - y) / (1 - WR)
18
18
  [y, Utils.restrict(u, -U_MAX..U_MAX), Utils.restrict(v, -V_MAX..V_MAX)]
19
19
  end
20
20
 
@@ -50,17 +50,17 @@ module Sass
50
50
 
51
51
  yv = y.value
52
52
  if y.numerator_units == ["%"] && y.denominator_units.empty?
53
- raise ArgumentError.new("Brightness (Y') value #{y} must be between 0% and 100% inclusive") unless (0..100).include?(y.value)
54
- yv = yv / 100.0
53
+ fail ArgumentError, "Brightness (Y') value #{y} must be between 0% and 100% inclusive" unless (0..100).include?(y.value)
54
+ yv /= 100.0
55
55
  else
56
- raise ArgumentError.new("Brightness (Y') value #{y} must be between 0 and 1.0 inclusive") unless (0..1.0).include?(y.value)
56
+ fail ArgumentError, "Brightness (Y') value #{y} must be between 0 and 1.0 inclusive" unless (0..1.0).include?(y.value)
57
57
  end
58
- raise ArgumentError.new("Chrominance (U) value #{u} must be between -#{U_MAX} and #{U_MAX} inclusive") unless (-U_MAX..U_MAX).include?(u.value)
59
- raise ArgumentError.new("Chrominance (V) value #{v} must be between -#{V_MAX} and #{V_MAX} inclusive") unless (-V_MAX..V_MAX).include?(v.value)
58
+ fail ArgumentError, "Chrominance (U) value #{u} must be between -#{U_MAX} and #{U_MAX} inclusive" unless (-U_MAX..U_MAX).include?(u.value)
59
+ fail ArgumentError, "Chrominance (V) value #{v} must be between -#{V_MAX} and #{V_MAX} inclusive" unless (-V_MAX..V_MAX).include?(v.value)
60
60
 
61
- r = yv + v.value * (1 - WR)/(V_MAX)
62
- g = yv - u.value * (WB * (1 - WB))/(V_MAX * WG) - v.value * (WR * (1 - WR))/(V_MAX * WG)
63
- b = yv + u.value * (1 - WB)/U_MAX
61
+ r = yv + v.value * (1 - WR) / (V_MAX)
62
+ g = yv - u.value * (WB * (1 - WB)) / (V_MAX * WG) - v.value * (WR * (1 - WR)) / (V_MAX * WG)
63
+ b = yv + u.value * (1 - WB) / U_MAX
64
64
 
65
65
  rgb = [r, g, b].map { |c| [0, [255, c * 255].min].max }
66
66
  Sass::Script::Color.new(rgb)
@@ -68,13 +68,13 @@ module Sass
68
68
 
69
69
  def yuva(y, u, v, a)
70
70
  assert_type a, :Number, :a
71
- yuv(y, u, v).with(:alpha => a.value)
71
+ yuv(y, u, v).with(alpha: a.value)
72
72
  end
73
73
 
74
74
  # @param color [Color]
75
75
  # @param amount [Number] between 0 and 1.0, or 0% and 100%
76
76
  def set_brightness(color, amount)
77
- adjust_brightness(color, amount) { |c, y| c }
77
+ adjust_brightness(color, amount) { |c, _| c }
78
78
  end
79
79
 
80
80
  # @param color [Color]
@@ -107,10 +107,10 @@ module Sass
107
107
  y, u, v, a = color.yuva.map { |x| Sass::Script::Number.new x }
108
108
  c = amount.value
109
109
  if amount.numerator_units == ["%"] && amount.denominator_units.empty?
110
- raise ArgumentError.new("Amount value #{amount} must be between 0% and 100% inclusive") unless (0..100).include?(c)
111
- c = c / 100.0
110
+ fail ArgumentError, "Amount value #{amount} must be between 0% and 100% inclusive" unless (0..100).include?(c)
111
+ c /= 100.0
112
112
  else
113
- raise ArgumentError.new("Amount value #{amount} must be between 0 and 1.0 inclusive") unless (0..1.0).include?(c)
113
+ fail ArgumentError, "Amount value #{amount} must be between 0 and 1.0 inclusive" unless (0..1.0).include?(c)
114
114
  end
115
115
  y = Sass::Script::Number.new yield(c, y.value)
116
116
  yuva(y, u, v, a)
@@ -0,0 +1,48 @@
1
+ require_relative "spec_helper"
2
+
3
+ describe Sass::Extras::Variables do
4
+ describe "variable-get" do
5
+ it "gets the value of a local variable" do
6
+ unindent(<<-CSS).must_equal render(unindent(<<-SCSS))
7
+ a {
8
+ b: 42; }
9
+ CSS
10
+ a {
11
+ $my-local-var: 42;
12
+ b: variable-get(my-local-var); }
13
+ SCSS
14
+ end
15
+
16
+ it "also gets variables from the global scope" do
17
+ unindent(<<-CSS).must_equal render(unindent(<<-SCSS))
18
+ a {
19
+ b: 42; }
20
+ CSS
21
+ $my-global-var: 42;
22
+ a {
23
+ b: variable-get(my-global-var); }
24
+ SCSS
25
+ end
26
+ end
27
+
28
+ describe "global-variable-get" do
29
+ it "get the value of a global variable" do
30
+ unindent(<<-CSS).must_equal render(unindent(<<-SCSS))
31
+ a {
32
+ b: 42; }
33
+ CSS
34
+ $my-global-var: 42;
35
+ a {
36
+ b: global-variable-get(my-global-var); }
37
+ SCSS
38
+ end
39
+ end
40
+
41
+ def unindent(s)
42
+ s.gsub(/^#{s.scan(/^[ \t]+(?=\S)/).min}/, "")
43
+ end
44
+
45
+ def render(scss)
46
+ Sass::Engine.new(scss, syntax: :scss).render
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Haagen Michaelsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -112,11 +112,13 @@ files:
112
112
  - lib/sass/extras/contrast.rb
113
113
  - lib/sass/extras/inline_color_image.rb
114
114
  - lib/sass/extras/svg_data_urls.rb
115
+ - lib/sass/extras/variables.rb
115
116
  - lib/sass/extras/version.rb
116
117
  - lib/sass/extras/yuv.rb
117
118
  - sass-extras.gemspec
118
119
  - specs/contrast_spec.rb
119
120
  - specs/spec_helper.rb
121
+ - specs/variables_spec.rb
120
122
  - specs/yuv_spec.rb
121
123
  homepage: https://github.com/tobiashm/sass-extras
122
124
  licenses:
@@ -138,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  version: '0'
139
141
  requirements: []
140
142
  rubyforge_project:
141
- rubygems_version: 2.4.5
143
+ rubygems_version: 2.4.8
142
144
  signing_key:
143
145
  specification_version: 4
144
146
  summary: A collection of SASS extensions.