code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def hue
rgb_to_hsl!
@attrs[:hue]
end
|
The hue component of the color.
@return [Numeric]
|
hue
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def saturation
rgb_to_hsl!
@attrs[:saturation]
end
|
The saturation component of the color.
@return [Numeric]
|
saturation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def lightness
rgb_to_hsl!
@attrs[:lightness]
end
|
The lightness component of the color.
@return [Numeric]
|
lightness
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def alpha?
alpha < 1
end
|
Returns whether this color object is translucent;
that is, whether the alpha channel is non-1.
@return [Boolean]
|
alpha?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def rgb
[red, green, blue].freeze
end
|
Returns the red, green, and blue components of the color.
@return [Array<Integer>] A frozen three-element array of the red, green, and blue
values (respectively) of the color
|
rgb
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def rgba
[red, green, blue, alpha].freeze
end
|
Returns the red, green, blue, and alpha components of the color.
@return [Array<Integer>] A frozen four-element array of the red, green,
blue, and alpha values (respectively) of the color
|
rgba
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def hsl
[hue, saturation, lightness].freeze
end
|
Returns the hue, saturation, and lightness components of the color.
@return [Array<Integer>] A frozen three-element array of the
hue, saturation, and lightness values (respectively) of the color
|
hsl
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def hsla
[hue, saturation, lightness, alpha].freeze
end
|
Returns the hue, saturation, lightness, and alpha components of the color.
@return [Array<Integer>] A frozen four-element array of the hue,
saturation, lightness, and alpha values (respectively) of the color
|
hsla
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def eq(other)
Sass::Script::Value::Bool.new(
other.is_a?(Color) && rgb == other.rgb && alpha == other.alpha)
end
|
The SassScript `==` operation.
**Note that this returns a {Sass::Script::Value::Bool} object,
not a Ruby boolean**.
@param other [Value] The right-hand side of the operator
@return [Bool] True if this value is the same as the other,
false otherwise
|
eq
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def with(attrs)
attrs = attrs.reject {|_k, v| v.nil?}
hsl = !([:hue, :saturation, :lightness] & attrs.keys).empty?
rgb = !([:red, :green, :blue] & attrs.keys).empty?
if hsl && rgb
raise ArgumentError.new("Cannot specify HSL and RGB values for a color at the same time")
end
if hsl
[:hue, :saturation, :lightness].each {|k| attrs[k] ||= send(k)}
elsif rgb
[:red, :green, :blue].each {|k| attrs[k] ||= send(k)}
else
# If we're just changing the alpha channel,
# keep all the HSL/RGB stuff we've calculated
attrs = @attrs.merge(attrs)
end
attrs[:alpha] ||= alpha
Color.new(attrs, nil, :allow_both_rgb_and_hsl)
end
|
Returns a copy of this color with one or more channels changed.
RGB or HSL colors may be changed, but not both at once.
For example:
Color.new([10, 20, 30]).with(:blue => 40)
#=> rgb(10, 40, 30)
Color.new([126, 126, 126]).with(:red => 0, :green => 255)
#=> rgb(0, 255, 126)
Color.new([255, 0, 127]).with(:saturation => 60)
#=> rgb(204, 51, 127)
Color.new([1, 2, 3]).with(:alpha => 0.4)
#=> rgba(1, 2, 3, 0.4)
@param attrs [{Symbol => Numeric}]
A map of channel names (`:red`, `:green`, `:blue`,
`:hue`, `:saturation`, `:lightness`, or `:alpha`) to values
@return [Color] The new Color object
@raise [ArgumentError] if both RGB and HSL keys are specified
|
with
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def plus(other)
if other.is_a?(Sass::Script::Value::Number) || other.is_a?(Sass::Script::Value::Color)
piecewise(other, :+)
else
super
end
end
|
The SassScript `+` operation.
Its functionality depends on the type of its argument:
{Number}
: Adds the number to each of the RGB color channels.
{Color}
: Adds each of the RGB color channels together.
{Value}
: See {Value::Base#plus}.
@param other [Value] The right-hand side of the operator
@return [Color] The resulting color
@raise [Sass::SyntaxError] if `other` is a number with units
|
plus
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def minus(other)
if other.is_a?(Sass::Script::Value::Number) || other.is_a?(Sass::Script::Value::Color)
piecewise(other, :-)
else
super
end
end
|
The SassScript `-` operation.
Its functionality depends on the type of its argument:
{Number}
: Subtracts the number from each of the RGB color channels.
{Color}
: Subtracts each of the other color's RGB color channels from this color's.
{Value}
: See {Value::Base#minus}.
@param other [Value] The right-hand side of the operator
@return [Color] The resulting color
@raise [Sass::SyntaxError] if `other` is a number with units
|
minus
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def times(other)
if other.is_a?(Sass::Script::Value::Number) || other.is_a?(Sass::Script::Value::Color)
piecewise(other, :*)
else
raise NoMethodError.new(nil, :times)
end
end
|
The SassScript `*` operation.
Its functionality depends on the type of its argument:
{Number}
: Multiplies the number by each of the RGB color channels.
{Color}
: Multiplies each of the RGB color channels together.
@param other [Number, Color] The right-hand side of the operator
@return [Color] The resulting color
@raise [Sass::SyntaxError] if `other` is a number with units
|
times
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def div(other)
if other.is_a?(Sass::Script::Value::Number) ||
other.is_a?(Sass::Script::Value::Color)
piecewise(other, :/)
else
super
end
end
|
The SassScript `/` operation.
Its functionality depends on the type of its argument:
{Number}
: Divides each of the RGB color channels by the number.
{Color}
: Divides each of this color's RGB color channels by the other color's.
{Value}
: See {Value::Base#div}.
@param other [Value] The right-hand side of the operator
@return [Color] The resulting color
@raise [Sass::SyntaxError] if `other` is a number with units
|
div
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def mod(other)
if other.is_a?(Sass::Script::Value::Number) ||
other.is_a?(Sass::Script::Value::Color)
piecewise(other, :%)
else
raise NoMethodError.new(nil, :mod)
end
end
|
The SassScript `%` operation.
Its functionality depends on the type of its argument:
{Number}
: Takes each of the RGB color channels module the number.
{Color}
: Takes each of this color's RGB color channels modulo the other color's.
@param other [Number, Color] The right-hand side of the operator
@return [Color] The resulting color
@raise [Sass::SyntaxError] if `other` is a number with units
|
mod
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def to_s(opts = {})
return smallest if options[:style] == :compressed
return representation if representation
# IE10 doesn't properly support the color name "transparent", so we emit
# generated transparent colors as rgba(0, 0, 0, 0) in favor of that. See
# #1782.
return rgba_str if Number.basically_equal?(alpha, 0)
return name if name
alpha? ? rgba_str : hex_str
end
|
Returns a string representation of the color.
This is usually the color's hex value,
but if the color has a name that's used instead.
@return [String] The string representation
|
to_s
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def inspect
alpha? ? rgba_str : hex_str
end
|
Returns a string representation of the color.
@return [String] The hex value
|
inspect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/color.rb
|
Apache-2.0
|
def initialize(function)
unless function.type == "function"
raise ArgumentError.new("A callable of type function was expected.")
end
super
end
|
Constructs a Function value for use in SassScript.
@param function [Sass::Callable] The callable to be used when the
function is invoked.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/function.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/function.rb
|
Apache-2.0
|
def hex_color(value, alpha = nil)
Color.from_hex(value, alpha)
end
|
Construct a Sass Color from a hex color string.
@param value [::String] A string representing a hex color.
The leading hash ("#") is optional.
@param alpha [::Number] The alpha channel. A number between 0 and 1.
@return [Sass::Script::Value::Color] the color object
|
hex_color
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def hsl_color(hue, saturation, lightness, alpha = nil)
attrs = {:hue => hue, :saturation => saturation, :lightness => lightness}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end
|
Construct a Sass Color from hsl values.
@param hue [::Number] The hue of the color in degrees.
A non-negative number, usually less than 360.
@param saturation [::Number] The saturation of the color.
Must be between 0 and 100 inclusive.
@param lightness [::Number] The lightness of the color.
Must be between 0 and 100 inclusive.
@param alpha [::Number] The alpha channel. A number between 0 and 1.
@return [Sass::Script::Value::Color] the color object
|
hsl_color
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def rgb_color(red, green, blue, alpha = nil)
attrs = {:red => red, :green => green, :blue => blue}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end
|
Construct a Sass Color from rgb values.
@param red [::Number] The red component. Must be between 0 and 255 inclusive.
@param green [::Number] The green component. Must be between 0 and 255 inclusive.
@param blue [::Number] The blue component. Must be between 0 and 255 inclusive.
@param alpha [::Number] The alpha channel. A number between 0 and 1.
@return [Sass::Script::Value::Color] the color object
|
rgb_color
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def number(number, unit_string = nil)
Number.new(number, *parse_unit_string(unit_string))
end
|
Construct a Sass Number from a ruby number.
@param number [::Number] A numeric value.
@param unit_string [::String] A unit string of the form
`numeral_unit1 * numeral_unit2 ... / denominator_unit1 * denominator_unit2 ...`
this is the same format that is returned by
{Sass::Script::Value::Number#unit_str the `unit_str` method}
@see Sass::Script::Value::Number#unit_str
@return [Sass::Script::Value::Number] The sass number representing the given ruby number.
|
number
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def list(*elements, separator: nil, bracketed: false)
# Support passing separator as the last value in elements for
# backwards-compatibility.
if separator.nil?
if elements.last.is_a?(Symbol)
separator = elements.pop
else
raise ArgumentError.new("A separator of :space or :comma must be specified.")
end
end
if elements.size == 1 && elements.first.is_a?(Array)
elements = elements.first
end
Sass::Script::Value::List.new(elements, separator: separator, bracketed: bracketed)
end
|
@overload list(*elements, separator:, bracketed: false)
Create a space-separated list from the arguments given.
@param elements [Array<Sass::Script::Value::Base>] Each argument will be a list element.
@param separator [Symbol] Either :space or :comma.
@param bracketed [Boolean] Whether the list uses square brackets.
@return [Sass::Script::Value::List] The space separated list.
@overload list(array, separator:, bracketed: false)
Create a space-separated list from the array given.
@param array [Array<Sass::Script::Value::Base>] A ruby array of Sass values
to make into a list.
@param separator [Symbol] Either :space or :comma.
@param bracketed [Boolean] Whether the list uses square brackets.
@return [Sass::Script::Value::List] The space separated list.
|
list
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def quoted_string(str)
Sass::Script::String.new(str, :string)
end
|
Create a quoted string.
@param str [::String] A ruby string.
@return [Sass::Script::Value::String] A quoted string.
|
quoted_string
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def unquoted_string(str)
Sass::Script::String.new(str, :identifier)
end
|
Create an unquoted string.
@param str [::String] A ruby string.
@return [Sass::Script::Value::String] An unquoted string.
|
unquoted_string
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def parse_selector(value, name = nil, allow_parent_ref = false)
str = normalize_selector(value, name)
begin
Sass::SCSS::StaticParser.new(str, nil, nil, 1, 1, allow_parent_ref).parse_selector
rescue Sass::SyntaxError => e
err = "#{value.inspect} is not a valid selector: #{e}"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end
end
|
Parses a user-provided selector.
@param value [Sass::Script::Value::String, Sass::Script::Value::List]
The selector to parse. This can be either a string, a list of
strings, or a list of lists of strings as returned by `&`.
@param name [Symbol, nil]
If provided, the name of the selector argument. This is used
for error reporting.
@param allow_parent_ref [Boolean]
Whether the parsed selector should allow parent references.
@return [Sass::Selector::CommaSequence] The parsed selector.
@throw [ArgumentError] if the parse failed for any reason.
|
parse_selector
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def parse_complex_selector(value, name = nil, allow_parent_ref = false)
selector = parse_selector(value, name, allow_parent_ref)
return seq if selector.members.length == 1
err = "#{value.inspect} is not a complex selector"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end
|
Parses a user-provided complex selector.
A complex selector can contain combinators but cannot contain commas.
@param value [Sass::Script::Value::String, Sass::Script::Value::List]
The selector to parse. This can be either a string or a list of
strings.
@param name [Symbol, nil]
If provided, the name of the selector argument. This is used
for error reporting.
@param allow_parent_ref [Boolean]
Whether the parsed selector should allow parent references.
@return [Sass::Selector::Sequence] The parsed selector.
@throw [ArgumentError] if the parse failed for any reason.
|
parse_complex_selector
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def parse_compound_selector(value, name = nil, allow_parent_ref = false)
assert_type value, :String, name
selector = parse_selector(value, name, allow_parent_ref)
seq = selector.members.first
sseq = seq.members.first
if selector.members.length == 1 && seq.members.length == 1 &&
sseq.is_a?(Sass::Selector::SimpleSequence)
return sseq
end
err = "#{value.inspect} is not a compound selector"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end
|
Parses a user-provided compound selector.
A compound selector cannot contain combinators or commas.
@param value [Sass::Script::Value::String] The selector to parse.
@param name [Symbol, nil]
If provided, the name of the selector argument. This is used
for error reporting.
@param allow_parent_ref [Boolean]
Whether the parsed selector should allow parent references.
@return [Sass::Selector::SimpleSequence] The parsed selector.
@throw [ArgumentError] if the parse failed for any reason.
|
parse_compound_selector
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def calc?(literal)
literal.is_a?(Sass::Script::Value::String) && literal.value =~ /calc\(/
end
|
Returns true when the literal is a string containing a calc().
Use \{#special_number?} in preference to this.
@param literal [Sass::Script::Value::Base] The value to check
@return Boolean
|
calc?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def var?(literal)
literal.is_a?(Sass::Script::Value::String) && literal.value =~ /var\(/
end
|
Returns true when the literal is a string containing a var().
@param literal [Sass::Script::Value::Base] The value to check
@return Boolean
|
var?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def special_number?(literal)
literal.is_a?(Sass::Script::Value::String) && literal.value =~ /(calc|var)\(/
end
|
Returns whether the literal is a special CSS value that may evaluate to a
number, such as `calc()` or `var()`.
@param literal [Sass::Script::Value::Base] The value to check
@return Boolean
|
special_number?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def normalize_selector(value, name)
if (str = selector_to_str(value))
return str
end
err = "#{value.inspect} is not a valid selector: it must be a string,\n" +
"a list of strings, or a list of lists of strings"
err = "$#{name.to_s.tr('_', '-')}: #{err}" if name
raise ArgumentError.new(err)
end
|
Converts a user-provided selector into string form or throws an
ArgumentError if it's in an invalid format.
|
normalize_selector
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def selector_to_str(value)
return value.value if value.is_a?(Sass::Script::String)
return unless value.is_a?(Sass::Script::List)
if value.separator == :comma
return value.to_a.map do |complex|
next complex.value if complex.is_a?(Sass::Script::String)
return unless complex.is_a?(Sass::Script::List) && complex.separator == :space
return unless (str = selector_to_str(complex))
str
end.join(', ')
end
value.to_a.map do |compound|
return unless compound.is_a?(Sass::Script::String)
compound.value
end.join(' ')
end
|
Converts a user-provided selector into string form or returns
`nil` if it's in an invalid format.
|
selector_to_str
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def parse_unit_string(unit_string)
denominator_units = numerator_units = Sass::Script::Value::Number::NO_UNITS
return numerator_units, denominator_units unless unit_string && unit_string.length > 0
num_over_denominator = unit_string.split(%r{ */ *})
unless (1..2).include?(num_over_denominator.size)
raise ArgumentError.new("Malformed unit string: #{unit_string}")
end
numerator_units = num_over_denominator[0].split(/ *\* */)
denominator_units = (num_over_denominator[1] || "").split(/ *\* */)
[[numerator_units, "numerator"], [denominator_units, "denominator"]].each do |units, name|
if unit_string =~ %r{/} && units.size == 0
raise ArgumentError.new("Malformed unit string: #{unit_string}")
end
if units.any? {|unit| unit !~ VALID_UNIT}
raise ArgumentError.new("Malformed #{name} in unit string: #{unit_string}")
end
end
[numerator_units, denominator_units]
end
|
@example
parse_unit_string("em*px/in*%") # => [["em", "px], ["in", "%"]]
@param unit_string [String] A string adhering to the output of a number with complex
units. E.g. "em*px/in*%"
@return [Array<Array<String>>] A list of numerator units and a list of denominator units.
|
parse_unit_string
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/helpers.rb
|
Apache-2.0
|
def initialize(value, separator: nil, bracketed: false)
super(value)
@separator = separator
@bracketed = bracketed
end
|
Creates a new list.
@param value [Array<Value>] See \{#value}
@param separator [Symbol] See \{#separator}
@param bracketed [Boolean] See \{#bracketed}
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/list.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/list.rb
|
Apache-2.0
|
def initialize(value, numerator_units = NO_UNITS, denominator_units = NO_UNITS)
numerator_units = [numerator_units] if numerator_units.is_a?(::String)
denominator_units = [denominator_units] if denominator_units.is_a?(::String)
super(value)
@numerator_units = numerator_units
@denominator_units = denominator_units
@options = nil
normalize!
end
|
@param value [Numeric] The value of the number
@param numerator_units [::String, Array<::String>] See \{#numerator\_units}
@param denominator_units [::String, Array<::String>] See \{#denominator\_units}
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def plus(other)
if other.is_a? Number
operate(other, :+)
elsif other.is_a?(Color)
other.plus(self)
else
super
end
end
|
The SassScript `+` operation.
Its functionality depends on the type of its argument:
{Number}
: Adds the two numbers together, converting units if possible.
{Color}
: Adds this number to each of the RGB color channels.
{Value}
: See {Value::Base#plus}.
@param other [Value] The right-hand side of the operator
@return [Value] The result of the operation
@raise [Sass::UnitConversionError] if `other` is a number with incompatible units
|
plus
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def minus(other)
if other.is_a? Number
operate(other, :-)
else
super
end
end
|
The SassScript binary `-` operation (e.g. `$a - $b`).
Its functionality depends on the type of its argument:
{Number}
: Subtracts this number from the other, converting units if possible.
{Value}
: See {Value::Base#minus}.
@param other [Value] The right-hand side of the operator
@return [Value] The result of the operation
@raise [Sass::UnitConversionError] if `other` is a number with incompatible units
|
minus
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def unary_minus
Number.new(-value, @numerator_units, @denominator_units)
end
|
The SassScript unary `-` operation (e.g. `-$a`).
@return [Number] The negative value of this number
|
unary_minus
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def times(other)
if other.is_a? Number
operate(other, :*)
elsif other.is_a? Color
other.times(self)
else
raise NoMethodError.new(nil, :times)
end
end
|
The SassScript `*` operation.
Its functionality depends on the type of its argument:
{Number}
: Multiplies the two numbers together, converting units appropriately.
{Color}
: Multiplies each of the RGB color channels by this number.
@param other [Number, Color] The right-hand side of the operator
@return [Number, Color] The result of the operation
@raise [NoMethodError] if `other` is an invalid type
|
times
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def div(other)
if other.is_a? Number
res = operate(other, :/)
if original && other.original
res.original = "#{original}/#{other.original}"
end
res
else
super
end
end
|
The SassScript `/` operation.
Its functionality depends on the type of its argument:
{Number}
: Divides this number by the other, converting units appropriately.
{Value}
: See {Value::Base#div}.
@param other [Value] The right-hand side of the operator
@return [Value] The result of the operation
|
div
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def mod(other)
if other.is_a?(Number)
return Number.new(Float::NAN) if other.value == 0
operate(other, :%)
else
raise NoMethodError.new(nil, :mod)
end
end
|
The SassScript `%` operation.
@param other [Number] The right-hand side of the operator
@return [Number] This number modulo the other
@raise [NoMethodError] if `other` is an invalid type
@raise [Sass::UnitConversionError] if `other` has incompatible units
|
mod
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def eq(other)
return Bool::FALSE unless other.is_a?(Sass::Script::Value::Number)
this = self
begin
if unitless?
this = this.coerce(other.numerator_units, other.denominator_units)
else
other = other.coerce(@numerator_units, @denominator_units)
end
rescue Sass::UnitConversionError
return Bool::FALSE
end
Bool.new(basically_equal?(this.value, other.value))
end
|
The SassScript `==` operation.
@param other [Value] The right-hand side of the operator
@return [Boolean] Whether this number is equal to the other object
|
eq
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def eql?(other)
basically_equal?(value, other.value) && numerator_units == other.numerator_units &&
denominator_units == other.denominator_units
end
|
Hash-equality works differently than `==` equality for numbers.
Hash-equality must be transitive, so it just compares the exact value,
numerator units, and denominator units.
|
eql?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def gt(other)
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
operate(other, :>)
end
|
The SassScript `>` operation.
@param other [Number] The right-hand side of the operator
@return [Boolean] Whether this number is greater than the other
@raise [NoMethodError] if `other` is an invalid type
|
gt
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def gte(other)
raise NoMethodError.new(nil, :gte) unless other.is_a?(Number)
operate(other, :>=)
end
|
The SassScript `>=` operation.
@param other [Number] The right-hand side of the operator
@return [Boolean] Whether this number is greater than or equal to the other
@raise [NoMethodError] if `other` is an invalid type
|
gte
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def lt(other)
raise NoMethodError.new(nil, :lt) unless other.is_a?(Number)
operate(other, :<)
end
|
The SassScript `<` operation.
@param other [Number] The right-hand side of the operator
@return [Boolean] Whether this number is less than the other
@raise [NoMethodError] if `other` is an invalid type
|
lt
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def lte(other)
raise NoMethodError.new(nil, :lte) unless other.is_a?(Number)
operate(other, :<=)
end
|
The SassScript `<=` operation.
@param other [Number] The right-hand side of the operator
@return [Boolean] Whether this number is less than or equal to the other
@raise [NoMethodError] if `other` is an invalid type
|
lte
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def to_s(opts = {})
return original if original
raise Sass::SyntaxError.new("#{inspect} isn't a valid CSS value.") unless legal_units?
inspect
end
|
@return [String] The CSS representation of this number
@raise [Sass::SyntaxError] if this number has units that can't be used in CSS
(e.g. `px*in`)
|
to_s
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def inspect(opts = {})
return original if original
value = self.class.round(self.value)
str = value.to_s
# Ruby will occasionally print in scientific notation if the number is
# small enough. That's technically valid CSS, but it's not well-supported
# and confusing.
str = ("%0.#{self.class.precision}f" % value).gsub(/0*$/, '') if str.include?('e')
# Sometimes numeric formatting will result in a decimal number with a trailing zero (x.0)
if str =~ /(.*)\.0$/
str = $1
end
# We omit a leading zero before the decimal point in compressed mode.
if @options && options[:style] == :compressed
str.sub!(/^(-)?0\./, '\1.')
end
unitless? ? str : "#{str}#{unit_str}"
end
|
Returns a readable representation of this number.
This representation is valid CSS (and valid SassScript)
as long as there is only one unit.
@return [String] The representation
|
inspect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def to_i
super unless int?
value.to_i
end
|
@return [Integer] The integer value of the number
@raise [Sass::SyntaxError] if the number isn't an integer
|
to_i
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def int?
basically_equal?(value % 1, 0.0)
end
|
@return [Boolean] Whether or not this number is an integer.
|
int?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def unitless?
@numerator_units.empty? && @denominator_units.empty?
end
|
@return [Boolean] Whether or not this number has no units.
|
unitless?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def is_unit?(unit)
if unit
denominator_units.size == 0 && numerator_units.size == 1 && numerator_units.first == unit
else
unitless?
end
end
|
Checks whether the number has the numerator unit specified.
@example
number = Sass::Script::Value::Number.new(10, "px")
number.is_unit?("px") => true
number.is_unit?(nil) => false
@param unit [::String, nil] The unit the number should have or nil if the number
should be unitless.
@see Number#unitless? The unitless? method may be more readable.
|
is_unit?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def legal_units?
(@numerator_units.empty? || @numerator_units.size == 1) && @denominator_units.empty?
end
|
@return [Boolean] Whether or not this number has units that can be represented in CSS
(that is, zero or one \{#numerator\_units}).
|
legal_units?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def coerce(num_units, den_units)
Number.new(if unitless?
value
else
value * coercion_factor(@numerator_units, num_units) /
coercion_factor(@denominator_units, den_units)
end, num_units, den_units)
end
|
Returns this number converted to other units.
The conversion takes into account the relationship between e.g. mm and cm,
as well as between e.g. in and cm.
If this number has no units, it will simply return itself
with the given units.
An incompatible coercion, e.g. between px and cm, will raise an error.
@param num_units [Array<String>] The numerator units to coerce this number into.
See {\#numerator\_units}
@param den_units [Array<String>] The denominator units to coerce this number into.
See {\#denominator\_units}
@return [Number] The number with the new units
@raise [Sass::UnitConversionError] if the given units are incompatible with the number's
current units
|
coerce
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def comparable_to?(other)
operate(other, :+)
true
rescue Sass::UnitConversionError
false
end
|
@param other [Number] A number to decide if it can be compared with this number.
@return [Boolean] Whether or not this number can be compared with the other.
|
comparable_to?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def unit_str
rv = @numerator_units.sort.join("*")
if @denominator_units.any?
rv << "/"
rv << @denominator_units.sort.join("*")
end
rv
end
|
Returns a human readable representation of the units in this number.
For complex units this takes the form of:
numerator_unit1 * numerator_unit2 / denominator_unit1 * denominator_unit2
@return [String] a string that represents the units in this number
|
unit_str
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/script/value/number.rb
|
Apache-2.0
|
def initialize(str, filename, importer, line = 1, offset = 1)
@template = str
@filename = filename
@importer = importer
@line = line
@offset = offset
@strs = []
@expected = nil
@throw_error = false
end
|
@param str [String, StringScanner] The source document to parse.
Note that `Parser` *won't* raise a nice error message if this isn't properly parsed;
for that, you should use the higher-level {Sass::Engine} or {Sass::CSS}.
@param filename [String] The name of the file being parsed. Used for
warnings and source maps.
@param importer [Sass::Importers::Base] The importer used to import the
file being parsed. Used for source maps.
@param line [Integer] The 1-based line on which the source string appeared,
if it's part of another document.
@param offset [Integer] The 1-based character (not byte) offset in the line on
which the source string starts. Used for error reporting and sourcemap
building.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse
init_scanner!
root = stylesheet
expected("selector or at-rule") unless root && @scanner.eos?
root
end
|
Parses an SCSS document.
@return [Sass::Tree::RootNode] The root node of the document tree
@raise [Sass::SyntaxError] if there's a syntax error in the document
|
parse
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_interp_ident
init_scanner!
interp_ident
end
|
Parses an identifier with interpolation.
Note that this won't assert that the identifier takes up the entire input string;
it's meant to be used with `StringScanner`s as part of other parsers.
@return [Array<String, Sass::Script::Tree::Node>, nil]
The interpolated identifier, or nil if none could be parsed
|
parse_interp_ident
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_supports_clause
init_scanner!
ss
clause = supports_clause
ss
clause
end
|
Parses a supports clause for an @import directive
|
parse_supports_clause
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_media_query_list
init_scanner!
ql = media_query_list
expected("media query list") unless ql && @scanner.eos?
ql
end
|
Parses a media query list.
@return [Sass::Media::QueryList] The parsed query list
@raise [Sass::SyntaxError] if there's a syntax error in the query list,
or if it doesn't take up the entire input string.
|
parse_media_query_list
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_at_root_query
init_scanner!
query = at_root_query
expected("@at-root query list") unless query && @scanner.eos?
query
end
|
Parses an at-root query.
@return [Array<String, Sass::Script;:Tree::Node>] The interpolated query.
@raise [Sass::SyntaxError] if there's a syntax error in the query,
or if it doesn't take up the entire input string.
|
parse_at_root_query
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_supports_condition
init_scanner!
condition = supports_condition
expected("supports condition") unless condition && @scanner.eos?
condition
end
|
Parses a supports query condition.
@return [Sass::Supports::Condition] The parsed condition
@raise [Sass::SyntaxError] if there's a syntax error in the condition,
or if it doesn't take up the entire input string.
|
parse_supports_condition
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_declaration_value
init_scanner!
value = declaration_value
expected('"}"') unless value && @scanner.eos?
value
end
|
Parses a custom property value.
@return [Array<String, Sass::Script;:Tree::Node>] The interpolated value.
@raise [Sass::SyntaxError] if there's a syntax error in the value,
or if it doesn't take up the entire input string.
|
parse_declaration_value
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def media_query_list
query = media_query
return unless query
queries = [query]
ss
while tok(/,/)
ss; queries << expr!(:media_query)
end
ss
Sass::Media::QueryList.new(queries)
end
|
http://www.w3.org/TR/css3-mediaqueries/#syntax
|
media_query_list
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def block_contents(node, context)
block_given? ? yield : ss_comments(node)
node << (child = block_child(context))
while tok(/;/) || has_children?(child)
block_given? ? yield : ss_comments(node)
node << (child = block_child(context))
end
node
end
|
A block may contain declarations and/or rulesets
|
block_contents
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def declaration_or_ruleset
start_pos = source_position
declaration = try_declaration
if declaration.nil?
return unless (selector = almost_any_value)
elsif declaration.is_a?(Array)
selector = declaration
else
# Declaration should be a PropNode.
return declaration
end
if (additional_selector = almost_any_value)
selector << additional_selector
end
block(
node(
Sass::Tree::RuleNode.new(merge(selector), range(start_pos)), start_pos), :ruleset)
end
|
When parsing the contents of a ruleset, it can be difficult to tell
declarations apart from nested rulesets. Since we don't thoroughly parse
selectors until after resolving interpolation, we can share a bunch of
the parsing of the two, but we need to disambiguate them first. We use
the following criteria:
* If the entity doesn't start with an identifier followed by a colon,
it's a selector. There are some additional mostly-unimportant cases
here to support various declaration hacks.
* If the colon is followed by another colon, it's a selector.
* Otherwise, if the colon is followed by anything other than
interpolation or a character that's valid as the beginning of an
identifier, it's a declaration.
* If the colon is followed by interpolation or a valid identifier, try
parsing it as a declaration value. If this fails, backtrack and parse
it as a selector.
* If the declaration value value valid but is followed by "{", backtrack
and parse it as a selector anyway. This ensures that ".foo:bar {" is
always parsed as a selector and never as a property with nested
properties beneath it.
|
declaration_or_ruleset
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def try_declaration
# This allows the "*prop: val", ":prop: val", "#prop: val", and ".prop:
# val" hacks.
name_start_pos = source_position
if (s = tok(/[:\*\.]|\#(?!\{)/))
name = [s, str {ss}]
return name unless (ident = interp_ident)
name << ident
else
return unless (name = interp_ident)
name = Array(name)
end
if (comment = tok(COMMENT))
name << comment
end
name_end_pos = source_position
mid = [str {ss}]
return name + mid unless tok(/:/)
mid << ':'
# If this is a CSS variable, parse it as a property no matter what.
if name.first.is_a?(String) && name.first.start_with?("--")
return css_variable_declaration(name, name_start_pos, name_end_pos)
end
return name + mid + [':'] if tok(/:/)
mid << str {ss}
post_colon_whitespace = !mid.last.empty?
could_be_selector = !post_colon_whitespace && (tok?(IDENT_START) || tok?(INTERP_START))
value_start_pos = source_position
value = nil
error = catch_error do
value = value!
if tok?(/\{/)
# Properties that are ambiguous with selectors can't have additional
# properties nested beneath them.
tok!(/;/) if could_be_selector
elsif !tok?(/[;{}]/)
# We want an exception if there's no valid end-of-property character
# exists, but we don't want to consume it if it does.
tok!(/[;{}]/)
end
end
if error
rethrow error unless could_be_selector
# If the value would be followed by a semicolon, it's definitely
# supposed to be a property, not a selector.
additional_selector = almost_any_value
rethrow error if tok?(/;/)
return name + mid + (additional_selector || [])
end
value_end_pos = source_position
ss
require_block = tok?(/\{/)
node = node(Sass::Tree::PropNode.new(name.flatten.compact, [value], :new),
name_start_pos, value_end_pos)
node.name_source_range = range(name_start_pos, name_end_pos)
node.value_source_range = range(value_start_pos, value_end_pos)
return node unless require_block
nested_properties! node
end
|
Tries to parse a declaration, and returns the value parsed so far if it
fails.
This has three possible return types. It can return `nil`, indicating
that parsing failed completely and the scanner hasn't moved forward at
all. It can return an Array, indicating that parsing failed after
consuming some text (possibly containing interpolation), which is
returned. Or it can return a PropNode, indicating that parsing
succeeded.
|
try_declaration
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def almost_any_value
return unless (tok = almost_any_value_token)
sel = [tok]
while (tok = almost_any_value_token)
sel << tok
end
merge(sel)
end
|
This production consumes values that could be a selector, an expression,
or a combination of both. It respects strings and comments and supports
interpolation. It will consume up to "{", "}", ";", or "!".
Values consumed by this production will usually be parsed more
thoroughly once interpolation has been resolved.
|
almost_any_value
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/parser.rb
|
Apache-2.0
|
def parse_selector
init_scanner!
seq = expr!(:selector_comma_sequence)
expected("selector") unless @scanner.eos?
seq.line = @line
seq.filename = @filename
seq
end
|
Parses the text as a selector.
@param filename [String, nil] The file in which the selector appears,
or nil if there is no such file.
Used for error reporting.
@return [Selector::CommaSequence] The parsed selector
@raise [Sass::SyntaxError] if there's a syntax error in the selector
|
parse_selector
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/static_parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/static_parser.rb
|
Apache-2.0
|
def parse_static_at_root_query
init_scanner!
tok!(/\(/); ss
type = tok!(/\b(without|with)\b/).to_sym; ss
tok!(/:/); ss
directives = expr!(:at_root_directive_list); ss
tok!(/\)/)
expected("@at-root query list") unless @scanner.eos?
return type, directives
end
|
Parses a static at-root query.
@return [(Symbol, Array<String>)] The type of the query
(`:with` or `:without`) and the values that are being filtered.
@raise [Sass::SyntaxError] if there's a syntax error in the query,
or if it doesn't take up the entire input string.
|
parse_static_at_root_query
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/static_parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/static_parser.rb
|
Apache-2.0
|
def initialize(str, filename, importer, line = 1, offset = 1, allow_parent_ref = true)
super(str, filename, importer, line, offset)
@allow_parent_ref = allow_parent_ref
end
|
@see Parser#initialize
@param allow_parent_ref [Boolean] Whether to allow the
parent-reference selector, `&`, when parsing the document.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/static_parser.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/scss/static_parser.rb
|
Apache-2.0
|
def hash
@_hash ||= _hash
end
|
Returns a hash code for this sequence.
Subclasses should define `#_hash` rather than overriding this method,
which automatically handles memoizing the result.
@return [Integer]
|
hash
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/abstract_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/abstract_sequence.rb
|
Apache-2.0
|
def eql?(other)
other.class == self.class && other.hash == hash && _eql?(other)
end
|
Checks equality between this and another object.
Subclasses should define `#_eql?` rather than overriding this method,
which handles checking class equality and hash equality.
@param other [Object] The object to test equality against
@return [Boolean] Whether or not this is equal to `other`
|
eql?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/abstract_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/abstract_sequence.rb
|
Apache-2.0
|
def invisible?
@invisible ||= members.any? do |m|
next m.invisible? if m.is_a?(AbstractSequence) || m.is_a?(Pseudo)
m.is_a?(Placeholder)
end
end
|
Whether or not this selector should be hidden due to containing a
placeholder.
|
invisible?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/abstract_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/abstract_sequence.rb
|
Apache-2.0
|
def initialize(seqs)
@members = seqs
end
|
@param seqs [Array<Sequence>] See \{#members}
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def resolve_parent_refs(super_cseq, implicit_parent = true)
if super_cseq.nil?
if contains_parent_ref?
raise Sass::SyntaxError.new(
"Base-level rules cannot contain the parent-selector-referencing character '&'.")
end
return self
end
CommaSequence.new(Sass::Util.flatten_vertically(@members.map do |seq|
seq.resolve_parent_refs(super_cseq, implicit_parent).members
end))
end
|
Resolves the {Parent} selectors within this selector
by replacing them with the given parent selector,
handling commas appropriately.
@param super_cseq [CommaSequence] The parent selector
@param implicit_parent [Boolean] Whether the the parent
selector should automatically be prepended to the resolved
selector if it contains no parent refs.
@return [CommaSequence] This selector, with parent references resolved
@raise [Sass::SyntaxError] If a parent selector is invalid
|
resolve_parent_refs
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def contains_parent_ref?
@members.any? {|sel| sel.contains_parent_ref?}
end
|
Returns whether there's a {Parent} selector anywhere in this sequence.
@return [Boolean]
|
contains_parent_ref?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def do_extend(extends, parent_directives = [], replace = false, seen = Set.new,
original = true)
CommaSequence.new(members.map do |seq|
seq.do_extend(extends, parent_directives, replace, seen, original)
end.flatten)
end
|
Non-destrucively extends this selector with the extensions specified in a hash
(which should come from {Sass::Tree::Visitors::Cssize}).
@todo Link this to the reference documentation on `@extend`
when such a thing exists.
@param extends [Sass::Util::SubsetMap{Selector::Simple =>
Sass::Tree::Visitors::Cssize::Extend}]
The extensions to perform on this selector
@param parent_directives [Array<Sass::Tree::DirectiveNode>]
The directives containing this selector.
@param replace [Boolean]
Whether to replace the original selector entirely or include
it in the result.
@param seen [Set<Array<Selector::Simple>>]
The set of simple sequences that are currently being replaced.
@param original [Boolean]
Whether this is the original selector being extended, as opposed to
the result of a previous extension that's being re-extended.
@return [CommaSequence] A copy of this selector,
with extensions made according to `extends`
|
do_extend
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def superselector?(cseq)
cseq.members.all? {|seq1| members.any? {|seq2| seq2.superselector?(seq1)}}
end
|
Returns whether or not this selector matches all elements
that the given selector matches (as well as possibly more).
@example
(.foo).superselector?(.foo.bar) #=> true
(.foo).superselector?(.bar) #=> false
@param cseq [CommaSequence]
@return [Boolean]
|
superselector?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def populate_extends(extends, extendee, extend_node = nil, parent_directives = [],
allow_compound_target = false)
extendee.members.each do |seq|
if seq.members.size > 1
raise Sass::SyntaxError.new("Can't extend #{seq}: can't extend nested selectors")
end
sseq = seq.members.first
if !sseq.is_a?(Sass::Selector::SimpleSequence)
raise Sass::SyntaxError.new("Can't extend #{seq}: invalid selector")
elsif sseq.members.any? {|ss| ss.is_a?(Sass::Selector::Parent)}
raise Sass::SyntaxError.new("Can't extend #{seq}: can't extend parent selectors")
end
sel = sseq.members
if !allow_compound_target && sel.length > 1
@@compound_extend_deprecation.warn(sseq.filename, sseq.line, <<WARNING)
Extending a compound selector, #{sseq}, is deprecated and will not be supported in a future release.
Consider "@extend #{sseq.members.join(', ')}" instead.
See http://bit.ly/ExtendCompound for details.
WARNING
end
members.each do |member|
unless member.members.last.is_a?(Sass::Selector::SimpleSequence)
raise Sass::SyntaxError.new("#{member} can't extend: invalid selector")
end
extends[sel] = Sass::Tree::Visitors::Cssize::Extend.new(
member, sel, extend_node, parent_directives, false)
end
end
end
|
Populates a subset map that can then be used to extend
selectors. This registers an extension with this selector as
the extender and `extendee` as the extendee.
@param extends [Sass::Util::SubsetMap{Selector::Simple =>
Sass::Tree::Visitors::Cssize::Extend}]
The subset map representing the extensions to perform.
@param extendee [CommaSequence] The selector being extended.
@param extend_node [Sass::Tree::ExtendNode]
The node that caused this extension.
@param parent_directives [Array<Sass::Tree::DirectiveNode>]
The parent directives containing `extend_node`.
@param allow_compound_target [Boolean]
Whether `extendee` is allowed to contain compound selectors.
@raise [Sass::SyntaxError] if this extension is invalid.
|
populate_extends
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def unify(other)
results = members.map {|seq1| other.members.map {|seq2| seq1.unify(seq2)}}.flatten.compact
results.empty? ? nil : CommaSequence.new(results.map {|cseq| cseq.members}.flatten)
end
|
Unifies this with another comma selector to produce a selector
that matches (a subset of) the intersection of the two inputs.
@param other [CommaSequence]
@return [CommaSequence, nil] The unified selector, or nil if unification failed.
@raise [Sass::SyntaxError] If this selector cannot be unified.
This will only ever occur when a dynamic selector,
such as {Parent} or {Interpolation}, is used in unification.
Since these selectors should be resolved
by the time extension and unification happen,
this exception will only ever be raised as a result of programmer error
|
unify
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def to_sass_script
Sass::Script::Value::List.new(members.map do |seq|
Sass::Script::Value::List.new(seq.members.map do |component|
next if component == "\n"
Sass::Script::Value::String.new(component.to_s)
end.compact, separator: :space)
end, separator: :comma)
end
|
Returns a SassScript representation of this selector.
@return [Sass::Script::Value::List]
|
to_sass_script
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def inspect
members.map {|m| m.inspect}.join(", ")
end
|
Returns a string representation of the sequence.
This is basically the selector string.
@return [String]
|
inspect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/comma_sequence.rb
|
Apache-2.0
|
def initialize(syntactic_type, name, arg, selector)
@syntactic_type = syntactic_type
@name = name
@arg = arg
@selector = selector
end
|
@param syntactic_type [Symbol] See \{#syntactic_type}
@param name [String] See \{#name}
@param arg [nil, String] See \{#arg}
@param selector [nil, CommaSequence] See \{#selector}
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/pseudo.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/pseudo.rb
|
Apache-2.0
|
def initialize(seqs_and_ops)
@members = seqs_and_ops
end
|
@param seqs_and_ops [Array<SimpleSequence, String|Array<Sass::Tree::Node, String>>]
See \{#members}
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def resolve_parent_refs(super_cseq, implicit_parent)
members = @members.dup
nl = (members.first == "\n" && members.shift)
contains_parent_ref = contains_parent_ref?
return CommaSequence.new([self]) if !implicit_parent && !contains_parent_ref
unless contains_parent_ref
old_members, members = members, []
members << nl if nl
members << SimpleSequence.new([Parent.new], false)
members += old_members
end
CommaSequence.new(Sass::Util.paths(members.map do |sseq_or_op|
next [sseq_or_op] unless sseq_or_op.is_a?(SimpleSequence)
sseq_or_op.resolve_parent_refs(super_cseq).members
end).map do |path|
path_members = path.map do |seq_or_op|
next seq_or_op unless seq_or_op.is_a?(Sequence)
seq_or_op.members
end
if path_members.length == 2 && path_members[1][0] == "\n"
path_members[0].unshift path_members[1].shift
end
Sequence.new(path_members.flatten)
end)
end
|
Resolves the {Parent} selectors within this selector
by replacing them with the given parent selector,
handling commas appropriately.
@param super_cseq [CommaSequence] The parent selector
@param implicit_parent [Boolean] Whether the the parent
selector should automatically be prepended to the resolved
selector if it contains no parent refs.
@return [CommaSequence] This selector, with parent references resolved
@raise [Sass::SyntaxError] If a parent selector is invalid
|
resolve_parent_refs
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def contains_parent_ref?
members.any? do |sseq_or_op|
next false unless sseq_or_op.is_a?(SimpleSequence)
next true if sseq_or_op.members.first.is_a?(Parent)
sseq_or_op.members.any? do |sel|
sel.is_a?(Pseudo) && sel.selector && sel.selector.contains_parent_ref?
end
end
end
|
Returns whether there's a {Parent} selector anywhere in this sequence.
@return [Boolean]
|
contains_parent_ref?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def do_extend(extends, parent_directives, replace, seen, original)
extended_not_expanded = members.map do |sseq_or_op|
next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
extended = sseq_or_op.do_extend(extends, parent_directives, replace, seen)
# The First Law of Extend says that the generated selector should have
# specificity greater than or equal to that of the original selector.
# In order to ensure that, we record the original selector's
# (`extended.first`) original specificity.
extended.first.add_sources!([self]) if original && !invisible?
extended.map {|seq| seq.members}
end
weaves = Sass::Util.paths(extended_not_expanded).map {|path| weave(path)}
trim(weaves).map {|p| Sequence.new(p)}
end
|
Non-destructively extends this selector with the extensions specified in a hash
(which should come from {Sass::Tree::Visitors::Cssize}).
@param extends [Sass::Util::SubsetMap{Selector::Simple =>
Sass::Tree::Visitors::Cssize::Extend}]
The extensions to perform on this selector
@param parent_directives [Array<Sass::Tree::DirectiveNode>]
The directives containing this selector.
@param replace [Boolean]
Whether to replace the original selector entirely or include
it in the result.
@param seen [Set<Array<Selector::Simple>>]
The set of simple sequences that are currently being replaced.
@param original [Boolean]
Whether this is the original selector being extended, as opposed to
the result of a previous extension that's being re-extended.
@return [Array<Sequence>] A list of selectors generated
by extending this selector with `extends`.
These correspond to a {CommaSequence}'s {CommaSequence#members members array}.
@see CommaSequence#do_extend
|
do_extend
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def unify(other)
base = members.last
other_base = other.members.last
return unless base.is_a?(SimpleSequence) && other_base.is_a?(SimpleSequence)
return unless (unified = other_base.unify(base))
woven = weave([members[0...-1], other.members[0...-1] + [unified]])
CommaSequence.new(woven.map {|w| Sequence.new(w)})
end
|
Unifies this with another selector sequence to produce a selector
that matches (a subset of) the intersection of the two inputs.
@param other [Sequence]
@return [CommaSequence, nil] The unified selector, or nil if unification failed.
@raise [Sass::SyntaxError] If this selector cannot be unified.
This will only ever occur when a dynamic selector,
such as {Parent} or {Interpolation}, is used in unification.
Since these selectors should be resolved
by the time extension and unification happen,
this exception will only ever be raised as a result of programmer error
|
unify
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def superselector?(seq)
_superselector?(members, seq.members)
end
|
Returns whether or not this selector matches all elements
that the given selector matches (as well as possibly more).
@example
(.foo).superselector?(.foo.bar) #=> true
(.foo).superselector?(.bar) #=> false
@param cseq [Sequence]
@return [Boolean]
|
superselector?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def inspect
members.map {|m| m.inspect}.join(" ")
end
|
Returns a string representation of the sequence.
This is basically the selector string.
@return [String]
|
inspect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def add_sources!(sources)
members.map! {|m| m.is_a?(SimpleSequence) ? m.with_more_sources(sources) : m}
end
|
Add to the {SimpleSequence#sources} sets of the child simple sequences.
This destructively modifies this sequence's members array, but not the
child simple sequences.
@param sources [Set<Sequence>]
|
add_sources!
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def subjectless
pre_subject = []
has = []
subject = nil
members.each do |sseq_or_op|
if subject
has << sseq_or_op
elsif sseq_or_op.is_a?(String) || !sseq_or_op.subject?
pre_subject << sseq_or_op
else
subject = sseq_or_op.dup
subject.members = sseq_or_op.members.dup
subject.subject = false
has = []
end
end
return self unless subject
unless has.empty?
subject.members << Pseudo.new(:class, 'has', nil, CommaSequence.new([Sequence.new(has)]))
end
Sequence.new(pre_subject + [subject])
end
|
Converts the subject operator "!", if it exists, into a ":has()"
selector.
@retur [Sequence]
|
subjectless
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def weave(path)
# This function works by moving through the selector path left-to-right,
# building all possible prefixes simultaneously.
prefixes = [[]]
path.each do |current|
next if current.empty?
current = current.dup
last_current = [current.pop]
prefixes = prefixes.map do |prefix|
sub = subweave(prefix, current)
next [] unless sub
sub.map {|seqs| seqs + last_current}
end.flatten(1)
end
prefixes
end
|
Conceptually, this expands "parenthesized selectors". That is, if we
have `.A .B {@extend .C}` and `.D .C {...}`, this conceptually expands
into `.D .C, .D (.A .B)`, and this function translates `.D (.A .B)` into
`.D .A .B, .A .D .B`. For thoroughness, `.A.D .B` would also be
required, but including merged selectors results in exponential output
for very little gain.
@param path [Array<Array<SimpleSequence or String>>]
A list of parenthesized selector groups.
@return [Array<Array<SimpleSequence or String>>] A list of fully-expanded selectors.
|
weave
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def subweave(seq1, seq2)
return [seq2] if seq1.empty?
return [seq1] if seq2.empty?
seq1, seq2 = seq1.dup, seq2.dup
return unless (init = merge_initial_ops(seq1, seq2))
return unless (fin = merge_final_ops(seq1, seq2))
# Make sure there's only one root selector in the output.
root1 = has_root?(seq1.first) && seq1.shift
root2 = has_root?(seq2.first) && seq2.shift
if root1 && root2
return unless (root = root1.unify(root2))
seq1.unshift root
seq2.unshift root
elsif root1
seq2.unshift root1
elsif root2
seq1.unshift root2
end
seq1 = group_selectors(seq1)
seq2 = group_selectors(seq2)
lcs = Sass::Util.lcs(seq2, seq1) do |s1, s2|
next s1 if s1 == s2
next unless s1.first.is_a?(SimpleSequence) && s2.first.is_a?(SimpleSequence)
next s2 if parent_superselector?(s1, s2)
next s1 if parent_superselector?(s2, s1)
next unless must_unify?(s1, s2)
next unless (unified = Sequence.new(s1).unify(Sequence.new(s2)))
unified.members.first.members if unified.members.length == 1
end
diff = [[init]]
until lcs.empty?
diff << chunks(seq1, seq2) {|s| parent_superselector?(s.first, lcs.first)} << [lcs.shift]
seq1.shift
seq2.shift
end
diff << chunks(seq1, seq2) {|s| s.empty?}
diff += fin.map {|sel| sel.is_a?(Array) ? sel : [sel]}
diff.reject! {|c| c.empty?}
Sass::Util.paths(diff).map {|p| p.flatten}.reject {|p| path_has_two_subjects?(p)}
end
|
This interweaves two lists of selectors,
returning all possible orderings of them (including using unification)
that maintain the relative ordering of the input arrays.
For example, given `.foo .bar` and `.baz .bang`,
this would return `.foo .bar .baz .bang`, `.foo .bar.baz .bang`,
`.foo .baz .bar .bang`, `.foo .baz .bar.bang`, `.foo .baz .bang .bar`,
and so on until `.baz .bang .foo .bar`.
Semantically, for selectors A and B, this returns all selectors `AB_i`
such that the union over all i of elements matched by `AB_i X` is
identical to the intersection of all elements matched by `A X` and all
elements matched by `B X`. Some `AB_i` are elided to reduce the size of
the output.
@param seq1 [Array<SimpleSequence or String>]
@param seq2 [Array<SimpleSequence or String>]
@return [Array<Array<SimpleSequence or String>>]
|
subweave
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def merge_initial_ops(seq1, seq2)
ops1, ops2 = [], []
ops1 << seq1.shift while seq1.first.is_a?(String)
ops2 << seq2.shift while seq2.first.is_a?(String)
newline = false
newline ||= !!ops1.shift if ops1.first == "\n"
newline ||= !!ops2.shift if ops2.first == "\n"
# If neither sequence is a subsequence of the other, they cannot be
# merged successfully
lcs = Sass::Util.lcs(ops1, ops2)
return unless lcs == ops1 || lcs == ops2
(newline ? ["\n"] : []) + (ops1.size > ops2.size ? ops1 : ops2)
end
|
Extracts initial selector combinators (`"+"`, `">"`, `"~"`, and `"\n"`)
from two sequences and merges them together into a single array of
selector combinators.
@param seq1 [Array<SimpleSequence or String>]
@param seq2 [Array<SimpleSequence or String>]
@return [Array<String>, nil] If there are no operators in the merged
sequence, this will be the empty array. If the operators cannot be
merged, this will be nil.
|
merge_initial_ops
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
def merge_final_ops(seq1, seq2, res = [])
ops1, ops2 = [], []
ops1 << seq1.pop while seq1.last.is_a?(String)
ops2 << seq2.pop while seq2.last.is_a?(String)
# Not worth the headache of trying to preserve newlines here. The most
# important use of newlines is at the beginning of the selector to wrap
# across lines anyway.
ops1.reject! {|o| o == "\n"}
ops2.reject! {|o| o == "\n"}
return res if ops1.empty? && ops2.empty?
if ops1.size > 1 || ops2.size > 1
# If there are multiple operators, something hacky's going on. If one
# is a supersequence of the other, use that, otherwise give up.
lcs = Sass::Util.lcs(ops1, ops2)
return unless lcs == ops1 || lcs == ops2
res.unshift(*(ops1.size > ops2.size ? ops1 : ops2).reverse)
return res
end
# This code looks complicated, but it's actually just a bunch of special
# cases for interactions between different combinators.
op1, op2 = ops1.first, ops2.first
if op1 && op2
sel1 = seq1.pop
sel2 = seq2.pop
if op1 == '~' && op2 == '~'
if sel1.superselector?(sel2)
res.unshift sel2, '~'
elsif sel2.superselector?(sel1)
res.unshift sel1, '~'
else
merged = sel1.unify(sel2)
res.unshift [
[sel1, '~', sel2, '~'],
[sel2, '~', sel1, '~'],
([merged, '~'] if merged)
].compact
end
elsif (op1 == '~' && op2 == '+') || (op1 == '+' && op2 == '~')
if op1 == '~'
tilde_sel, plus_sel = sel1, sel2
else
tilde_sel, plus_sel = sel2, sel1
end
if tilde_sel.superselector?(plus_sel)
res.unshift plus_sel, '+'
else
merged = plus_sel.unify(tilde_sel)
res.unshift [
[tilde_sel, '~', plus_sel, '+'],
([merged, '+'] if merged)
].compact
end
elsif op1 == '>' && %w(~ +).include?(op2)
res.unshift sel2, op2
seq1.push sel1, op1
elsif op2 == '>' && %w(~ +).include?(op1)
res.unshift sel1, op1
seq2.push sel2, op2
elsif op1 == op2
merged = sel1.unify(sel2)
return unless merged
res.unshift merged, op1
else
# Unknown selector combinators can't be unified
return
end
return merge_final_ops(seq1, seq2, res)
elsif op1
seq2.pop if op1 == '>' && seq2.last && seq2.last.superselector?(seq1.last)
res.unshift seq1.pop, op1
return merge_final_ops(seq1, seq2, res)
else # op2
seq1.pop if op2 == '>' && seq1.last && seq1.last.superselector?(seq2.last)
res.unshift seq2.pop, op2
return merge_final_ops(seq1, seq2, res)
end
end
|
Extracts final selector combinators (`"+"`, `">"`, `"~"`) and the
selectors to which they apply from two sequences and merges them
together into a single array.
@param seq1 [Array<SimpleSequence or String>]
@param seq2 [Array<SimpleSequence or String>]
@return [Array<SimpleSequence or String or
Array<Array<SimpleSequence or String>>]
If there are no trailing combinators to be merged, this will be the
empty array. If the trailing combinators cannot be merged, this will
be nil. Otherwise, this will contained the merged selector. Array
elements are [Sass::Util#paths]-style options; conceptually, an "or"
of multiple selectors.
|
merge_final_ops
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector/sequence.rb
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.