sass-embedded 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/sass/compile_error.rb +10 -5
- data/lib/sass/compile_result.rb +10 -1
- data/lib/sass/embedded/host.rb +2 -0
- data/lib/sass/embedded/version.rb +1 -1
- data/lib/sass/embedded.rb +54 -7
- data/lib/sass/logger/source_location.rb +3 -0
- data/lib/sass/logger/source_span.rb +10 -1
- data/lib/sass/logger.rb +2 -0
- data/lib/sass/value/argument_list.rb +6 -0
- data/lib/sass/value/boolean.rb +14 -6
- data/lib/sass/value/color.rb +67 -34
- data/lib/sass/value/function.rb +18 -4
- data/lib/sass/value/list.rb +33 -16
- data/lib/sass/value/map.rb +27 -15
- data/lib/sass/value/null.rb +13 -6
- data/lib/sass/value/number.rb +95 -38
- data/lib/sass/value/string.rb +22 -11
- data/lib/sass/value.rb +55 -27
- data/lib/sass.rb +10 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e66ada7e45e9d2645c9c11569f907001a4d8f9711df90f9cebe726e0a40d9539
|
4
|
+
data.tar.gz: aa2139021df463e31a2fa6f02d9515dd6b9553b57d73d38e831ad67ecb688275
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc77ad8ef5cbd139360443308899212ce95fd4b3be3be31fbca1f331f7cc73e6bd5ad0f6f2bc853d486ca0a90bc1e3fdf043adbcb534060f17c2209a7eac9499
|
7
|
+
data.tar.gz: 61918d88ebfa21159851b0294d1366b2ff403c3168592dc70554c68810a777552ecb773849e790fd9f8bd1be1f2e4839732700b02a5faf7b4db448776c34b120
|
data/README.md
CHANGED
@@ -15,11 +15,24 @@ gem install sass-embedded
|
|
15
15
|
|
16
16
|
## Usage
|
17
17
|
|
18
|
+
The Ruby API provides two entrypoints for compiling Sass to CSS.
|
19
|
+
|
20
|
+
- `Sass.compile` takes a path to a Sass file and return the result of compiling that file to CSS.
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
require 'sass'
|
24
|
+
|
25
|
+
result = Sass.compile('style.scss')
|
26
|
+
puts result.css
|
27
|
+
```
|
28
|
+
|
29
|
+
- `Sass.compile_string` takes a string that represents the contents of a Sass file and return the result of compiling that file to CSS.
|
30
|
+
|
18
31
|
``` ruby
|
19
32
|
require 'sass'
|
20
33
|
|
21
|
-
Sass.
|
22
|
-
|
34
|
+
result = Sass.compile_string('h1 { font-size: 40px; }')
|
35
|
+
puts result.css
|
23
36
|
```
|
24
37
|
|
25
38
|
---
|
data/lib/sass/compile_error.rb
CHANGED
@@ -3,18 +3,23 @@
|
|
3
3
|
module Sass
|
4
4
|
# An exception thrown because a Sass compilation failed.
|
5
5
|
class CompileError < StandardError
|
6
|
-
|
6
|
+
# @return [String, nil]
|
7
|
+
attr_accessor :sass_stack
|
8
|
+
|
9
|
+
# @return [Logger::SourceSpan, nil]
|
10
|
+
attr_accessor :span
|
7
11
|
|
8
12
|
def initialize(message, full_message, sass_stack, span)
|
9
13
|
super(message)
|
10
|
-
@full_message = full_message
|
11
|
-
@sass_stack = sass_stack
|
14
|
+
@full_message = full_message == '' ? nil : full_message.dup
|
15
|
+
@sass_stack = sass_stack == '' ? nil : sass_stack
|
12
16
|
@span = span
|
13
17
|
end
|
14
18
|
|
15
|
-
|
19
|
+
# @return [String]
|
20
|
+
def full_message(*args, **kwargs)
|
16
21
|
if @full_message.nil?
|
17
|
-
super
|
22
|
+
super(*args, **kwargs)
|
18
23
|
else
|
19
24
|
@full_message
|
20
25
|
end
|
data/lib/sass/compile_result.rb
CHANGED
@@ -2,8 +2,17 @@
|
|
2
2
|
|
3
3
|
module Sass
|
4
4
|
# The result of compiling Sass to CSS. Returned by {Sass.compile} and {Sass.compile_string}.
|
5
|
+
#
|
6
|
+
# @see https://sass-lang.com/documentation/js-api/interfaces/CompileResult
|
5
7
|
class CompileResult
|
6
|
-
|
8
|
+
# @return [String]
|
9
|
+
attr_reader :css
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_reader :source_map
|
13
|
+
|
14
|
+
# @return [Array<String>]
|
15
|
+
attr_reader :loaded_urls
|
7
16
|
|
8
17
|
def initialize(css, source_map, loaded_urls)
|
9
18
|
@css = css
|
data/lib/sass/embedded/host.rb
CHANGED
@@ -36,6 +36,8 @@ module Sass
|
|
36
36
|
quiet_deps:,
|
37
37
|
verbose:)
|
38
38
|
await do
|
39
|
+
alert_color = $stderr.tty? if alert_color.nil?
|
40
|
+
|
39
41
|
@function_registry = FunctionRegistry.new(functions, alert_color: alert_color)
|
40
42
|
@importer_registry = ImporterRegistry.new(importers, load_paths, alert_color: alert_color)
|
41
43
|
@logger_registry = LoggerRegistry.new(logger)
|
data/lib/sass/embedded.rb
CHANGED
@@ -14,10 +14,31 @@ module Sass
|
|
14
14
|
@channel = Channel.new
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
18
|
-
#
|
17
|
+
# Compiles the Sass file at +path+ to CSS.
|
18
|
+
# @param path [String]
|
19
|
+
# @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
|
20
|
+
# {@use}[https://sass-lang.com/documentation/at-rules/use] and {@import}[https://sass-lang.com/documentation/at-rules/import].
|
21
|
+
# @param source_map [Boolean] Whether or not Sass should generate a source map.
|
22
|
+
# @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
|
23
|
+
# @param style [String, Symbol] The OutputStyle of the compiled CSS.
|
24
|
+
# @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
|
25
|
+
# @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
|
26
|
+
# {@use}[https://sass-lang.com/documentation/at-rules/use] and {@import}[https://sass-lang.com/documentation/at-rules/import].
|
27
|
+
# @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
|
28
|
+
# and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
|
29
|
+
# @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
|
30
|
+
# warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
|
31
|
+
# not to use colors depending on whether the user is using an interactive terminal.
|
32
|
+
# @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
|
33
|
+
# @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
|
34
|
+
# dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
|
35
|
+
# Stylesheets that are imported relative to the entrypoint are not considered dependencies.
|
36
|
+
# @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
|
37
|
+
# compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
|
38
|
+
# deprecation warning it encounters.
|
19
39
|
# @return [CompileResult]
|
20
40
|
# @raise [CompileError]
|
41
|
+
# @see https://sass-lang.com/documentation/js-api/modules#compile
|
21
42
|
def compile(path,
|
22
43
|
load_paths: [],
|
23
44
|
|
@@ -29,7 +50,7 @@ module Sass
|
|
29
50
|
importers: [],
|
30
51
|
|
31
52
|
alert_ascii: false,
|
32
|
-
alert_color:
|
53
|
+
alert_color: nil,
|
33
54
|
logger: nil,
|
34
55
|
quiet_deps: false,
|
35
56
|
verbose: false)
|
@@ -58,10 +79,35 @@ module Sass
|
|
58
79
|
)
|
59
80
|
end
|
60
81
|
|
61
|
-
#
|
62
|
-
#
|
82
|
+
# Compiles a stylesheet whose contents is +source+ to CSS.
|
83
|
+
# @param source [String]
|
84
|
+
# @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
|
85
|
+
# @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
|
86
|
+
# {@use}[https://sass-lang.com/documentation/at-rules/use] and {@import}[https://sass-lang.com/documentation/at-rules/import].
|
87
|
+
# @param syntax [String, Symbol] The Syntax to use to parse the entrypoint stylesheet.
|
88
|
+
# @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
|
89
|
+
# used to resolve relative loads in the entrypoint stylesheet.
|
90
|
+
# @param source_map [Boolean] Whether or not Sass should generate a source map.
|
91
|
+
# @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
|
92
|
+
# @param style [String, Symbol] The OutputStyle of the compiled CSS.
|
93
|
+
# @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
|
94
|
+
# @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
|
95
|
+
# {@use}[https://sass-lang.com/documentation/at-rules/use] and {@import}[https://sass-lang.com/documentation/at-rules/import].
|
96
|
+
# @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
|
97
|
+
# and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
|
98
|
+
# @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
|
99
|
+
# warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
|
100
|
+
# not to use colors depending on whether the user is using an interactive terminal.
|
101
|
+
# @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
|
102
|
+
# @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
|
103
|
+
# dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
|
104
|
+
# Stylesheets that are imported relative to the entrypoint are not considered dependencies.
|
105
|
+
# @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
|
106
|
+
# compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
|
107
|
+
# deprecation warning it encounters.
|
63
108
|
# @return [CompileResult]
|
64
109
|
# @raise [CompileError]
|
110
|
+
# @see https://sass-lang.com/documentation/js-api/modules#compileString
|
65
111
|
def compile_string(source,
|
66
112
|
importer: nil,
|
67
113
|
load_paths: [],
|
@@ -76,7 +122,7 @@ module Sass
|
|
76
122
|
importers: [],
|
77
123
|
|
78
124
|
alert_ascii: false,
|
79
|
-
alert_color:
|
125
|
+
alert_color: nil,
|
80
126
|
logger: nil,
|
81
127
|
quiet_deps: false,
|
82
128
|
verbose: false)
|
@@ -104,7 +150,8 @@ module Sass
|
|
104
150
|
)
|
105
151
|
end
|
106
152
|
|
107
|
-
#
|
153
|
+
# @return [String] Information about the Sass implementation.
|
154
|
+
# @see https://sass-lang.com/documentation/js-api/modules#info
|
108
155
|
def info
|
109
156
|
@info ||= "sass-embedded\t#{Host.new(@channel).version_request.implementation_version}"
|
110
157
|
end
|
@@ -5,7 +5,10 @@ module Sass
|
|
5
5
|
# A specific location within a source file.
|
6
6
|
#
|
7
7
|
# This is always associated with a {SourceSpan} which indicates which file it refers to.
|
8
|
+
#
|
9
|
+
# @see https://sass-lang.com/documentation/js-api/interfaces/SourceLocation
|
8
10
|
class SourceLocation
|
11
|
+
# @return [Integer]
|
9
12
|
attr_reader :offset, :line, :column
|
10
13
|
|
11
14
|
def initialize(offset, line, column)
|
@@ -3,8 +3,17 @@
|
|
3
3
|
module Sass
|
4
4
|
module Logger
|
5
5
|
# A span of text within a source file.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/interfaces/SourceSpan
|
6
8
|
class SourceSpan
|
7
|
-
|
9
|
+
# @return [SourceLocation]
|
10
|
+
attr_reader :start, :end
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :text
|
14
|
+
|
15
|
+
# @return [String, nil]
|
16
|
+
attr_reader :url, :context
|
8
17
|
|
9
18
|
def initialize(start, end_, text, url, context)
|
10
19
|
@start = start
|
data/lib/sass/logger.rb
CHANGED
@@ -6,7 +6,12 @@ module Sass
|
|
6
6
|
#
|
7
7
|
# An argument list comes from a rest argument. It's distinct from a normal {List} in that it may contain a keyword
|
8
8
|
# map as well as the positional arguments.
|
9
|
+
#
|
10
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassArgumentList
|
9
11
|
class ArgumentList < Value::List
|
12
|
+
# @param contents [Array<Value>]
|
13
|
+
# @param keywords [Hash<::String, Value>]
|
14
|
+
# @param separator [::String]
|
10
15
|
def initialize(contents = [], keywords = {}, separator = ',')
|
11
16
|
super(contents, separator: separator)
|
12
17
|
|
@@ -15,6 +20,7 @@ module Sass
|
|
15
20
|
@keywords = keywords.transform_keys(&:to_s).freeze
|
16
21
|
end
|
17
22
|
|
23
|
+
# @return [Hash<::String, Value>]
|
18
24
|
def keywords
|
19
25
|
@keywords_accessed = true
|
20
26
|
@keywords
|
data/lib/sass/value/boolean.rb
CHANGED
@@ -3,31 +3,39 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's boolean type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassBoolean
|
6
8
|
class Boolean
|
7
9
|
include Value
|
8
10
|
|
11
|
+
# @param value [::Boolean]
|
9
12
|
def initialize(value)
|
10
13
|
@value = value
|
11
14
|
end
|
12
15
|
|
16
|
+
# @return [::Boolean]
|
13
17
|
attr_reader :value
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
self
|
19
|
+
# @return [Boolean]
|
20
|
+
def !
|
21
|
+
value ? Boolean::FALSE : Boolean::TRUE
|
19
22
|
end
|
20
23
|
|
24
|
+
# @return [::Boolean]
|
21
25
|
def ==(other)
|
22
26
|
other.is_a?(Sass::Value::Boolean) && other.value == value
|
23
27
|
end
|
24
28
|
|
29
|
+
# @return [Integer]
|
25
30
|
def hash
|
26
31
|
@hash ||= value.hash
|
27
32
|
end
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
alias to_bool value
|
35
|
+
|
36
|
+
# @return [Boolean]
|
37
|
+
def assert_boolean(_name = nil)
|
38
|
+
self
|
31
39
|
end
|
32
40
|
|
33
41
|
# Sass's true value.
|
data/lib/sass/value/color.rb
CHANGED
@@ -5,9 +5,20 @@ module Sass
|
|
5
5
|
# Sass's color type.
|
6
6
|
#
|
7
7
|
# No matter what representation was originally used to create this color, all of its channels are accessible.
|
8
|
+
#
|
9
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassColor
|
8
10
|
class Color
|
9
11
|
include Value
|
10
12
|
|
13
|
+
# @param red [Numeric]
|
14
|
+
# @param green [Numeric]
|
15
|
+
# @param blue [Numeric]
|
16
|
+
# @param hue [Numeric]
|
17
|
+
# @param saturation [Numeric]
|
18
|
+
# @param lightness [Numeric]
|
19
|
+
# @param whiteness [Numeric]
|
20
|
+
# @param blackness [Numeric]
|
21
|
+
# @param alpha [Numeric]
|
11
22
|
def initialize(red: nil,
|
12
23
|
green: nil,
|
13
24
|
blue: nil,
|
@@ -37,88 +48,104 @@ module Sass
|
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
40
|
-
|
41
|
-
green: nil,
|
42
|
-
blue: nil,
|
43
|
-
hue: nil,
|
44
|
-
saturation: nil,
|
45
|
-
lightness: nil,
|
46
|
-
whiteness: nil,
|
47
|
-
blackness: nil,
|
48
|
-
alpha: nil)
|
49
|
-
if whiteness || blackness
|
50
|
-
Sass::Value::Color.new(hue: hue || self.hue,
|
51
|
-
whiteness: whiteness || self.whiteness,
|
52
|
-
blackness: blackness || self.blackness,
|
53
|
-
alpha: alpha || self.alpha)
|
54
|
-
elsif hue || saturation || lightness
|
55
|
-
Sass::Value::Color.new(hue: hue || self.hue,
|
56
|
-
saturation: saturation || self.saturation,
|
57
|
-
lightness: lightness || self.lightness,
|
58
|
-
alpha: alpha || self.alpha)
|
59
|
-
elsif red || green || blue
|
60
|
-
Sass::Value::Color.new(red: red ? FuzzyMath.round(red) : self.red,
|
61
|
-
green: green ? FuzzyMath.round(green) : self.green,
|
62
|
-
blue: blue ? FuzzyMath.round(blue) : self.blue,
|
63
|
-
alpha: alpha || self.alpha)
|
64
|
-
else
|
65
|
-
dup.instance_eval do
|
66
|
-
@alpha = FuzzyMath.assert_between(alpha, 0, 1, 'alpha')
|
67
|
-
self
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
51
|
+
# @return [Integer]
|
72
52
|
def red
|
73
53
|
hsl_to_rgb unless defined? @red
|
74
54
|
|
75
55
|
@red
|
76
56
|
end
|
77
57
|
|
58
|
+
# @return [Integer]
|
78
59
|
def green
|
79
60
|
hsl_to_rgb unless defined? @green
|
80
61
|
|
81
62
|
@green
|
82
63
|
end
|
83
64
|
|
65
|
+
# @return [Integer]
|
84
66
|
def blue
|
85
67
|
hsl_to_rgb unless defined? @blue
|
86
68
|
|
87
69
|
@blue
|
88
70
|
end
|
89
71
|
|
72
|
+
# @return [Numeric]
|
90
73
|
def hue
|
91
74
|
rgb_to_hsl unless defined? @hue
|
92
75
|
|
93
76
|
@hue
|
94
77
|
end
|
95
78
|
|
79
|
+
# @return [Numeric]
|
96
80
|
def saturation
|
97
81
|
rgb_to_hsl unless defined? @saturation
|
98
82
|
|
99
83
|
@saturation
|
100
84
|
end
|
101
85
|
|
86
|
+
# @return [Numeric]
|
102
87
|
def lightness
|
103
88
|
rgb_to_hsl unless defined? @lightness
|
104
89
|
|
105
90
|
@lightness
|
106
91
|
end
|
107
92
|
|
93
|
+
# @return [Numeric]
|
108
94
|
def whiteness
|
109
95
|
@whiteness ||= Rational([red, green, blue].min, 255) * 100
|
110
96
|
end
|
111
97
|
|
98
|
+
# @return [Numeric]
|
112
99
|
def blackness
|
113
100
|
@blackness ||= 100 - (Rational([red, green, blue].max, 255) * 100)
|
114
101
|
end
|
115
102
|
|
103
|
+
# @return [Numeric]
|
116
104
|
attr_reader :alpha
|
117
105
|
|
118
|
-
|
119
|
-
|
106
|
+
# @param red [Numeric]
|
107
|
+
# @param green [Numeric]
|
108
|
+
# @param blue [Numeric]
|
109
|
+
# @param hue [Numeric]
|
110
|
+
# @param saturation [Numeric]
|
111
|
+
# @param lightness [Numeric]
|
112
|
+
# @param whiteness [Numeric]
|
113
|
+
# @param blackness [Numeric]
|
114
|
+
# @param alpha [Numeric]
|
115
|
+
# @return [Color]
|
116
|
+
def change(red: nil,
|
117
|
+
green: nil,
|
118
|
+
blue: nil,
|
119
|
+
hue: nil,
|
120
|
+
saturation: nil,
|
121
|
+
lightness: nil,
|
122
|
+
whiteness: nil,
|
123
|
+
blackness: nil,
|
124
|
+
alpha: nil)
|
125
|
+
if whiteness || blackness
|
126
|
+
Sass::Value::Color.new(hue: hue || self.hue,
|
127
|
+
whiteness: whiteness || self.whiteness,
|
128
|
+
blackness: blackness || self.blackness,
|
129
|
+
alpha: alpha || self.alpha)
|
130
|
+
elsif hue || saturation || lightness
|
131
|
+
Sass::Value::Color.new(hue: hue || self.hue,
|
132
|
+
saturation: saturation || self.saturation,
|
133
|
+
lightness: lightness || self.lightness,
|
134
|
+
alpha: alpha || self.alpha)
|
135
|
+
elsif red || green || blue
|
136
|
+
Sass::Value::Color.new(red: red ? FuzzyMath.round(red) : self.red,
|
137
|
+
green: green ? FuzzyMath.round(green) : self.green,
|
138
|
+
blue: blue ? FuzzyMath.round(blue) : self.blue,
|
139
|
+
alpha: alpha || self.alpha)
|
140
|
+
else
|
141
|
+
dup.instance_eval do
|
142
|
+
@alpha = FuzzyMath.assert_between(alpha, 0, 1, 'alpha')
|
143
|
+
self
|
144
|
+
end
|
145
|
+
end
|
120
146
|
end
|
121
147
|
|
148
|
+
# @return [::Boolean]
|
122
149
|
def ==(other)
|
123
150
|
other.is_a?(Sass::Value::Color) &&
|
124
151
|
other.red == red &&
|
@@ -127,10 +154,16 @@ module Sass
|
|
127
154
|
other.alpha == alpha
|
128
155
|
end
|
129
156
|
|
157
|
+
# @return [Integer]
|
130
158
|
def hash
|
131
159
|
@hash ||= red.hash ^ green.hash ^ blue.hash ^ alpha.hash
|
132
160
|
end
|
133
161
|
|
162
|
+
# @return [Color]
|
163
|
+
def assert_color(_name = nil)
|
164
|
+
self
|
165
|
+
end
|
166
|
+
|
134
167
|
private
|
135
168
|
|
136
169
|
def rgb_to_hsl
|
data/lib/sass/value/function.rb
CHANGED
@@ -3,9 +3,13 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's function type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassFunction
|
6
8
|
class Function
|
7
9
|
include Value
|
8
10
|
|
11
|
+
# @param id_or_signature [Numeric, ::String]
|
12
|
+
# @param callback [Proc]
|
9
13
|
def initialize(id_or_signature, callback = nil)
|
10
14
|
if id_or_signature.is_a? Numeric
|
11
15
|
@id = id_or_signature
|
@@ -15,12 +19,16 @@ module Sass
|
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
|
-
|
22
|
+
# @return [Integer, nil]
|
23
|
+
attr_reader :id
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
# @return [::String, nil]
|
26
|
+
attr_reader :signature
|
27
|
+
|
28
|
+
# @return [Proc, nil]
|
29
|
+
attr_reader :callback
|
23
30
|
|
31
|
+
# @return [::Boolean]
|
24
32
|
def ==(other)
|
25
33
|
if id.nil?
|
26
34
|
other.equal? self
|
@@ -29,9 +37,15 @@ module Sass
|
|
29
37
|
end
|
30
38
|
end
|
31
39
|
|
40
|
+
# @return [Integer]
|
32
41
|
def hash
|
33
42
|
id.nil? ? signature.hash : id.hash
|
34
43
|
end
|
44
|
+
|
45
|
+
# @return [Function]
|
46
|
+
def assert_function(_name = nil)
|
47
|
+
self
|
48
|
+
end
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
data/lib/sass/value/list.rb
CHANGED
@@ -3,9 +3,14 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's list type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassList
|
6
8
|
class List
|
7
9
|
include Value
|
8
10
|
|
11
|
+
# @param contents [Array<Value>]
|
12
|
+
# @param separator [::String]
|
13
|
+
# @param bracketed [::Boolean]
|
9
14
|
def initialize(contents = [], separator: ',', bracketed: false)
|
10
15
|
if separator.nil? && contents.length > 1
|
11
16
|
raise error 'A list with more than one element must have an explicit separator'
|
@@ -16,22 +21,28 @@ module Sass
|
|
16
21
|
@bracketed = bracketed.freeze
|
17
22
|
end
|
18
23
|
|
19
|
-
|
24
|
+
# @return [Array<Value>]
|
25
|
+
attr_reader :contents
|
20
26
|
|
21
|
-
|
27
|
+
# @return [::String, nil]
|
28
|
+
attr_reader :separator
|
22
29
|
|
30
|
+
# @return [::Boolean]
|
23
31
|
def bracketed?
|
24
32
|
@bracketed
|
25
33
|
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
35
|
+
# @return [::Boolean]
|
36
|
+
def ==(other)
|
37
|
+
(other.is_a?(Sass::Value::List) &&
|
38
|
+
other.contents == contents &&
|
39
|
+
other.separator == separator &&
|
40
|
+
other.bracketed? == bracketed?) ||
|
41
|
+
(to_a.empty? && other.is_a?(Sass::Value::Map) && other.to_a.empty?)
|
33
42
|
end
|
34
43
|
|
44
|
+
# @param index [Numeric]
|
45
|
+
# @return [Value]
|
35
46
|
def at(index)
|
36
47
|
index = index.floor
|
37
48
|
index = to_a.length + index if index.negative?
|
@@ -40,18 +51,24 @@ module Sass
|
|
40
51
|
to_a[index]
|
41
52
|
end
|
42
53
|
|
43
|
-
|
44
|
-
(other.is_a?(Sass::Value::List) &&
|
45
|
-
other.contents == contents &&
|
46
|
-
other.separator == separator &&
|
47
|
-
other.bracketed? == bracketed?) ||
|
48
|
-
(to_a.empty? && other.is_a?(Sass::Value::Map) && other.to_a.empty?)
|
49
|
-
end
|
50
|
-
|
54
|
+
# @return [Integer]
|
51
55
|
def hash
|
52
56
|
@hash ||= contents.hash
|
53
57
|
end
|
54
58
|
|
59
|
+
alias to_a contents
|
60
|
+
|
61
|
+
# @return [Map, nil]
|
62
|
+
def to_map
|
63
|
+
to_a.empty? ? Sass::Value::Map.new({}) : nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Map]
|
67
|
+
# @raise [ScriptError]
|
68
|
+
def assert_map(name = nil)
|
69
|
+
to_a.empty? ? Sass::Value::Map.new({}) : super.assert_map(name)
|
70
|
+
end
|
71
|
+
|
55
72
|
private
|
56
73
|
|
57
74
|
def to_a_length
|
data/lib/sass/value/map.rb
CHANGED
@@ -3,31 +3,32 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's map type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassMap
|
6
8
|
class Map
|
7
9
|
include Value
|
8
10
|
|
11
|
+
# @param contents [Hash<Value, Value>]
|
9
12
|
def initialize(contents = {})
|
10
13
|
@contents = contents.freeze
|
11
14
|
end
|
12
15
|
|
16
|
+
# @return [Hash<Value, Value>]
|
13
17
|
attr_reader :contents
|
14
18
|
|
19
|
+
# @return [::String, nil]
|
15
20
|
def separator
|
16
21
|
contents.empty? ? nil : ','
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def to_map
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_a
|
28
|
-
contents.to_a.map { |entry| Sass::Value::List.new(entry, separator: ' ') }
|
24
|
+
# @return [::Boolean]
|
25
|
+
def ==(other)
|
26
|
+
(other.is_a?(Sass::Value::Map) && other.contents == contents) ||
|
27
|
+
(contents.empty? && other.is_a?(Sass::Value::List) && other.to_a.empty?)
|
29
28
|
end
|
30
29
|
|
30
|
+
# @param index [Numeric, Value]
|
31
|
+
# @return [List<(Value, Value)>, Value]
|
31
32
|
def at(index)
|
32
33
|
if index.is_a? Numeric
|
33
34
|
index = index.floor
|
@@ -40,15 +41,26 @@ module Sass
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
-
(other.is_a?(Sass::Value::Map) && other.contents == contents) ||
|
45
|
-
(contents.empty? && other.is_a?(Sass::Value::List) && other.to_a.empty?)
|
46
|
-
end
|
47
|
-
|
44
|
+
# @return [Integer]
|
48
45
|
def hash
|
49
46
|
@hash ||= contents.hash
|
50
47
|
end
|
51
48
|
|
49
|
+
# @return [Array<List<(Value, Value)>>]
|
50
|
+
def to_a
|
51
|
+
contents.to_a.map { |entry| Sass::Value::List.new(entry, separator: ' ') }
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Map]
|
55
|
+
def to_map
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Map]
|
60
|
+
def assert_map(_name = nil)
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
52
64
|
private
|
53
65
|
|
54
66
|
def to_a_length
|
data/lib/sass/value/null.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's null type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/modules#sassNull
|
6
8
|
class Null
|
7
9
|
include Value
|
8
10
|
|
@@ -10,26 +12,31 @@ module Sass
|
|
10
12
|
@value = nil
|
11
13
|
end
|
12
14
|
|
15
|
+
# @return [nil]
|
13
16
|
attr_reader :value
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
false
|
18
|
+
# @return [Boolean]
|
19
|
+
def !
|
20
|
+
Boolean::TRUE
|
19
21
|
end
|
20
22
|
|
23
|
+
# @return [::Boolean]
|
21
24
|
def ==(other)
|
22
25
|
other.is_a?(Sass::Value::Null)
|
23
26
|
end
|
24
27
|
|
28
|
+
# @return [Integer]
|
25
29
|
def hash
|
26
30
|
@hash ||= value.hash
|
27
31
|
end
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
# @return [::Boolean]
|
34
|
+
def to_bool
|
35
|
+
false
|
31
36
|
end
|
32
37
|
|
38
|
+
alias to_nil value
|
39
|
+
|
33
40
|
# Sass's null value.
|
34
41
|
NULL = Null.new
|
35
42
|
|
data/lib/sass/value/number.rb
CHANGED
@@ -3,9 +3,14 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's number type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassNumber
|
6
8
|
class Number
|
7
9
|
include Value
|
8
10
|
|
11
|
+
# @param value [Numeric]
|
12
|
+
# @param numerator_units [Array<::String>, ::String]
|
13
|
+
# @param denominator_units [Array<::String>, ::String]
|
9
14
|
def initialize(value, numerator_units = [], denominator_units = [])
|
10
15
|
numerator_units = [numerator_units] if numerator_units.is_a?(::String)
|
11
16
|
denominator_units = [denominator_units] if denominator_units.is_a?(::String)
|
@@ -40,65 +45,141 @@ module Sass
|
|
40
45
|
@denominator_units = denominator_units.freeze
|
41
46
|
end
|
42
47
|
|
43
|
-
|
48
|
+
# @return [Numeric]
|
49
|
+
attr_reader :value
|
44
50
|
|
51
|
+
# @return [Array<::String>]
|
52
|
+
attr_reader :numerator_units, :denominator_units
|
53
|
+
|
54
|
+
# @return [::Boolean]
|
55
|
+
def ==(other)
|
56
|
+
return false unless other.is_a? Sass::Value::Number
|
57
|
+
|
58
|
+
return false if numerator_units.length != other.numerator_units.length ||
|
59
|
+
denominator_units.length != other.denominator_units.length
|
60
|
+
|
61
|
+
return FuzzyMath.equals(value, other.value) if unitless?
|
62
|
+
|
63
|
+
if Unit.canonicalize_units(numerator_units) != Unit.canonicalize_units(other.numerator_units) &&
|
64
|
+
Unit.canonicalize_units(denominator_units) != Unit.canonicalize_units(other.denominator_units)
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
|
68
|
+
FuzzyMath.equals(
|
69
|
+
(value *
|
70
|
+
Unit.canonical_multiplier(numerator_units) /
|
71
|
+
Unit.canonical_multiplier(denominator_units)),
|
72
|
+
(other.value *
|
73
|
+
Unit.canonical_multiplier(other.numerator_units) /
|
74
|
+
Unit.canonical_multiplier(other.denominator_units))
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
# @return [Integer]
|
79
|
+
def hash
|
80
|
+
@hash ||= if unitless?
|
81
|
+
FuzzyMath.hash(value)
|
82
|
+
elsif single_unit?
|
83
|
+
FuzzyMath.hash(
|
84
|
+
value * Unit.canonical_multiplier_for_unit(numerator_units.first)
|
85
|
+
)
|
86
|
+
else
|
87
|
+
FuzzyMath.hash(
|
88
|
+
value * Unit.canonical_multiplier(numerator_units) / Unit.canonical_multiplier(denominator_units)
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [::Boolean]
|
45
94
|
def unitless?
|
46
95
|
numerator_units.empty? && denominator_units.empty?
|
47
96
|
end
|
48
97
|
|
98
|
+
# @return [Number]
|
99
|
+
# @raise [ScriptError]
|
49
100
|
def assert_unitless(name = nil)
|
50
101
|
raise error "Expected #{self} to have no units", name unless unitless?
|
102
|
+
|
103
|
+
self
|
51
104
|
end
|
52
105
|
|
106
|
+
# @return [::Boolean]
|
53
107
|
def units?
|
54
108
|
!unitless?
|
55
109
|
end
|
56
110
|
|
111
|
+
# @param unit [::String]
|
112
|
+
# @return [::Boolean]
|
57
113
|
def unit?(unit)
|
58
114
|
single_unit? && numerator_units.first == unit
|
59
115
|
end
|
60
116
|
|
117
|
+
# @param unit [::String]
|
118
|
+
# @return [Number]
|
119
|
+
# @raise [ScriptError]
|
61
120
|
def assert_unit(unit, name = nil)
|
62
121
|
raise error "Expected #{self} to have no unit \"#{unit}\"", name unless unit?(unit)
|
122
|
+
|
123
|
+
self
|
63
124
|
end
|
64
125
|
|
126
|
+
# @return [::Boolean]
|
65
127
|
def integer?
|
66
128
|
FuzzyMath.integer?(value)
|
67
129
|
end
|
68
130
|
|
131
|
+
# @return [Integer]
|
132
|
+
# @raise [ScriptError]
|
69
133
|
def assert_integer(name = nil)
|
70
134
|
raise error "#{self} is not an integer", name unless integer?
|
71
135
|
|
72
136
|
to_i
|
73
137
|
end
|
74
138
|
|
139
|
+
# @return [Integer]
|
75
140
|
def to_i
|
76
141
|
FuzzyMath.to_i(value)
|
77
142
|
end
|
78
143
|
|
144
|
+
# @param min [Numeric]
|
145
|
+
# @param max [Numeric]
|
146
|
+
# @return [Numeric]
|
147
|
+
# @raise [ScriptError]
|
79
148
|
def assert_between(min, max, name = nil)
|
80
149
|
FuzzyMath.assert_between(value, min, max, name)
|
81
150
|
end
|
82
151
|
|
152
|
+
# @param unit [::String]
|
153
|
+
# @return [::Boolean]
|
83
154
|
def compatible_with_unit?(unit)
|
84
155
|
single_unit? && !Unit.conversion_factor(numerator_units.first, unit).nil?
|
85
156
|
end
|
86
157
|
|
158
|
+
# @param new_numerator_units [Array<::String>]
|
159
|
+
# @param new_denominator_units [Array<::String>]
|
160
|
+
# @return [Number]
|
87
161
|
def convert(new_numerator_units, new_denominator_units, name = nil)
|
88
162
|
Number.new(convert_value(new_numerator_units, new_denominator_units, name), new_numerator_units,
|
89
163
|
new_denominator_units)
|
90
164
|
end
|
91
165
|
|
166
|
+
# @param new_numerator_units [Array<::String>]
|
167
|
+
# @param new_denominator_units [Array<::String>]
|
168
|
+
# @return [Numeric]
|
92
169
|
def convert_value(new_numerator_units, new_denominator_units, name = nil)
|
93
170
|
coerce_or_convert_value(new_numerator_units, new_denominator_units,
|
94
171
|
coerce_unitless: false,
|
95
172
|
name: name)
|
96
173
|
end
|
97
174
|
|
175
|
+
# @param other [Number]
|
176
|
+
# @return [Number]
|
98
177
|
def convert_to_match(other, name = nil, other_name = nil)
|
99
178
|
Number.new(convert_value_to_match(other, name, other_name), other.numerator_units, other.denominator_units)
|
100
179
|
end
|
101
180
|
|
181
|
+
# @param other [Number]
|
182
|
+
# @return [Numeric]
|
102
183
|
def convert_value_to_match(other, name = nil, other_name = nil)
|
103
184
|
coerce_or_convert_value(other.numerator_units, other.denominator_units,
|
104
185
|
coerce_unitless: false,
|
@@ -107,25 +188,37 @@ module Sass
|
|
107
188
|
other_name: other_name)
|
108
189
|
end
|
109
190
|
|
191
|
+
# @param new_numerator_units [Array<::String>]
|
192
|
+
# @param new_denominator_units [Array<::String>]
|
193
|
+
# @return [Number]
|
110
194
|
def coerce(new_numerator_units, new_denominator_units, name = nil)
|
111
195
|
Number.new(coerce_value(new_numerator_units, new_denominator_units, name), new_numerator_units,
|
112
196
|
new_denominator_units)
|
113
197
|
end
|
114
198
|
|
199
|
+
# @param new_numerator_units [Array<::String>]
|
200
|
+
# @param new_denominator_units [Array<::String>]
|
201
|
+
# @return [Numeric]
|
115
202
|
def coerce_value(new_numerator_units, new_denominator_units, name = nil)
|
116
203
|
coerce_or_convert_value(new_numerator_units, new_denominator_units,
|
117
204
|
coerce_unitless: true,
|
118
205
|
name: name)
|
119
206
|
end
|
120
207
|
|
208
|
+
# @param unit [::String]
|
209
|
+
# @return [Numeric]
|
121
210
|
def coerce_value_to_unit(unit, name = nil)
|
122
211
|
coerce_value([unit], [], name)
|
123
212
|
end
|
124
213
|
|
214
|
+
# @param other [Number]
|
215
|
+
# @return [Number]
|
125
216
|
def coerce_to_match(other, name = nil, other_name = nil)
|
126
217
|
Number.new(coerce_value_to_match(other, name, other_name), other.numerator_units, other.denominator_units)
|
127
218
|
end
|
128
219
|
|
220
|
+
# @param other [Number]
|
221
|
+
# @return [Numeric]
|
129
222
|
def coerce_value_to_match(other, name = nil, other_name = nil)
|
130
223
|
coerce_or_convert_value(other.numerator_units, other.denominator_units,
|
131
224
|
coerce_unitless: true,
|
@@ -134,47 +227,11 @@ module Sass
|
|
134
227
|
other_name: other_name)
|
135
228
|
end
|
136
229
|
|
230
|
+
# @return [Number]
|
137
231
|
def assert_number(_name = nil)
|
138
232
|
self
|
139
233
|
end
|
140
234
|
|
141
|
-
def ==(other)
|
142
|
-
return false unless other.is_a? Sass::Value::Number
|
143
|
-
|
144
|
-
return false if numerator_units.length != other.numerator_units.length ||
|
145
|
-
denominator_units.length != other.denominator_units.length
|
146
|
-
|
147
|
-
return FuzzyMath.equals(value, other.value) if unitless?
|
148
|
-
|
149
|
-
if Unit.canonicalize_units(numerator_units) != Unit.canonicalize_units(other.numerator_units) &&
|
150
|
-
Unit.canonicalize_units(denominator_units) != Unit.canonicalize_units(other.denominator_units)
|
151
|
-
return false
|
152
|
-
end
|
153
|
-
|
154
|
-
FuzzyMath.equals(
|
155
|
-
(value *
|
156
|
-
Unit.canonical_multiplier(numerator_units) /
|
157
|
-
Unit.canonical_multiplier(denominator_units)),
|
158
|
-
(other.value *
|
159
|
-
Unit.canonical_multiplier(other.numerator_units) /
|
160
|
-
Unit.canonical_multiplier(other.denominator_units))
|
161
|
-
)
|
162
|
-
end
|
163
|
-
|
164
|
-
def hash
|
165
|
-
@hash ||= if unitless?
|
166
|
-
FuzzyMath.hash(value)
|
167
|
-
elsif single_unit?
|
168
|
-
FuzzyMath.hash(
|
169
|
-
value * Unit.canonical_multiplier_for_unit(numerator_units.first)
|
170
|
-
)
|
171
|
-
else
|
172
|
-
FuzzyMath.hash(
|
173
|
-
value * Unit.canonical_multiplier(numerator_units) / Unit.canonical_multiplier(denominator_units)
|
174
|
-
)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
235
|
protected
|
179
236
|
|
180
237
|
def single_unit?
|
data/lib/sass/value/string.rb
CHANGED
@@ -3,42 +3,53 @@
|
|
3
3
|
module Sass
|
4
4
|
module Value
|
5
5
|
# Sass's string type.
|
6
|
+
#
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/SassString
|
6
8
|
class String
|
7
9
|
include Value
|
8
10
|
|
11
|
+
# @param text [::String]
|
12
|
+
# @param quoted: [::Boolean]
|
9
13
|
def initialize(text = '', quoted: true)
|
10
14
|
@text = text.freeze
|
11
15
|
@quoted = quoted
|
12
16
|
end
|
13
17
|
|
18
|
+
# @return [::String]
|
14
19
|
attr_reader :text
|
15
20
|
|
21
|
+
# @return [::Boolean]
|
16
22
|
def quoted?
|
17
23
|
@quoted
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
index = sass_index.assert_number(name).assert_integer(name)
|
22
|
-
raise error('String index may not be 0', name) if index.zero?
|
23
|
-
|
24
|
-
if index.abs > text.length
|
25
|
-
raise error("Invalid index #{sass_index} for a string with #{text.length} characters", name)
|
26
|
-
end
|
27
|
-
|
28
|
-
index.negative? ? text.length + index : index - 1
|
29
|
-
end
|
30
|
-
|
26
|
+
# @return [::Boolean]
|
31
27
|
def ==(other)
|
32
28
|
other.is_a?(Sass::Value::String) && other.text == text
|
33
29
|
end
|
34
30
|
|
31
|
+
# @return [Integer]
|
35
32
|
def hash
|
36
33
|
@hash ||= text.hash
|
37
34
|
end
|
38
35
|
|
36
|
+
# @return [String]
|
39
37
|
def assert_string(_name = nil)
|
40
38
|
self
|
41
39
|
end
|
40
|
+
|
41
|
+
# @param sass_index [Number]
|
42
|
+
# @return [Integer]
|
43
|
+
def sass_index_to_string_index(sass_index, name = nil)
|
44
|
+
index = sass_index.assert_number(name).assert_integer(name)
|
45
|
+
raise error('String index may not be 0', name) if index.zero?
|
46
|
+
|
47
|
+
if index.abs > text.length
|
48
|
+
raise error("Invalid index #{sass_index} for a string with #{text.length} characters", name)
|
49
|
+
end
|
50
|
+
|
51
|
+
index.negative? ? text.length + index : index - 1
|
52
|
+
end
|
42
53
|
end
|
43
54
|
end
|
44
55
|
end
|
data/lib/sass/value.rb
CHANGED
@@ -2,80 +2,108 @@
|
|
2
2
|
|
3
3
|
module Sass
|
4
4
|
# The abstract base class of Sass's value types.
|
5
|
+
#
|
6
|
+
# @see https://sass-lang.com/documentation/js-api/classes/Value
|
5
7
|
module Value
|
6
|
-
|
7
|
-
|
8
|
+
# @return [::String, nil]
|
9
|
+
def separator
|
10
|
+
nil
|
8
11
|
end
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
# @return [::Boolean]
|
14
|
+
def bracketed?
|
15
|
+
false
|
12
16
|
end
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
# @return [::Boolean]
|
19
|
+
def eql?(other)
|
20
|
+
self == other
|
16
21
|
end
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
# @param index [Numeric]
|
24
|
+
# @return [Value]
|
25
|
+
def [](index)
|
26
|
+
at(index)
|
20
27
|
end
|
21
28
|
|
22
|
-
|
23
|
-
|
29
|
+
# @param index [Numeric]
|
30
|
+
# @return [Value]
|
31
|
+
def at(index)
|
32
|
+
index < 1 && index >= -1 ? self : nil
|
24
33
|
end
|
25
34
|
|
26
|
-
|
27
|
-
|
35
|
+
# @return [Array<Value>]
|
36
|
+
def to_a
|
37
|
+
[self]
|
28
38
|
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if index.abs > to_a_length
|
35
|
-
raise error("Invalid index #{sass_index} for a list with #{to_a_length} elements", name)
|
36
|
-
end
|
37
|
-
|
38
|
-
index.negative? ? to_a_length + index : index - 1
|
40
|
+
# @return [::Boolean]
|
41
|
+
def to_bool
|
42
|
+
true
|
39
43
|
end
|
40
44
|
|
41
|
-
|
42
|
-
|
45
|
+
# @return [Map, nil]
|
46
|
+
def to_map
|
47
|
+
nil
|
43
48
|
end
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
# @return [Value, nil]
|
51
|
+
def to_nil
|
52
|
+
self
|
47
53
|
end
|
48
54
|
|
55
|
+
# @return [Boolean]
|
56
|
+
# @raise [ScriptError]
|
49
57
|
def assert_boolean(name = nil)
|
50
58
|
raise error("#{self} is not a boolean", name)
|
51
59
|
end
|
52
60
|
|
61
|
+
# @raise [ScriptError]
|
53
62
|
def assert_calculation(name = nil)
|
54
63
|
raise error("#{self} is not a calculation", name)
|
55
64
|
end
|
56
65
|
|
66
|
+
# @return [Color]
|
67
|
+
# @raise [ScriptError]
|
57
68
|
def assert_color(name = nil)
|
58
69
|
raise error("#{self} is not a color", name)
|
59
70
|
end
|
60
71
|
|
72
|
+
# @return [Function]
|
73
|
+
# @raise [ScriptError]
|
61
74
|
def assert_function(name = nil)
|
62
75
|
raise error("#{self} is not a function", name)
|
63
76
|
end
|
64
77
|
|
78
|
+
# @return [Map]
|
79
|
+
# @raise [ScriptError]
|
65
80
|
def assert_map(name = nil)
|
66
81
|
raise error("#{self} is not a map", name)
|
67
82
|
end
|
68
83
|
|
84
|
+
# @return [Number]
|
85
|
+
# @raise [ScriptError]
|
69
86
|
def assert_number(name = nil)
|
70
87
|
raise error("#{self} is not a number", name)
|
71
88
|
end
|
72
89
|
|
90
|
+
# @return [String]
|
91
|
+
# @raise [ScriptError]
|
73
92
|
def assert_string(name = nil)
|
74
93
|
raise error("#{self} is not a string", name)
|
75
94
|
end
|
76
95
|
|
77
|
-
|
78
|
-
|
96
|
+
# @param sass_index [Number]
|
97
|
+
# @return [Integer]
|
98
|
+
def sass_index_to_array_index(sass_index, name = nil)
|
99
|
+
index = sass_index.assert_number(name).assert_integer(name)
|
100
|
+
raise error('List index may not be 0', name) if index.zero?
|
101
|
+
|
102
|
+
if index.abs > to_a_length
|
103
|
+
raise error("Invalid index #{sass_index} for a list with #{to_a_length} elements", name)
|
104
|
+
end
|
105
|
+
|
106
|
+
index.negative? ? to_a_length + index : index - 1
|
79
107
|
end
|
80
108
|
|
81
109
|
private
|
data/lib/sass.rb
CHANGED
@@ -37,39 +37,30 @@ require_relative 'sass/value/string'
|
|
37
37
|
# The Sass module.
|
38
38
|
#
|
39
39
|
# This communicates with Embedded Dart Sass using the Embedded Sass protocol.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# Sass.compile('style.scss')
|
43
|
+
#
|
44
|
+
# @example
|
45
|
+
# Sass.compile_string('h1 { font-size: 40px; }')
|
40
46
|
module Sass
|
41
47
|
class << self
|
42
|
-
# The global {.compile} method.
|
43
|
-
#
|
44
|
-
# This instantiates a global {Embedded} instance and calls {Embedded#compile}.
|
45
|
-
#
|
46
|
-
# See {Embedded#compile} for keyword arguments.
|
47
|
-
#
|
48
|
-
# @example
|
49
|
-
# Sass.compile('style.scss')
|
50
48
|
# @return [CompileResult]
|
51
49
|
# @raise [CompileError]
|
50
|
+
# @see Embedded#compile
|
52
51
|
def compile(path, **kwargs)
|
53
52
|
instance.compile(path, **kwargs)
|
54
53
|
end
|
55
54
|
|
56
|
-
# The global {.compile_string} method.
|
57
|
-
#
|
58
|
-
# This instantiates a global {Embedded} instance and calls {Embedded#compile_string}.
|
59
|
-
#
|
60
|
-
# See {Embedded#compile_string} for keyword arguments.
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
# Sass.compile_string('h1 { font-size: 40px; }')
|
64
55
|
# @return [CompileResult]
|
65
56
|
# @raise [CompileError]
|
57
|
+
# @see Embedded#compile_string
|
66
58
|
def compile_string(source, **kwargs)
|
67
59
|
instance.compile_string(source, **kwargs)
|
68
60
|
end
|
69
61
|
|
70
|
-
#
|
71
|
-
#
|
72
|
-
# This instantiates a global {Embedded} instance and calls {Embedded#info}.
|
62
|
+
# @return [String]
|
63
|
+
# @see Embedded#info
|
73
64
|
def info
|
74
65
|
instance.info
|
75
66
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass-embedded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- なつき
|
@@ -177,8 +177,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
|
|
177
177
|
licenses:
|
178
178
|
- MIT
|
179
179
|
metadata:
|
180
|
-
documentation_uri: https://www.rubydoc.info/gems/sass-embedded/1.0.
|
181
|
-
source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.0.
|
180
|
+
documentation_uri: https://www.rubydoc.info/gems/sass-embedded/1.0.9
|
181
|
+
source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.0.9
|
182
182
|
funding_uri: https://github.com/sponsors/ntkme
|
183
183
|
post_install_message:
|
184
184
|
rdoc_options: []
|