repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
sass/ruby-sass | lib/sass/tree/rule_node.rb | Sass::Tree.RuleNode.add_rules | def add_rules(node)
@rule = Sass::Util.strip_string_array(
Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
try_to_parse_non_interpolated_rules
end | ruby | def add_rules(node)
@rule = Sass::Util.strip_string_array(
Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
try_to_parse_non_interpolated_rules
end | [
"def",
"add_rules",
"(",
"node",
")",
"@rule",
"=",
"Sass",
"::",
"Util",
".",
"strip_string_array",
"(",
"Sass",
"::",
"Util",
".",
"merge_adjacent_strings",
"(",
"@rule",
"+",
"[",
"\"\\n\"",
"]",
"+",
"node",
".",
"rule",
")",
")",
"try_to_parse_non_interpolated_rules",
"end"
] | Compares the contents of two rules.
@param other [Object] The object to compare with
@return [Boolean] Whether or not this node and the other object
are the same
Adds another {RuleNode}'s rules to this one's.
@param node [RuleNode] The other node | [
"Compares",
"the",
"contents",
"of",
"two",
"rules",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/tree/rule_node.rb#L104-L108 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.map_vals | def map_vals(hash)
# We don't delegate to map_hash for performance here
# because map_hash does more than is necessary.
rv = hash.class.new
hash = hash.as_stored if hash.is_a?(NormalizedMap)
hash.each do |k, v|
rv[k] = yield(v)
end
rv
end | ruby | def map_vals(hash)
# We don't delegate to map_hash for performance here
# because map_hash does more than is necessary.
rv = hash.class.new
hash = hash.as_stored if hash.is_a?(NormalizedMap)
hash.each do |k, v|
rv[k] = yield(v)
end
rv
end | [
"def",
"map_vals",
"(",
"hash",
")",
"rv",
"=",
"hash",
".",
"class",
".",
"new",
"hash",
"=",
"hash",
".",
"as_stored",
"if",
"hash",
".",
"is_a?",
"(",
"NormalizedMap",
")",
"hash",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"rv",
"[",
"k",
"]",
"=",
"yield",
"(",
"v",
")",
"end",
"rv",
"end"
] | Maps the values in a hash according to a block.
@example
map_values({:foo => "bar", :baz => "bang"}) {|v| v.to_sym}
#=> {:foo => :bar, :baz => :bang}
@param hash [Hash] The hash to map
@yield [value] A block in which the values are transformed
@yieldparam value [Object] The value that should be mapped
@yieldreturn [Object] The new value for the value
@return [Hash] The mapped hash
@see #map_keys
@see #map_hash | [
"Maps",
"the",
"values",
"in",
"a",
"hash",
"according",
"to",
"a",
"block",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L64-L73 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.map_hash | def map_hash(hash)
# Copy and modify is more performant than mapping to an array and using
# to_hash on the result.
rv = hash.class.new
hash.each do |k, v|
new_key, new_value = yield(k, v)
new_key = hash.denormalize(new_key) if hash.is_a?(NormalizedMap) && new_key == k
rv[new_key] = new_value
end
rv
end | ruby | def map_hash(hash)
# Copy and modify is more performant than mapping to an array and using
# to_hash on the result.
rv = hash.class.new
hash.each do |k, v|
new_key, new_value = yield(k, v)
new_key = hash.denormalize(new_key) if hash.is_a?(NormalizedMap) && new_key == k
rv[new_key] = new_value
end
rv
end | [
"def",
"map_hash",
"(",
"hash",
")",
"rv",
"=",
"hash",
".",
"class",
".",
"new",
"hash",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"new_key",
",",
"new_value",
"=",
"yield",
"(",
"k",
",",
"v",
")",
"new_key",
"=",
"hash",
".",
"denormalize",
"(",
"new_key",
")",
"if",
"hash",
".",
"is_a?",
"(",
"NormalizedMap",
")",
"&&",
"new_key",
"==",
"k",
"rv",
"[",
"new_key",
"]",
"=",
"new_value",
"end",
"rv",
"end"
] | Maps the key-value pairs of a hash according to a block.
@example
map_hash({:foo => "bar", :baz => "bang"}) {|k, v| [k.to_s, v.to_sym]}
#=> {"foo" => :bar, "baz" => :bang}
@param hash [Hash] The hash to map
@yield [key, value] A block in which the key-value pairs are transformed
@yieldparam [key] The hash key
@yieldparam [value] The hash value
@yieldreturn [(Object, Object)] The new value for the `[key, value]` pair
@return [Hash] The mapped hash
@see #map_keys
@see #map_vals | [
"Maps",
"the",
"key",
"-",
"value",
"pairs",
"of",
"a",
"hash",
"according",
"to",
"a",
"block",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L88-L98 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.powerset | def powerset(arr)
arr.inject([Set.new].to_set) do |powerset, el|
new_powerset = Set.new
powerset.each do |subset|
new_powerset << subset
new_powerset << subset + [el]
end
new_powerset
end
end | ruby | def powerset(arr)
arr.inject([Set.new].to_set) do |powerset, el|
new_powerset = Set.new
powerset.each do |subset|
new_powerset << subset
new_powerset << subset + [el]
end
new_powerset
end
end | [
"def",
"powerset",
"(",
"arr",
")",
"arr",
".",
"inject",
"(",
"[",
"Set",
".",
"new",
"]",
".",
"to_set",
")",
"do",
"|",
"powerset",
",",
"el",
"|",
"new_powerset",
"=",
"Set",
".",
"new",
"powerset",
".",
"each",
"do",
"|",
"subset",
"|",
"new_powerset",
"<<",
"subset",
"new_powerset",
"<<",
"subset",
"+",
"[",
"el",
"]",
"end",
"new_powerset",
"end",
"end"
] | Computes the powerset of the given array.
This is the set of all subsets of the array.
@example
powerset([1, 2, 3]) #=>
Set[Set[], Set[1], Set[2], Set[3], Set[1, 2], Set[2, 3], Set[1, 3], Set[1, 2, 3]]
@param arr [Enumerable]
@return [Set<Set>] The subsets of `arr` | [
"Computes",
"the",
"powerset",
"of",
"the",
"given",
"array",
".",
"This",
"is",
"the",
"set",
"of",
"all",
"subsets",
"of",
"the",
"array",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L108-L117 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.restrict | def restrict(value, range)
[[value, range.first].max, range.last].min
end | ruby | def restrict(value, range)
[[value, range.first].max, range.last].min
end | [
"def",
"restrict",
"(",
"value",
",",
"range",
")",
"[",
"[",
"value",
",",
"range",
".",
"first",
"]",
".",
"max",
",",
"range",
".",
"last",
"]",
".",
"min",
"end"
] | Restricts a number to falling within a given range.
Returns the number if it falls within the range,
or the closest value in the range if it doesn't.
@param value [Numeric]
@param range [Range<Numeric>]
@return [Numeric] | [
"Restricts",
"a",
"number",
"to",
"falling",
"within",
"a",
"given",
"range",
".",
"Returns",
"the",
"number",
"if",
"it",
"falls",
"within",
"the",
"range",
"or",
"the",
"closest",
"value",
"in",
"the",
"range",
"if",
"it",
"doesn",
"t",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L126-L128 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.merge_adjacent_strings | def merge_adjacent_strings(arr)
# Optimize for the common case of one element
return arr if arr.size < 2
arr.inject([]) do |a, e|
if e.is_a?(String)
if a.last.is_a?(String)
a.last << e
else
a << e.dup
end
else
a << e
end
a
end
end | ruby | def merge_adjacent_strings(arr)
# Optimize for the common case of one element
return arr if arr.size < 2
arr.inject([]) do |a, e|
if e.is_a?(String)
if a.last.is_a?(String)
a.last << e
else
a << e.dup
end
else
a << e
end
a
end
end | [
"def",
"merge_adjacent_strings",
"(",
"arr",
")",
"return",
"arr",
"if",
"arr",
".",
"size",
"<",
"2",
"arr",
".",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"a",
",",
"e",
"|",
"if",
"e",
".",
"is_a?",
"(",
"String",
")",
"if",
"a",
".",
"last",
".",
"is_a?",
"(",
"String",
")",
"a",
".",
"last",
"<<",
"e",
"else",
"a",
"<<",
"e",
".",
"dup",
"end",
"else",
"a",
"<<",
"e",
"end",
"a",
"end",
"end"
] | Concatenates all strings that are adjacent in an array,
while leaving other elements as they are.
@example
merge_adjacent_strings([1, "foo", "bar", 2, "baz"])
#=> [1, "foobar", 2, "baz"]
@param arr [Array]
@return [Array] The enumerable with strings merged | [
"Concatenates",
"all",
"strings",
"that",
"are",
"adjacent",
"in",
"an",
"array",
"while",
"leaving",
"other",
"elements",
"as",
"they",
"are",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L155-L170 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.replace_subseq | def replace_subseq(arr, subseq, replacement)
new = []
matched = []
i = 0
arr.each do |elem|
if elem != subseq[i]
new.push(*matched)
matched = []
i = 0
new << elem
next
end
if i == subseq.length - 1
matched = []
i = 0
new.push(*replacement)
else
matched << elem
i += 1
end
end
new.push(*matched)
new
end | ruby | def replace_subseq(arr, subseq, replacement)
new = []
matched = []
i = 0
arr.each do |elem|
if elem != subseq[i]
new.push(*matched)
matched = []
i = 0
new << elem
next
end
if i == subseq.length - 1
matched = []
i = 0
new.push(*replacement)
else
matched << elem
i += 1
end
end
new.push(*matched)
new
end | [
"def",
"replace_subseq",
"(",
"arr",
",",
"subseq",
",",
"replacement",
")",
"new",
"=",
"[",
"]",
"matched",
"=",
"[",
"]",
"i",
"=",
"0",
"arr",
".",
"each",
"do",
"|",
"elem",
"|",
"if",
"elem",
"!=",
"subseq",
"[",
"i",
"]",
"new",
".",
"push",
"(",
"*",
"matched",
")",
"matched",
"=",
"[",
"]",
"i",
"=",
"0",
"new",
"<<",
"elem",
"next",
"end",
"if",
"i",
"==",
"subseq",
".",
"length",
"-",
"1",
"matched",
"=",
"[",
"]",
"i",
"=",
"0",
"new",
".",
"push",
"(",
"*",
"replacement",
")",
"else",
"matched",
"<<",
"elem",
"i",
"+=",
"1",
"end",
"end",
"new",
".",
"push",
"(",
"*",
"matched",
")",
"new",
"end"
] | Non-destructively replaces all occurrences of a subsequence in an array
with another subsequence.
@example
replace_subseq([1, 2, 3, 4, 5], [2, 3], [:a, :b])
#=> [1, :a, :b, 4, 5]
@param arr [Array] The array whose subsequences will be replaced.
@param subseq [Array] The subsequence to find and replace.
@param replacement [Array] The sequence that `subseq` will be replaced with.
@return [Array] `arr` with `subseq` replaced with `replacement`. | [
"Non",
"-",
"destructively",
"replaces",
"all",
"occurrences",
"of",
"a",
"subsequence",
"in",
"an",
"array",
"with",
"another",
"subsequence",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L183-L207 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.substitute | def substitute(ary, from, to)
res = ary.dup
i = 0
while i < res.size
if res[i...i + from.size] == from
res[i...i + from.size] = to
end
i += 1
end
res
end | ruby | def substitute(ary, from, to)
res = ary.dup
i = 0
while i < res.size
if res[i...i + from.size] == from
res[i...i + from.size] = to
end
i += 1
end
res
end | [
"def",
"substitute",
"(",
"ary",
",",
"from",
",",
"to",
")",
"res",
"=",
"ary",
".",
"dup",
"i",
"=",
"0",
"while",
"i",
"<",
"res",
".",
"size",
"if",
"res",
"[",
"i",
"...",
"i",
"+",
"from",
".",
"size",
"]",
"==",
"from",
"res",
"[",
"i",
"...",
"i",
"+",
"from",
".",
"size",
"]",
"=",
"to",
"end",
"i",
"+=",
"1",
"end",
"res",
"end"
] | Substitutes a sub-array of one array with another sub-array.
@param ary [Array] The array in which to make the substitution
@param from [Array] The sequence of elements to replace with `to`
@param to [Array] The sequence of elements to replace `from` with | [
"Substitutes",
"a",
"sub",
"-",
"array",
"of",
"one",
"array",
"with",
"another",
"sub",
"-",
"array",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L237-L247 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.paths | def paths(arrs)
arrs.inject([[]]) do |paths, arr|
arr.map {|e| paths.map {|path| path + [e]}}.flatten(1)
end
end | ruby | def paths(arrs)
arrs.inject([[]]) do |paths, arr|
arr.map {|e| paths.map {|path| path + [e]}}.flatten(1)
end
end | [
"def",
"paths",
"(",
"arrs",
")",
"arrs",
".",
"inject",
"(",
"[",
"[",
"]",
"]",
")",
"do",
"|",
"paths",
",",
"arr",
"|",
"arr",
".",
"map",
"{",
"|",
"e",
"|",
"paths",
".",
"map",
"{",
"|",
"path",
"|",
"path",
"+",
"[",
"e",
"]",
"}",
"}",
".",
"flatten",
"(",
"1",
")",
"end",
"end"
] | Return an array of all possible paths through the given arrays.
@param arrs [Array<Array>]
@return [Array<Arrays>]
@example
paths([[1, 2], [3, 4], [5]]) #=>
# [[1, 3, 5],
# [2, 3, 5],
# [1, 4, 5],
# [2, 4, 5]] | [
"Return",
"an",
"array",
"of",
"all",
"possible",
"paths",
"through",
"the",
"given",
"arrays",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L321-L325 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.lcs | def lcs(x, y, &block)
x = [nil, *x]
y = [nil, *y]
block ||= proc {|a, b| a == b && a}
lcs_backtrace(lcs_table(x, y, &block), x, y, x.size - 1, y.size - 1, &block)
end | ruby | def lcs(x, y, &block)
x = [nil, *x]
y = [nil, *y]
block ||= proc {|a, b| a == b && a}
lcs_backtrace(lcs_table(x, y, &block), x, y, x.size - 1, y.size - 1, &block)
end | [
"def",
"lcs",
"(",
"x",
",",
"y",
",",
"&",
"block",
")",
"x",
"=",
"[",
"nil",
",",
"*",
"x",
"]",
"y",
"=",
"[",
"nil",
",",
"*",
"y",
"]",
"block",
"||=",
"proc",
"{",
"|",
"a",
",",
"b",
"|",
"a",
"==",
"b",
"&&",
"a",
"}",
"lcs_backtrace",
"(",
"lcs_table",
"(",
"x",
",",
"y",
",",
"&",
"block",
")",
",",
"x",
",",
"y",
",",
"x",
".",
"size",
"-",
"1",
",",
"y",
".",
"size",
"-",
"1",
",",
"&",
"block",
")",
"end"
] | Computes a single longest common subsequence for `x` and `y`.
If there are more than one longest common subsequences,
the one returned is that which starts first in `x`.
@param x [Array]
@param y [Array]
@yield [a, b] An optional block to use in place of a check for equality
between elements of `x` and `y`.
@yieldreturn [Object, nil] If the two values register as equal,
this will return the value to use in the LCS array.
@return [Array] The LCS | [
"Computes",
"a",
"single",
"longest",
"common",
"subsequence",
"for",
"x",
"and",
"y",
".",
"If",
"there",
"are",
"more",
"than",
"one",
"longest",
"common",
"subsequences",
"the",
"one",
"returned",
"is",
"that",
"which",
"starts",
"first",
"in",
"x",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L338-L343 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.caller_info | def caller_info(entry = nil)
# JRuby evaluates `caller` incorrectly when it's in an actual default argument.
entry ||= caller[1]
info = entry.scan(/^((?:[A-Za-z]:)?.*?):(-?.*?)(?::.*`(.+)')?$/).first
info[1] = info[1].to_i
# This is added by Rubinius to designate a block, but we don't care about it.
info[2].sub!(/ \{\}\Z/, '') if info[2]
info
end | ruby | def caller_info(entry = nil)
# JRuby evaluates `caller` incorrectly when it's in an actual default argument.
entry ||= caller[1]
info = entry.scan(/^((?:[A-Za-z]:)?.*?):(-?.*?)(?::.*`(.+)')?$/).first
info[1] = info[1].to_i
# This is added by Rubinius to designate a block, but we don't care about it.
info[2].sub!(/ \{\}\Z/, '') if info[2]
info
end | [
"def",
"caller_info",
"(",
"entry",
"=",
"nil",
")",
"entry",
"||=",
"caller",
"[",
"1",
"]",
"info",
"=",
"entry",
".",
"scan",
"(",
"/",
"/",
")",
".",
"first",
"info",
"[",
"1",
"]",
"=",
"info",
"[",
"1",
"]",
".",
"to_i",
"info",
"[",
"2",
"]",
".",
"sub!",
"(",
"/",
"\\{",
"\\}",
"\\Z",
"/",
",",
"''",
")",
"if",
"info",
"[",
"2",
"]",
"info",
"end"
] | Returns information about the caller of the previous method.
@param entry [String] An entry in the `#caller` list, or a similarly formatted string
@return [[String, Integer, (String, nil)]]
An array containing the filename, line, and method name of the caller.
The method name may be nil | [
"Returns",
"information",
"about",
"the",
"caller",
"of",
"the",
"previous",
"method",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L439-L447 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.version_gt | def version_gt(v1, v2)
# Construct an array to make sure the shorter version is padded with nil
Array.new([v1.length, v2.length].max).zip(v1.split("."), v2.split(".")) do |_, p1, p2|
p1 ||= "0"
p2 ||= "0"
release1 = p1 =~ /^[0-9]+$/
release2 = p2 =~ /^[0-9]+$/
if release1 && release2
# Integer comparison if both are full releases
p1, p2 = p1.to_i, p2.to_i
next if p1 == p2
return p1 > p2
elsif !release1 && !release2
# String comparison if both are prereleases
next if p1 == p2
return p1 > p2
else
# If only one is a release, that one is newer
return release1
end
end
end | ruby | def version_gt(v1, v2)
# Construct an array to make sure the shorter version is padded with nil
Array.new([v1.length, v2.length].max).zip(v1.split("."), v2.split(".")) do |_, p1, p2|
p1 ||= "0"
p2 ||= "0"
release1 = p1 =~ /^[0-9]+$/
release2 = p2 =~ /^[0-9]+$/
if release1 && release2
# Integer comparison if both are full releases
p1, p2 = p1.to_i, p2.to_i
next if p1 == p2
return p1 > p2
elsif !release1 && !release2
# String comparison if both are prereleases
next if p1 == p2
return p1 > p2
else
# If only one is a release, that one is newer
return release1
end
end
end | [
"def",
"version_gt",
"(",
"v1",
",",
"v2",
")",
"Array",
".",
"new",
"(",
"[",
"v1",
".",
"length",
",",
"v2",
".",
"length",
"]",
".",
"max",
")",
".",
"zip",
"(",
"v1",
".",
"split",
"(",
"\".\"",
")",
",",
"v2",
".",
"split",
"(",
"\".\"",
")",
")",
"do",
"|",
"_",
",",
"p1",
",",
"p2",
"|",
"p1",
"||=",
"\"0\"",
"p2",
"||=",
"\"0\"",
"release1",
"=",
"p1",
"=~",
"/",
"/",
"release2",
"=",
"p2",
"=~",
"/",
"/",
"if",
"release1",
"&&",
"release2",
"p1",
",",
"p2",
"=",
"p1",
".",
"to_i",
",",
"p2",
".",
"to_i",
"next",
"if",
"p1",
"==",
"p2",
"return",
"p1",
">",
"p2",
"elsif",
"!",
"release1",
"&&",
"!",
"release2",
"next",
"if",
"p1",
"==",
"p2",
"return",
"p1",
">",
"p2",
"else",
"return",
"release1",
"end",
"end",
"end"
] | Returns whether one version string represents a more recent version than another.
@param v1 [String] A version string.
@param v2 [String] Another version string.
@return [Boolean] | [
"Returns",
"whether",
"one",
"version",
"string",
"represents",
"a",
"more",
"recent",
"version",
"than",
"another",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L454-L475 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.deprecated | def deprecated(obj, message = nil)
obj_class = obj.is_a?(Class) ? "#{obj}." : "#{obj.class}#"
full_message = "DEPRECATION WARNING: #{obj_class}#{caller_info[2]} " +
"will be removed in a future version of Sass.#{("\n" + message) if message}"
Sass::Util.sass_warn full_message
end | ruby | def deprecated(obj, message = nil)
obj_class = obj.is_a?(Class) ? "#{obj}." : "#{obj.class}#"
full_message = "DEPRECATION WARNING: #{obj_class}#{caller_info[2]} " +
"will be removed in a future version of Sass.#{("\n" + message) if message}"
Sass::Util.sass_warn full_message
end | [
"def",
"deprecated",
"(",
"obj",
",",
"message",
"=",
"nil",
")",
"obj_class",
"=",
"obj",
".",
"is_a?",
"(",
"Class",
")",
"?",
"\"#{obj}.\"",
":",
"\"#{obj.class}#\"",
"full_message",
"=",
"\"DEPRECATION WARNING: #{obj_class}#{caller_info[2]} \"",
"+",
"\"will be removed in a future version of Sass.#{(\"\\n\" + message) if message}\"",
"Sass",
"::",
"Util",
".",
"sass_warn",
"full_message",
"end"
] | Prints a deprecation warning for the caller method.
@param obj [Object] `self`
@param message [String] A message describing what to do instead. | [
"Prints",
"a",
"deprecation",
"warning",
"for",
"the",
"caller",
"method",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L499-L504 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.silence_sass_warnings | def silence_sass_warnings
old_level, Sass.logger.log_level = Sass.logger.log_level, :error
yield
ensure
Sass.logger.log_level = old_level
end | ruby | def silence_sass_warnings
old_level, Sass.logger.log_level = Sass.logger.log_level, :error
yield
ensure
Sass.logger.log_level = old_level
end | [
"def",
"silence_sass_warnings",
"old_level",
",",
"Sass",
".",
"logger",
".",
"log_level",
"=",
"Sass",
".",
"logger",
".",
"log_level",
",",
":error",
"yield",
"ensure",
"Sass",
".",
"logger",
".",
"log_level",
"=",
"old_level",
"end"
] | Silences all Sass warnings within a block.
@yield A block in which no Sass warnings will be printed | [
"Silences",
"all",
"Sass",
"warnings",
"within",
"a",
"block",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L509-L514 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.rails_root | def rails_root
if defined?(::Rails.root)
return ::Rails.root.to_s if ::Rails.root
raise "ERROR: Rails.root is nil!"
end
return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
nil
end | ruby | def rails_root
if defined?(::Rails.root)
return ::Rails.root.to_s if ::Rails.root
raise "ERROR: Rails.root is nil!"
end
return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
nil
end | [
"def",
"rails_root",
"if",
"defined?",
"(",
"::",
"Rails",
".",
"root",
")",
"return",
"::",
"Rails",
".",
"root",
".",
"to_s",
"if",
"::",
"Rails",
".",
"root",
"raise",
"\"ERROR: Rails.root is nil!\"",
"end",
"return",
"RAILS_ROOT",
".",
"to_s",
"if",
"defined?",
"(",
"RAILS_ROOT",
")",
"nil",
"end"
] | Cross Rails Version Compatibility
Returns the root of the Rails application,
if this is running in a Rails context.
Returns `nil` if no such root is defined.
@return [String, nil] | [
"Cross",
"Rails",
"Version",
"Compatibility",
"Returns",
"the",
"root",
"of",
"the",
"Rails",
"application",
"if",
"this",
"is",
"running",
"in",
"a",
"Rails",
"context",
".",
"Returns",
"nil",
"if",
"no",
"such",
"root",
"is",
"defined",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L530-L537 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.ap_geq? | def ap_geq?(version)
# The ActionPack module is always loaded automatically in Rails >= 3
return false unless defined?(ActionPack) && defined?(ActionPack::VERSION) &&
defined?(ActionPack::VERSION::STRING)
version_geq(ActionPack::VERSION::STRING, version)
end | ruby | def ap_geq?(version)
# The ActionPack module is always loaded automatically in Rails >= 3
return false unless defined?(ActionPack) && defined?(ActionPack::VERSION) &&
defined?(ActionPack::VERSION::STRING)
version_geq(ActionPack::VERSION::STRING, version)
end | [
"def",
"ap_geq?",
"(",
"version",
")",
"return",
"false",
"unless",
"defined?",
"(",
"ActionPack",
")",
"&&",
"defined?",
"(",
"ActionPack",
"::",
"VERSION",
")",
"&&",
"defined?",
"(",
"ActionPack",
"::",
"VERSION",
"::",
"STRING",
")",
"version_geq",
"(",
"ActionPack",
"::",
"VERSION",
"::",
"STRING",
",",
"version",
")",
"end"
] | Returns whether this environment is using ActionPack
of a version greater than or equal to that specified.
@param version [String] The string version number to check against.
Should be greater than or equal to Rails 3,
because otherwise ActionPack::VERSION isn't autoloaded
@return [Boolean] | [
"Returns",
"whether",
"this",
"environment",
"is",
"using",
"ActionPack",
"of",
"a",
"version",
"greater",
"than",
"or",
"equal",
"to",
"that",
"specified",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L565-L571 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.glob | def glob(path)
path = path.tr('\\', '/') if windows?
if block_given?
Dir.glob(path) {|f| yield(f)}
else
Dir.glob(path)
end
end | ruby | def glob(path)
path = path.tr('\\', '/') if windows?
if block_given?
Dir.glob(path) {|f| yield(f)}
else
Dir.glob(path)
end
end | [
"def",
"glob",
"(",
"path",
")",
"path",
"=",
"path",
".",
"tr",
"(",
"'\\\\'",
",",
"'/'",
")",
"if",
"windows?",
"if",
"block_given?",
"Dir",
".",
"glob",
"(",
"path",
")",
"{",
"|",
"f",
"|",
"yield",
"(",
"f",
")",
"}",
"else",
"Dir",
".",
"glob",
"(",
"path",
")",
"end",
"end"
] | Like `Dir.glob`, but works with backslash-separated paths on Windows.
@param path [String] | [
"Like",
"Dir",
".",
"glob",
"but",
"works",
"with",
"backslash",
"-",
"separated",
"paths",
"on",
"Windows",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L633-L640 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.realpath | def realpath(path)
path = Pathname.new(path) unless path.is_a?(Pathname)
# Explicitly DON'T run #pathname here. We don't want to convert
# to Windows directory separators because we're comparing these
# against the paths returned by Listen, which use forward
# slashes everywhere.
begin
path.realpath
rescue SystemCallError
# If [path] doesn't actually exist, don't bail, just
# return the original.
path
end
end | ruby | def realpath(path)
path = Pathname.new(path) unless path.is_a?(Pathname)
# Explicitly DON'T run #pathname here. We don't want to convert
# to Windows directory separators because we're comparing these
# against the paths returned by Listen, which use forward
# slashes everywhere.
begin
path.realpath
rescue SystemCallError
# If [path] doesn't actually exist, don't bail, just
# return the original.
path
end
end | [
"def",
"realpath",
"(",
"path",
")",
"path",
"=",
"Pathname",
".",
"new",
"(",
"path",
")",
"unless",
"path",
".",
"is_a?",
"(",
"Pathname",
")",
"begin",
"path",
".",
"realpath",
"rescue",
"SystemCallError",
"path",
"end",
"end"
] | Returns `path` with all symlinks resolved.
@param path [String, Pathname]
@return [Pathname] | [
"Returns",
"path",
"with",
"all",
"symlinks",
"resolved",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L671-L685 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.relative_path_from | def relative_path_from(path, from)
pathname(path.to_s).relative_path_from(pathname(from.to_s))
rescue NoMethodError => e
raise e unless e.name == :zero?
# Work around https://github.com/ruby/ruby/pull/713.
path = path.to_s
from = from.to_s
raise ArgumentError("Incompatible path encodings: #{path.inspect} is #{path.encoding}, " +
"#{from.inspect} is #{from.encoding}")
end | ruby | def relative_path_from(path, from)
pathname(path.to_s).relative_path_from(pathname(from.to_s))
rescue NoMethodError => e
raise e unless e.name == :zero?
# Work around https://github.com/ruby/ruby/pull/713.
path = path.to_s
from = from.to_s
raise ArgumentError("Incompatible path encodings: #{path.inspect} is #{path.encoding}, " +
"#{from.inspect} is #{from.encoding}")
end | [
"def",
"relative_path_from",
"(",
"path",
",",
"from",
")",
"pathname",
"(",
"path",
".",
"to_s",
")",
".",
"relative_path_from",
"(",
"pathname",
"(",
"from",
".",
"to_s",
")",
")",
"rescue",
"NoMethodError",
"=>",
"e",
"raise",
"e",
"unless",
"e",
".",
"name",
"==",
":zero?",
"path",
"=",
"path",
".",
"to_s",
"from",
"=",
"from",
".",
"to_s",
"raise",
"ArgumentError",
"(",
"\"Incompatible path encodings: #{path.inspect} is #{path.encoding}, \"",
"+",
"\"#{from.inspect} is #{from.encoding}\"",
")",
"end"
] | Returns `path` relative to `from`.
This is like `Pathname#relative_path_from` except it accepts both strings
and pathnames, it handles Windows path separators correctly, and it throws
an error rather than crashing if the paths use different encodings
(https://github.com/ruby/ruby/pull/713).
@param path [String, Pathname]
@param from [String, Pathname]
@return [Pathname?] | [
"Returns",
"path",
"relative",
"to",
"from",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L697-L707 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.extract! | def extract!(array)
out = []
array.reject! do |e|
next false unless yield e
out << e
true
end
out
end | ruby | def extract!(array)
out = []
array.reject! do |e|
next false unless yield e
out << e
true
end
out
end | [
"def",
"extract!",
"(",
"array",
")",
"out",
"=",
"[",
"]",
"array",
".",
"reject!",
"do",
"|",
"e",
"|",
"next",
"false",
"unless",
"yield",
"e",
"out",
"<<",
"e",
"true",
"end",
"out",
"end"
] | Destructively removes all elements from an array that match a block, and
returns the removed elements.
@param array [Array] The array from which to remove elements.
@yield [el] Called for each element.
@yieldparam el [*] The element to test.
@yieldreturn [Boolean] Whether or not to extract the element.
@return [Array] The extracted elements. | [
"Destructively",
"removes",
"all",
"elements",
"from",
"an",
"array",
"that",
"match",
"a",
"block",
"and",
"returns",
"the",
"removed",
"elements",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L832-L840 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.with_extracted_values | def with_extracted_values(arr)
str, vals = extract_values(arr)
str = yield str
inject_values(str, vals)
end | ruby | def with_extracted_values(arr)
str, vals = extract_values(arr)
str = yield str
inject_values(str, vals)
end | [
"def",
"with_extracted_values",
"(",
"arr",
")",
"str",
",",
"vals",
"=",
"extract_values",
"(",
"arr",
")",
"str",
"=",
"yield",
"str",
"inject_values",
"(",
"str",
",",
"vals",
")",
"end"
] | Allows modifications to be performed on the string form
of an array containing both strings and non-strings.
@param arr [Array] The array from which values are extracted.
@yield [str] A block in which string manipulation can be done to the array.
@yieldparam str [String] The string form of `arr`.
@yieldreturn [String] The modified string.
@return [Array] The modified, interpolated array. | [
"Allows",
"modifications",
"to",
"be",
"performed",
"on",
"the",
"string",
"form",
"of",
"an",
"array",
"containing",
"both",
"strings",
"and",
"non",
"-",
"strings",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L920-L924 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.json_escape_string | def json_escape_string(s)
return s if s !~ /["\\\b\f\n\r\t]/
result = ""
s.split("").each do |c|
case c
when '"', "\\"
result << "\\" << c
when "\n" then result << "\\n"
when "\t" then result << "\\t"
when "\r" then result << "\\r"
when "\f" then result << "\\f"
when "\b" then result << "\\b"
else
result << c
end
end
result
end | ruby | def json_escape_string(s)
return s if s !~ /["\\\b\f\n\r\t]/
result = ""
s.split("").each do |c|
case c
when '"', "\\"
result << "\\" << c
when "\n" then result << "\\n"
when "\t" then result << "\\t"
when "\r" then result << "\\r"
when "\f" then result << "\\f"
when "\b" then result << "\\b"
else
result << c
end
end
result
end | [
"def",
"json_escape_string",
"(",
"s",
")",
"return",
"s",
"if",
"s",
"!~",
"/",
"\\\\",
"\\b",
"\\f",
"\\n",
"\\r",
"\\t",
"/",
"result",
"=",
"\"\"",
"s",
".",
"split",
"(",
"\"\"",
")",
".",
"each",
"do",
"|",
"c",
"|",
"case",
"c",
"when",
"'\"'",
",",
"\"\\\\\"",
"result",
"<<",
"\"\\\\\"",
"<<",
"c",
"when",
"\"\\n\"",
"then",
"result",
"<<",
"\"\\\\n\"",
"when",
"\"\\t\"",
"then",
"result",
"<<",
"\"\\\\t\"",
"when",
"\"\\r\"",
"then",
"result",
"<<",
"\"\\\\r\"",
"when",
"\"\\f\"",
"then",
"result",
"<<",
"\"\\\\f\"",
"when",
"\"\\b\"",
"then",
"result",
"<<",
"\"\\\\b\"",
"else",
"result",
"<<",
"c",
"end",
"end",
"result",
"end"
] | Escapes certain characters so that the result can be used
as the JSON string value. Returns the original string if
no escaping is necessary.
@param s [String] The string to be escaped
@return [String] The escaped string | [
"Escapes",
"certain",
"characters",
"so",
"that",
"the",
"result",
"can",
"be",
"used",
"as",
"the",
"JSON",
"string",
"value",
".",
"Returns",
"the",
"original",
"string",
"if",
"no",
"escaping",
"is",
"necessary",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L940-L958 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.json_value_of | def json_value_of(v)
case v
when Integer
v.to_s
when String
"\"" + json_escape_string(v) + "\""
when Array
"[" + v.map {|x| json_value_of(x)}.join(",") + "]"
when NilClass
"null"
when TrueClass
"true"
when FalseClass
"false"
else
raise ArgumentError.new("Unknown type: #{v.class.name}")
end
end | ruby | def json_value_of(v)
case v
when Integer
v.to_s
when String
"\"" + json_escape_string(v) + "\""
when Array
"[" + v.map {|x| json_value_of(x)}.join(",") + "]"
when NilClass
"null"
when TrueClass
"true"
when FalseClass
"false"
else
raise ArgumentError.new("Unknown type: #{v.class.name}")
end
end | [
"def",
"json_value_of",
"(",
"v",
")",
"case",
"v",
"when",
"Integer",
"v",
".",
"to_s",
"when",
"String",
"\"\\\"\"",
"+",
"json_escape_string",
"(",
"v",
")",
"+",
"\"\\\"\"",
"when",
"Array",
"\"[\"",
"+",
"v",
".",
"map",
"{",
"|",
"x",
"|",
"json_value_of",
"(",
"x",
")",
"}",
".",
"join",
"(",
"\",\"",
")",
"+",
"\"]\"",
"when",
"NilClass",
"\"null\"",
"when",
"TrueClass",
"\"true\"",
"when",
"FalseClass",
"\"false\"",
"else",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Unknown type: #{v.class.name}\"",
")",
"end",
"end"
] | Converts the argument into a valid JSON value.
@param v [Integer, String, Array, Boolean, nil]
@return [String] | [
"Converts",
"the",
"argument",
"into",
"a",
"valid",
"JSON",
"value",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L964-L981 | train |
sass/ruby-sass | lib/sass/util.rb | Sass.Util.atomic_create_and_write_file | def atomic_create_and_write_file(filename, perms = 0666)
require 'tempfile'
tmpfile = Tempfile.new(File.basename(filename), File.dirname(filename))
tmpfile.binmode if tmpfile.respond_to?(:binmode)
result = yield tmpfile
tmpfile.close
ATOMIC_WRITE_MUTEX.synchronize do
begin
File.chmod(perms & ~File.umask, tmpfile.path)
rescue Errno::EPERM
# If we don't have permissions to chmod the file, don't let that crash
# the compilation. See issue 1215.
end
File.rename tmpfile.path, filename
end
result
ensure
# close and remove the tempfile if it still exists,
# presumably due to an error during write
tmpfile.close if tmpfile
tmpfile.unlink if tmpfile
end | ruby | def atomic_create_and_write_file(filename, perms = 0666)
require 'tempfile'
tmpfile = Tempfile.new(File.basename(filename), File.dirname(filename))
tmpfile.binmode if tmpfile.respond_to?(:binmode)
result = yield tmpfile
tmpfile.close
ATOMIC_WRITE_MUTEX.synchronize do
begin
File.chmod(perms & ~File.umask, tmpfile.path)
rescue Errno::EPERM
# If we don't have permissions to chmod the file, don't let that crash
# the compilation. See issue 1215.
end
File.rename tmpfile.path, filename
end
result
ensure
# close and remove the tempfile if it still exists,
# presumably due to an error during write
tmpfile.close if tmpfile
tmpfile.unlink if tmpfile
end | [
"def",
"atomic_create_and_write_file",
"(",
"filename",
",",
"perms",
"=",
"0666",
")",
"require",
"'tempfile'",
"tmpfile",
"=",
"Tempfile",
".",
"new",
"(",
"File",
".",
"basename",
"(",
"filename",
")",
",",
"File",
".",
"dirname",
"(",
"filename",
")",
")",
"tmpfile",
".",
"binmode",
"if",
"tmpfile",
".",
"respond_to?",
"(",
":binmode",
")",
"result",
"=",
"yield",
"tmpfile",
"tmpfile",
".",
"close",
"ATOMIC_WRITE_MUTEX",
".",
"synchronize",
"do",
"begin",
"File",
".",
"chmod",
"(",
"perms",
"&",
"~",
"File",
".",
"umask",
",",
"tmpfile",
".",
"path",
")",
"rescue",
"Errno",
"::",
"EPERM",
"end",
"File",
".",
"rename",
"tmpfile",
".",
"path",
",",
"filename",
"end",
"result",
"ensure",
"tmpfile",
".",
"close",
"if",
"tmpfile",
"tmpfile",
".",
"unlink",
"if",
"tmpfile",
"end"
] | This creates a temp file and yields it for writing. When the
write is complete, the file is moved into the desired location.
The atomicity of this operation is provided by the filesystem's
rename operation.
@param filename [String] The file to write to.
@param perms [Integer] The permissions used for creating this file.
Will be masked by the process umask. Defaults to readable/writeable
by all users however the umask usually changes this to only be writable
by the process's user.
@yieldparam tmpfile [Tempfile] The temp file that can be written to.
@return The value returned by the block. | [
"This",
"creates",
"a",
"temp",
"file",
"and",
"yields",
"it",
"for",
"writing",
".",
"When",
"the",
"write",
"is",
"complete",
"the",
"file",
"is",
"moved",
"into",
"the",
"desired",
"location",
".",
"The",
"atomicity",
"of",
"this",
"operation",
"is",
"provided",
"by",
"the",
"filesystem",
"s",
"rename",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/util.rb#L1054-L1075 | train |
sass/ruby-sass | lib/sass/script/value/map.rb | Sass::Script::Value.Map.options= | def options=(options)
super
value.each do |k, v|
k.options = options
v.options = options
end
end | ruby | def options=(options)
super
value.each do |k, v|
k.options = options
v.options = options
end
end | [
"def",
"options",
"=",
"(",
"options",
")",
"super",
"value",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"k",
".",
"options",
"=",
"options",
"v",
".",
"options",
"=",
"options",
"end",
"end"
] | Creates a new map.
@param hash [Hash<Node, Node>]
@see Value#options= | [
"Creates",
"a",
"new",
"map",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/map.rb#L19-L25 | train |
sass/ruby-sass | lib/sass/script/tree/node.rb | Sass::Script::Tree.Node.perform | def perform(environment)
_perform(environment)
rescue Sass::SyntaxError => e
e.modify_backtrace(:line => line)
raise e
end | ruby | def perform(environment)
_perform(environment)
rescue Sass::SyntaxError => e
e.modify_backtrace(:line => line)
raise e
end | [
"def",
"perform",
"(",
"environment",
")",
"_perform",
"(",
"environment",
")",
"rescue",
"Sass",
"::",
"SyntaxError",
"=>",
"e",
"e",
".",
"modify_backtrace",
"(",
":line",
"=>",
"line",
")",
"raise",
"e",
"end"
] | Evaluates the node.
\{#perform} shouldn't be overridden directly;
instead, override \{#\_perform}.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript
@return [Sass::Script::Value] The SassScript object that is the value of the SassScript | [
"Evaluates",
"the",
"node",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/node.rb#L49-L54 | train |
sass/ruby-sass | lib/sass/script/tree/funcall.rb | Sass::Script::Tree.Funcall._perform | def _perform(environment)
args = @args.each_with_index.
map {|a, i| perform_arg(a, environment, signature && signature.args[i])}
keywords = Sass::Util.map_hash(@keywords) do |k, v|
[k, perform_arg(v, environment, k.tr('-', '_'))]
end
splat = Sass::Tree::Visitors::Perform.perform_splat(
@splat, keywords, @kwarg_splat, environment)
fn = @callable || environment.function(@name)
if fn && fn.origin == :stylesheet
environment.stack.with_function(filename, line, name) do
return without_original(perform_sass_fn(fn, args, splat, environment))
end
end
args = construct_ruby_args(ruby_name, args, splat, environment)
if Sass::Script::Functions.callable?(ruby_name) && (!fn || fn.origin == :builtin)
local_environment = Sass::Environment.new(environment.global_env, environment.options)
local_environment.caller = Sass::ReadOnlyEnvironment.new(environment, environment.options)
result = local_environment.stack.with_function(filename, line, name) do
opts(Sass::Script::Functions::EvaluationContext.new(
local_environment).send(ruby_name, *args))
end
without_original(result)
else
opts(to_literal(args))
end
rescue ArgumentError => e
reformat_argument_error(e)
end | ruby | def _perform(environment)
args = @args.each_with_index.
map {|a, i| perform_arg(a, environment, signature && signature.args[i])}
keywords = Sass::Util.map_hash(@keywords) do |k, v|
[k, perform_arg(v, environment, k.tr('-', '_'))]
end
splat = Sass::Tree::Visitors::Perform.perform_splat(
@splat, keywords, @kwarg_splat, environment)
fn = @callable || environment.function(@name)
if fn && fn.origin == :stylesheet
environment.stack.with_function(filename, line, name) do
return without_original(perform_sass_fn(fn, args, splat, environment))
end
end
args = construct_ruby_args(ruby_name, args, splat, environment)
if Sass::Script::Functions.callable?(ruby_name) && (!fn || fn.origin == :builtin)
local_environment = Sass::Environment.new(environment.global_env, environment.options)
local_environment.caller = Sass::ReadOnlyEnvironment.new(environment, environment.options)
result = local_environment.stack.with_function(filename, line, name) do
opts(Sass::Script::Functions::EvaluationContext.new(
local_environment).send(ruby_name, *args))
end
without_original(result)
else
opts(to_literal(args))
end
rescue ArgumentError => e
reformat_argument_error(e)
end | [
"def",
"_perform",
"(",
"environment",
")",
"args",
"=",
"@args",
".",
"each_with_index",
".",
"map",
"{",
"|",
"a",
",",
"i",
"|",
"perform_arg",
"(",
"a",
",",
"environment",
",",
"signature",
"&&",
"signature",
".",
"args",
"[",
"i",
"]",
")",
"}",
"keywords",
"=",
"Sass",
"::",
"Util",
".",
"map_hash",
"(",
"@keywords",
")",
"do",
"|",
"k",
",",
"v",
"|",
"[",
"k",
",",
"perform_arg",
"(",
"v",
",",
"environment",
",",
"k",
".",
"tr",
"(",
"'-'",
",",
"'_'",
")",
")",
"]",
"end",
"splat",
"=",
"Sass",
"::",
"Tree",
"::",
"Visitors",
"::",
"Perform",
".",
"perform_splat",
"(",
"@splat",
",",
"keywords",
",",
"@kwarg_splat",
",",
"environment",
")",
"fn",
"=",
"@callable",
"||",
"environment",
".",
"function",
"(",
"@name",
")",
"if",
"fn",
"&&",
"fn",
".",
"origin",
"==",
":stylesheet",
"environment",
".",
"stack",
".",
"with_function",
"(",
"filename",
",",
"line",
",",
"name",
")",
"do",
"return",
"without_original",
"(",
"perform_sass_fn",
"(",
"fn",
",",
"args",
",",
"splat",
",",
"environment",
")",
")",
"end",
"end",
"args",
"=",
"construct_ruby_args",
"(",
"ruby_name",
",",
"args",
",",
"splat",
",",
"environment",
")",
"if",
"Sass",
"::",
"Script",
"::",
"Functions",
".",
"callable?",
"(",
"ruby_name",
")",
"&&",
"(",
"!",
"fn",
"||",
"fn",
".",
"origin",
"==",
":builtin",
")",
"local_environment",
"=",
"Sass",
"::",
"Environment",
".",
"new",
"(",
"environment",
".",
"global_env",
",",
"environment",
".",
"options",
")",
"local_environment",
".",
"caller",
"=",
"Sass",
"::",
"ReadOnlyEnvironment",
".",
"new",
"(",
"environment",
",",
"environment",
".",
"options",
")",
"result",
"=",
"local_environment",
".",
"stack",
".",
"with_function",
"(",
"filename",
",",
"line",
",",
"name",
")",
"do",
"opts",
"(",
"Sass",
"::",
"Script",
"::",
"Functions",
"::",
"EvaluationContext",
".",
"new",
"(",
"local_environment",
")",
".",
"send",
"(",
"ruby_name",
",",
"*",
"args",
")",
")",
"end",
"without_original",
"(",
"result",
")",
"else",
"opts",
"(",
"to_literal",
"(",
"args",
")",
")",
"end",
"rescue",
"ArgumentError",
"=>",
"e",
"reformat_argument_error",
"(",
"e",
")",
"end"
] | Evaluates the function call.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript
@return [Sass::Script::Value] The SassScript object that is the value of the function call
@raise [Sass::SyntaxError] if the function call raises an ArgumentError | [
"Evaluates",
"the",
"function",
"call",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/funcall.rb#L127-L159 | train |
sass/ruby-sass | lib/sass/environment.rb | Sass.ReadOnlyEnvironment.caller | def caller
return @caller if @caller
env = super
@caller ||= env.is_a?(ReadOnlyEnvironment) ? env : ReadOnlyEnvironment.new(env, env.options)
end | ruby | def caller
return @caller if @caller
env = super
@caller ||= env.is_a?(ReadOnlyEnvironment) ? env : ReadOnlyEnvironment.new(env, env.options)
end | [
"def",
"caller",
"return",
"@caller",
"if",
"@caller",
"env",
"=",
"super",
"@caller",
"||=",
"env",
".",
"is_a?",
"(",
"ReadOnlyEnvironment",
")",
"?",
"env",
":",
"ReadOnlyEnvironment",
".",
"new",
"(",
"env",
",",
"env",
".",
"options",
")",
"end"
] | The read-only environment of the caller of this environment's mixin or function.
@see BaseEnvironment#caller
@return {ReadOnlyEnvironment} | [
"The",
"read",
"-",
"only",
"environment",
"of",
"the",
"caller",
"of",
"this",
"environment",
"s",
"mixin",
"or",
"function",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/environment.rb#L186-L190 | train |
sass/ruby-sass | lib/sass/environment.rb | Sass.ReadOnlyEnvironment.content | def content
# Return the cached content from a previous invocation if any
return @content if @content_cached
# get the content with a read-write environment from the superclass
read_write_content = super
if read_write_content
tree, env = read_write_content
# make the content's environment read-only
if env && !env.is_a?(ReadOnlyEnvironment)
env = ReadOnlyEnvironment.new(env, env.options)
end
@content_cached = true
@content = [tree, env]
else
@content_cached = true
@content = nil
end
end | ruby | def content
# Return the cached content from a previous invocation if any
return @content if @content_cached
# get the content with a read-write environment from the superclass
read_write_content = super
if read_write_content
tree, env = read_write_content
# make the content's environment read-only
if env && !env.is_a?(ReadOnlyEnvironment)
env = ReadOnlyEnvironment.new(env, env.options)
end
@content_cached = true
@content = [tree, env]
else
@content_cached = true
@content = nil
end
end | [
"def",
"content",
"return",
"@content",
"if",
"@content_cached",
"read_write_content",
"=",
"super",
"if",
"read_write_content",
"tree",
",",
"env",
"=",
"read_write_content",
"if",
"env",
"&&",
"!",
"env",
".",
"is_a?",
"(",
"ReadOnlyEnvironment",
")",
"env",
"=",
"ReadOnlyEnvironment",
".",
"new",
"(",
"env",
",",
"env",
".",
"options",
")",
"end",
"@content_cached",
"=",
"true",
"@content",
"=",
"[",
"tree",
",",
"env",
"]",
"else",
"@content_cached",
"=",
"true",
"@content",
"=",
"nil",
"end",
"end"
] | The content passed to this environment. If the content's environment isn't already
read-only, it's made read-only.
@see BaseEnvironment#content
@return {[Array<Sass::Tree::Node>, ReadOnlyEnvironment]?} The content nodes and
the lexical environment of the content block.
Returns `nil` when there is no content in this environment. | [
"The",
"content",
"passed",
"to",
"this",
"environment",
".",
"If",
"the",
"content",
"s",
"environment",
"isn",
"t",
"already",
"read",
"-",
"only",
"it",
"s",
"made",
"read",
"-",
"only",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/environment.rb#L200-L217 | train |
sass/ruby-sass | lib/sass/script/tree/interpolation.rb | Sass::Script::Tree.Interpolation.to_string_interpolation | def to_string_interpolation(node_or_interp)
unless node_or_interp.is_a?(Interpolation)
node = node_or_interp
return string_literal(node.value.to_s) if node.is_a?(Literal)
if node.is_a?(StringInterpolation)
return concat(string_literal(node.quote), concat(node, string_literal(node.quote)))
end
return StringInterpolation.new(string_literal(""), node, string_literal(""))
end
interp = node_or_interp
after_string_or_interp =
if interp.after
to_string_interpolation(interp.after)
else
string_literal("")
end
if interp.after && interp.whitespace_after
after_string_or_interp = concat(string_literal(' '), after_string_or_interp)
end
mid_string_or_interp = to_string_interpolation(interp.mid)
before_string_or_interp =
if interp.before
to_string_interpolation(interp.before)
else
string_literal("")
end
if interp.before && interp.whitespace_before
before_string_or_interp = concat(before_string_or_interp, string_literal(' '))
end
concat(before_string_or_interp, concat(mid_string_or_interp, after_string_or_interp))
end | ruby | def to_string_interpolation(node_or_interp)
unless node_or_interp.is_a?(Interpolation)
node = node_or_interp
return string_literal(node.value.to_s) if node.is_a?(Literal)
if node.is_a?(StringInterpolation)
return concat(string_literal(node.quote), concat(node, string_literal(node.quote)))
end
return StringInterpolation.new(string_literal(""), node, string_literal(""))
end
interp = node_or_interp
after_string_or_interp =
if interp.after
to_string_interpolation(interp.after)
else
string_literal("")
end
if interp.after && interp.whitespace_after
after_string_or_interp = concat(string_literal(' '), after_string_or_interp)
end
mid_string_or_interp = to_string_interpolation(interp.mid)
before_string_or_interp =
if interp.before
to_string_interpolation(interp.before)
else
string_literal("")
end
if interp.before && interp.whitespace_before
before_string_or_interp = concat(before_string_or_interp, string_literal(' '))
end
concat(before_string_or_interp, concat(mid_string_or_interp, after_string_or_interp))
end | [
"def",
"to_string_interpolation",
"(",
"node_or_interp",
")",
"unless",
"node_or_interp",
".",
"is_a?",
"(",
"Interpolation",
")",
"node",
"=",
"node_or_interp",
"return",
"string_literal",
"(",
"node",
".",
"value",
".",
"to_s",
")",
"if",
"node",
".",
"is_a?",
"(",
"Literal",
")",
"if",
"node",
".",
"is_a?",
"(",
"StringInterpolation",
")",
"return",
"concat",
"(",
"string_literal",
"(",
"node",
".",
"quote",
")",
",",
"concat",
"(",
"node",
",",
"string_literal",
"(",
"node",
".",
"quote",
")",
")",
")",
"end",
"return",
"StringInterpolation",
".",
"new",
"(",
"string_literal",
"(",
"\"\"",
")",
",",
"node",
",",
"string_literal",
"(",
"\"\"",
")",
")",
"end",
"interp",
"=",
"node_or_interp",
"after_string_or_interp",
"=",
"if",
"interp",
".",
"after",
"to_string_interpolation",
"(",
"interp",
".",
"after",
")",
"else",
"string_literal",
"(",
"\"\"",
")",
"end",
"if",
"interp",
".",
"after",
"&&",
"interp",
".",
"whitespace_after",
"after_string_or_interp",
"=",
"concat",
"(",
"string_literal",
"(",
"' '",
")",
",",
"after_string_or_interp",
")",
"end",
"mid_string_or_interp",
"=",
"to_string_interpolation",
"(",
"interp",
".",
"mid",
")",
"before_string_or_interp",
"=",
"if",
"interp",
".",
"before",
"to_string_interpolation",
"(",
"interp",
".",
"before",
")",
"else",
"string_literal",
"(",
"\"\"",
")",
"end",
"if",
"interp",
".",
"before",
"&&",
"interp",
".",
"whitespace_before",
"before_string_or_interp",
"=",
"concat",
"(",
"before_string_or_interp",
",",
"string_literal",
"(",
"' '",
")",
")",
"end",
"concat",
"(",
"before_string_or_interp",
",",
"concat",
"(",
"mid_string_or_interp",
",",
"after_string_or_interp",
")",
")",
"end"
] | Converts a script node into a corresponding string interpolation
expression.
@param node_or_interp [Sass::Script::Tree::Node]
@return [Sass::Script::Tree::StringInterpolation] | [
"Converts",
"a",
"script",
"node",
"into",
"a",
"corresponding",
"string",
"interpolation",
"expression",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/interpolation.rb#L119-L153 | train |
sass/ruby-sass | lib/sass/script/tree/interpolation.rb | Sass::Script::Tree.Interpolation.concat | def concat(string_or_interp1, string_or_interp2)
if string_or_interp1.is_a?(Literal) && string_or_interp2.is_a?(Literal)
return string_literal(string_or_interp1.value.value + string_or_interp2.value.value)
end
if string_or_interp1.is_a?(Literal)
string = string_or_interp1
interp = string_or_interp2
before = string_literal(string.value.value + interp.before.value.value)
return StringInterpolation.new(before, interp.mid, interp.after)
end
StringInterpolation.new(
string_or_interp1.before,
string_or_interp1.mid,
concat(string_or_interp1.after, string_or_interp2))
end | ruby | def concat(string_or_interp1, string_or_interp2)
if string_or_interp1.is_a?(Literal) && string_or_interp2.is_a?(Literal)
return string_literal(string_or_interp1.value.value + string_or_interp2.value.value)
end
if string_or_interp1.is_a?(Literal)
string = string_or_interp1
interp = string_or_interp2
before = string_literal(string.value.value + interp.before.value.value)
return StringInterpolation.new(before, interp.mid, interp.after)
end
StringInterpolation.new(
string_or_interp1.before,
string_or_interp1.mid,
concat(string_or_interp1.after, string_or_interp2))
end | [
"def",
"concat",
"(",
"string_or_interp1",
",",
"string_or_interp2",
")",
"if",
"string_or_interp1",
".",
"is_a?",
"(",
"Literal",
")",
"&&",
"string_or_interp2",
".",
"is_a?",
"(",
"Literal",
")",
"return",
"string_literal",
"(",
"string_or_interp1",
".",
"value",
".",
"value",
"+",
"string_or_interp2",
".",
"value",
".",
"value",
")",
"end",
"if",
"string_or_interp1",
".",
"is_a?",
"(",
"Literal",
")",
"string",
"=",
"string_or_interp1",
"interp",
"=",
"string_or_interp2",
"before",
"=",
"string_literal",
"(",
"string",
".",
"value",
".",
"value",
"+",
"interp",
".",
"before",
".",
"value",
".",
"value",
")",
"return",
"StringInterpolation",
".",
"new",
"(",
"before",
",",
"interp",
".",
"mid",
",",
"interp",
".",
"after",
")",
"end",
"StringInterpolation",
".",
"new",
"(",
"string_or_interp1",
".",
"before",
",",
"string_or_interp1",
".",
"mid",
",",
"concat",
"(",
"string_or_interp1",
".",
"after",
",",
"string_or_interp2",
")",
")",
"end"
] | Concatenates two string literals or string interpolation expressions.
@param string_or_interp1 [Sass::Script::Tree::Literal|Sass::Script::Tree::StringInterpolation]
@param string_or_interp2 [Sass::Script::Tree::Literal|Sass::Script::Tree::StringInterpolation]
@return [Sass::Script::Tree::StringInterpolation] | [
"Concatenates",
"two",
"string",
"literals",
"or",
"string",
"interpolation",
"expressions",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/interpolation.rb#L194-L210 | train |
sass/ruby-sass | lib/sass/script/tree/interpolation.rb | Sass::Script::Tree.Interpolation.string_literal | def string_literal(string)
Literal.new(Sass::Script::Value::String.new(string, :string))
end | ruby | def string_literal(string)
Literal.new(Sass::Script::Value::String.new(string, :string))
end | [
"def",
"string_literal",
"(",
"string",
")",
"Literal",
".",
"new",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
".",
"new",
"(",
"string",
",",
":string",
")",
")",
"end"
] | Returns a string literal with the given contents.
@param string [String]
@return string [Sass::Script::Tree::Literal] | [
"Returns",
"a",
"string",
"literal",
"with",
"the",
"given",
"contents",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/interpolation.rb#L216-L218 | train |
sass/ruby-sass | lib/sass/exec/sass_scss.rb | Sass::Exec.SassScss.process_result | def process_result
require 'sass'
if !@options[:update] && !@options[:watch] &&
@args.first && colon_path?(@args.first)
if @args.size == 1
@args = split_colon_path(@args.first)
else
@fake_update = true
@options[:update] = true
end
end
load_compass if @options[:compass]
return interactive if @options[:interactive]
return watch_or_update if @options[:watch] || @options[:update]
super
if @options[:sourcemap] != :none && @options[:output_filename]
@options[:sourcemap_filename] = Sass::Util.sourcemap_name(@options[:output_filename])
end
@options[:for_engine][:filename] = @options[:filename]
@options[:for_engine][:css_filename] = @options[:output] if @options[:output].is_a?(String)
@options[:for_engine][:sourcemap_filename] = @options[:sourcemap_filename]
@options[:for_engine][:sourcemap] = @options[:sourcemap]
run
end | ruby | def process_result
require 'sass'
if !@options[:update] && !@options[:watch] &&
@args.first && colon_path?(@args.first)
if @args.size == 1
@args = split_colon_path(@args.first)
else
@fake_update = true
@options[:update] = true
end
end
load_compass if @options[:compass]
return interactive if @options[:interactive]
return watch_or_update if @options[:watch] || @options[:update]
super
if @options[:sourcemap] != :none && @options[:output_filename]
@options[:sourcemap_filename] = Sass::Util.sourcemap_name(@options[:output_filename])
end
@options[:for_engine][:filename] = @options[:filename]
@options[:for_engine][:css_filename] = @options[:output] if @options[:output].is_a?(String)
@options[:for_engine][:sourcemap_filename] = @options[:sourcemap_filename]
@options[:for_engine][:sourcemap] = @options[:sourcemap]
run
end | [
"def",
"process_result",
"require",
"'sass'",
"if",
"!",
"@options",
"[",
":update",
"]",
"&&",
"!",
"@options",
"[",
":watch",
"]",
"&&",
"@args",
".",
"first",
"&&",
"colon_path?",
"(",
"@args",
".",
"first",
")",
"if",
"@args",
".",
"size",
"==",
"1",
"@args",
"=",
"split_colon_path",
"(",
"@args",
".",
"first",
")",
"else",
"@fake_update",
"=",
"true",
"@options",
"[",
":update",
"]",
"=",
"true",
"end",
"end",
"load_compass",
"if",
"@options",
"[",
":compass",
"]",
"return",
"interactive",
"if",
"@options",
"[",
":interactive",
"]",
"return",
"watch_or_update",
"if",
"@options",
"[",
":watch",
"]",
"||",
"@options",
"[",
":update",
"]",
"super",
"if",
"@options",
"[",
":sourcemap",
"]",
"!=",
":none",
"&&",
"@options",
"[",
":output_filename",
"]",
"@options",
"[",
":sourcemap_filename",
"]",
"=",
"Sass",
"::",
"Util",
".",
"sourcemap_name",
"(",
"@options",
"[",
":output_filename",
"]",
")",
"end",
"@options",
"[",
":for_engine",
"]",
"[",
":filename",
"]",
"=",
"@options",
"[",
":filename",
"]",
"@options",
"[",
":for_engine",
"]",
"[",
":css_filename",
"]",
"=",
"@options",
"[",
":output",
"]",
"if",
"@options",
"[",
":output",
"]",
".",
"is_a?",
"(",
"String",
")",
"@options",
"[",
":for_engine",
"]",
"[",
":sourcemap_filename",
"]",
"=",
"@options",
"[",
":sourcemap_filename",
"]",
"@options",
"[",
":for_engine",
"]",
"[",
":sourcemap",
"]",
"=",
"@options",
"[",
":sourcemap",
"]",
"run",
"end"
] | Processes the options set by the command-line arguments,
and runs the Sass compiler appropriately. | [
"Processes",
"the",
"options",
"set",
"by",
"the",
"command",
"-",
"line",
"arguments",
"and",
"runs",
"the",
"Sass",
"compiler",
"appropriately",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/exec/sass_scss.rb#L37-L64 | train |
sass/ruby-sass | lib/sass/deprecation.rb | Sass.Deprecation.warn | def warn(filename, line, column_or_message, message = nil)
return if !@@allow_double_warnings && @seen.add?([filename, line]).nil?
if message
column = column_or_message
else
message = column_or_message
end
location = "line #{line}"
location << ", column #{column}" if column
location << " of #{filename}" if filename
Sass::Util.sass_warn("DEPRECATION WARNING on #{location}:\n#{message}")
end | ruby | def warn(filename, line, column_or_message, message = nil)
return if !@@allow_double_warnings && @seen.add?([filename, line]).nil?
if message
column = column_or_message
else
message = column_or_message
end
location = "line #{line}"
location << ", column #{column}" if column
location << " of #{filename}" if filename
Sass::Util.sass_warn("DEPRECATION WARNING on #{location}:\n#{message}")
end | [
"def",
"warn",
"(",
"filename",
",",
"line",
",",
"column_or_message",
",",
"message",
"=",
"nil",
")",
"return",
"if",
"!",
"@@allow_double_warnings",
"&&",
"@seen",
".",
"add?",
"(",
"[",
"filename",
",",
"line",
"]",
")",
".",
"nil?",
"if",
"message",
"column",
"=",
"column_or_message",
"else",
"message",
"=",
"column_or_message",
"end",
"location",
"=",
"\"line #{line}\"",
"location",
"<<",
"\", column #{column}\"",
"if",
"column",
"location",
"<<",
"\" of #{filename}\"",
"if",
"filename",
"Sass",
"::",
"Util",
".",
"sass_warn",
"(",
"\"DEPRECATION WARNING on #{location}:\\n#{message}\"",
")",
"end"
] | Prints `message` as a deprecation warning associated with `filename`,
`line`, and optionally `column`.
This ensures that only one message will be printed for each line of a
given file.
@overload warn(filename, line, message)
@param filename [String, nil]
@param line [Number]
@param message [String]
@overload warn(filename, line, column, message)
@param filename [String, nil]
@param line [Number]
@param column [Number]
@param message [String] | [
"Prints",
"message",
"as",
"a",
"deprecation",
"warning",
"associated",
"with",
"filename",
"line",
"and",
"optionally",
"column",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/deprecation.rb#L40-L53 | train |
sass/ruby-sass | lib/sass/plugin/compiler.rb | Sass::Plugin.Compiler.update_stylesheets | def update_stylesheets(individual_files = [])
Sass::Plugin.checked_for_updates = true
staleness_checker = StalenessChecker.new(engine_options)
files = file_list(individual_files)
run_updating_stylesheets(files)
updated_stylesheets = []
files.each do |file, css, sourcemap|
# TODO: Does staleness_checker need to check the sourcemap file as well?
if options[:always_update] || staleness_checker.stylesheet_needs_update?(css, file)
# XXX For consistency, this should return the sourcemap too, but it would
# XXX be an API change.
updated_stylesheets << [file, css]
update_stylesheet(file, css, sourcemap)
else
run_not_updating_stylesheet(file, css, sourcemap)
end
end
run_updated_stylesheets(updated_stylesheets)
end | ruby | def update_stylesheets(individual_files = [])
Sass::Plugin.checked_for_updates = true
staleness_checker = StalenessChecker.new(engine_options)
files = file_list(individual_files)
run_updating_stylesheets(files)
updated_stylesheets = []
files.each do |file, css, sourcemap|
# TODO: Does staleness_checker need to check the sourcemap file as well?
if options[:always_update] || staleness_checker.stylesheet_needs_update?(css, file)
# XXX For consistency, this should return the sourcemap too, but it would
# XXX be an API change.
updated_stylesheets << [file, css]
update_stylesheet(file, css, sourcemap)
else
run_not_updating_stylesheet(file, css, sourcemap)
end
end
run_updated_stylesheets(updated_stylesheets)
end | [
"def",
"update_stylesheets",
"(",
"individual_files",
"=",
"[",
"]",
")",
"Sass",
"::",
"Plugin",
".",
"checked_for_updates",
"=",
"true",
"staleness_checker",
"=",
"StalenessChecker",
".",
"new",
"(",
"engine_options",
")",
"files",
"=",
"file_list",
"(",
"individual_files",
")",
"run_updating_stylesheets",
"(",
"files",
")",
"updated_stylesheets",
"=",
"[",
"]",
"files",
".",
"each",
"do",
"|",
"file",
",",
"css",
",",
"sourcemap",
"|",
"if",
"options",
"[",
":always_update",
"]",
"||",
"staleness_checker",
".",
"stylesheet_needs_update?",
"(",
"css",
",",
"file",
")",
"updated_stylesheets",
"<<",
"[",
"file",
",",
"css",
"]",
"update_stylesheet",
"(",
"file",
",",
"css",
",",
"sourcemap",
")",
"else",
"run_not_updating_stylesheet",
"(",
"file",
",",
"css",
",",
"sourcemap",
")",
"end",
"end",
"run_updated_stylesheets",
"(",
"updated_stylesheets",
")",
"end"
] | Updates out-of-date stylesheets.
Checks each Sass/SCSS file in
{file:SASS_REFERENCE.md#template_location-option `:template_location`}
to see if it's been modified more recently than the corresponding CSS file
in {file:SASS_REFERENCE.md#css_location-option `:css_location`}.
If it has, it updates the CSS file.
@param individual_files [Array<(String, String[, String])>]
A list of files to check for updates
**in addition to those specified by the
{file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
The first string in each pair is the location of the Sass/SCSS file,
the second is the location of the CSS file that it should be compiled to.
The third string, if provided, is the location of the Sourcemap file. | [
"Updates",
"out",
"-",
"of",
"-",
"date",
"stylesheets",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/plugin/compiler.rb#L201-L221 | train |
sass/ruby-sass | lib/sass/plugin/compiler.rb | Sass::Plugin.Compiler.file_list | def file_list(individual_files = [])
files = individual_files.map do |tuple|
if engine_options[:sourcemap] == :none
tuple[0..1]
elsif tuple.size < 3
[tuple[0], tuple[1], Sass::Util.sourcemap_name(tuple[1])]
else
tuple.dup
end
end
template_location_array.each do |template_location, css_location|
Sass::Util.glob(File.join(template_location, "**", "[^_]*.s[ca]ss")).sort.each do |file|
# Get the relative path to the file
name = Sass::Util.relative_path_from(file, template_location).to_s
css = css_filename(name, css_location)
sourcemap = Sass::Util.sourcemap_name(css) unless engine_options[:sourcemap] == :none
files << [file, css, sourcemap]
end
end
files
end | ruby | def file_list(individual_files = [])
files = individual_files.map do |tuple|
if engine_options[:sourcemap] == :none
tuple[0..1]
elsif tuple.size < 3
[tuple[0], tuple[1], Sass::Util.sourcemap_name(tuple[1])]
else
tuple.dup
end
end
template_location_array.each do |template_location, css_location|
Sass::Util.glob(File.join(template_location, "**", "[^_]*.s[ca]ss")).sort.each do |file|
# Get the relative path to the file
name = Sass::Util.relative_path_from(file, template_location).to_s
css = css_filename(name, css_location)
sourcemap = Sass::Util.sourcemap_name(css) unless engine_options[:sourcemap] == :none
files << [file, css, sourcemap]
end
end
files
end | [
"def",
"file_list",
"(",
"individual_files",
"=",
"[",
"]",
")",
"files",
"=",
"individual_files",
".",
"map",
"do",
"|",
"tuple",
"|",
"if",
"engine_options",
"[",
":sourcemap",
"]",
"==",
":none",
"tuple",
"[",
"0",
"..",
"1",
"]",
"elsif",
"tuple",
".",
"size",
"<",
"3",
"[",
"tuple",
"[",
"0",
"]",
",",
"tuple",
"[",
"1",
"]",
",",
"Sass",
"::",
"Util",
".",
"sourcemap_name",
"(",
"tuple",
"[",
"1",
"]",
")",
"]",
"else",
"tuple",
".",
"dup",
"end",
"end",
"template_location_array",
".",
"each",
"do",
"|",
"template_location",
",",
"css_location",
"|",
"Sass",
"::",
"Util",
".",
"glob",
"(",
"File",
".",
"join",
"(",
"template_location",
",",
"\"**\"",
",",
"\"[^_]*.s[ca]ss\"",
")",
")",
".",
"sort",
".",
"each",
"do",
"|",
"file",
"|",
"name",
"=",
"Sass",
"::",
"Util",
".",
"relative_path_from",
"(",
"file",
",",
"template_location",
")",
".",
"to_s",
"css",
"=",
"css_filename",
"(",
"name",
",",
"css_location",
")",
"sourcemap",
"=",
"Sass",
"::",
"Util",
".",
"sourcemap_name",
"(",
"css",
")",
"unless",
"engine_options",
"[",
":sourcemap",
"]",
"==",
":none",
"files",
"<<",
"[",
"file",
",",
"css",
",",
"sourcemap",
"]",
"end",
"end",
"files",
"end"
] | Construct a list of files that might need to be compiled
from the provided individual_files and the template_locations.
Note: this method does not cache the results as they can change
across invocations when sass files are added or removed.
@param individual_files [Array<(String, String[, String])>]
A list of files to check for updates
**in addition to those specified by the
{file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
The first string in each pair is the location of the Sass/SCSS file,
the second is the location of the CSS file that it should be compiled to.
The third string, if provided, is the location of the Sourcemap file.
@return [Array<(String, String, String)>]
A list of [sass_file, css_file, sourcemap_file] tuples similar
to what was passed in, but expanded to include the current state
of the directories being updated. | [
"Construct",
"a",
"list",
"of",
"files",
"that",
"might",
"need",
"to",
"be",
"compiled",
"from",
"the",
"provided",
"individual_files",
"and",
"the",
"template_locations",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/plugin/compiler.rb#L240-L261 | train |
sass/ruby-sass | lib/sass/plugin/compiler.rb | Sass::Plugin.Compiler.clean | def clean(individual_files = [])
file_list(individual_files).each do |(_, css_file, sourcemap_file)|
if File.exist?(css_file)
run_deleting_css css_file
File.delete(css_file)
end
if sourcemap_file && File.exist?(sourcemap_file)
run_deleting_sourcemap sourcemap_file
File.delete(sourcemap_file)
end
end
nil
end | ruby | def clean(individual_files = [])
file_list(individual_files).each do |(_, css_file, sourcemap_file)|
if File.exist?(css_file)
run_deleting_css css_file
File.delete(css_file)
end
if sourcemap_file && File.exist?(sourcemap_file)
run_deleting_sourcemap sourcemap_file
File.delete(sourcemap_file)
end
end
nil
end | [
"def",
"clean",
"(",
"individual_files",
"=",
"[",
"]",
")",
"file_list",
"(",
"individual_files",
")",
".",
"each",
"do",
"|",
"(",
"_",
",",
"css_file",
",",
"sourcemap_file",
")",
"|",
"if",
"File",
".",
"exist?",
"(",
"css_file",
")",
"run_deleting_css",
"css_file",
"File",
".",
"delete",
"(",
"css_file",
")",
"end",
"if",
"sourcemap_file",
"&&",
"File",
".",
"exist?",
"(",
"sourcemap_file",
")",
"run_deleting_sourcemap",
"sourcemap_file",
"File",
".",
"delete",
"(",
"sourcemap_file",
")",
"end",
"end",
"nil",
"end"
] | Remove all output files that would be created by calling update_stylesheets, if they exist.
This method runs the deleting_css and deleting_sourcemap callbacks for
the files that are deleted.
@param individual_files [Array<(String, String[, String])>]
A list of files to check for updates
**in addition to those specified by the
{file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
The first string in each pair is the location of the Sass/SCSS file,
the second is the location of the CSS file that it should be compiled to.
The third string, if provided, is the location of the Sourcemap file. | [
"Remove",
"all",
"output",
"files",
"that",
"would",
"be",
"created",
"by",
"calling",
"update_stylesheets",
"if",
"they",
"exist",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/plugin/compiler.rb#L362-L374 | train |
sass/ruby-sass | lib/sass/script/value/color.rb | Sass::Script::Value.Color.with | 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 | ruby | 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 | [
"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",
"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 | [
"Returns",
"a",
"copy",
"of",
"this",
"color",
"with",
"one",
"or",
"more",
"channels",
"changed",
".",
"RGB",
"or",
"HSL",
"colors",
"may",
"be",
"changed",
"but",
"not",
"both",
"at",
"once",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/color.rb#L426-L446 | train |
sass/ruby-sass | lib/sass/script/value/color.rb | Sass::Script::Value.Color.to_s | 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 | ruby | 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 | [
"def",
"to_s",
"(",
"opts",
"=",
"{",
"}",
")",
"return",
"smallest",
"if",
"options",
"[",
":style",
"]",
"==",
":compressed",
"return",
"representation",
"if",
"representation",
"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 | [
"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",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/color.rb#L564-L574 | train |
sass/ruby-sass | lib/sass/source/map.rb | Sass::Source.Map.shift_output_lines | def shift_output_lines(delta)
return if delta == 0
@data.each do |m|
m.output.start_pos.line += delta
m.output.end_pos.line += delta
end
end | ruby | def shift_output_lines(delta)
return if delta == 0
@data.each do |m|
m.output.start_pos.line += delta
m.output.end_pos.line += delta
end
end | [
"def",
"shift_output_lines",
"(",
"delta",
")",
"return",
"if",
"delta",
"==",
"0",
"@data",
".",
"each",
"do",
"|",
"m",
"|",
"m",
".",
"output",
".",
"start_pos",
".",
"line",
"+=",
"delta",
"m",
".",
"output",
".",
"end_pos",
".",
"line",
"+=",
"delta",
"end",
"end"
] | Shifts all output source ranges forward one or more lines.
@param delta [Integer] The number of lines to shift the ranges forward. | [
"Shifts",
"all",
"output",
"source",
"ranges",
"forward",
"one",
"or",
"more",
"lines",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/source/map.rb#L41-L47 | train |
sass/ruby-sass | lib/sass/source/map.rb | Sass::Source.Map.shift_output_offsets | def shift_output_offsets(delta)
return if delta == 0
@data.each do |m|
break if m.output.start_pos.line > 1
m.output.start_pos.offset += delta
m.output.end_pos.offset += delta if m.output.end_pos.line > 1
end
end | ruby | def shift_output_offsets(delta)
return if delta == 0
@data.each do |m|
break if m.output.start_pos.line > 1
m.output.start_pos.offset += delta
m.output.end_pos.offset += delta if m.output.end_pos.line > 1
end
end | [
"def",
"shift_output_offsets",
"(",
"delta",
")",
"return",
"if",
"delta",
"==",
"0",
"@data",
".",
"each",
"do",
"|",
"m",
"|",
"break",
"if",
"m",
".",
"output",
".",
"start_pos",
".",
"line",
">",
"1",
"m",
".",
"output",
".",
"start_pos",
".",
"offset",
"+=",
"delta",
"m",
".",
"output",
".",
"end_pos",
".",
"offset",
"+=",
"delta",
"if",
"m",
".",
"output",
".",
"end_pos",
".",
"line",
">",
"1",
"end",
"end"
] | Shifts any output source ranges that lie on the first line forward one or
more characters on that line.
@param delta [Integer] The number of characters to shift the ranges
forward. | [
"Shifts",
"any",
"output",
"source",
"ranges",
"that",
"lie",
"on",
"the",
"first",
"line",
"forward",
"one",
"or",
"more",
"characters",
"on",
"that",
"line",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/source/map.rb#L54-L61 | train |
sass/ruby-sass | lib/sass/tree/comment_node.rb | Sass::Tree.CommentNode.lines | def lines
@value.inject(0) do |s, e|
next s + e.count("\n") if e.is_a?(String)
next s
end
end | ruby | def lines
@value.inject(0) do |s, e|
next s + e.count("\n") if e.is_a?(String)
next s
end
end | [
"def",
"lines",
"@value",
".",
"inject",
"(",
"0",
")",
"do",
"|",
"s",
",",
"e",
"|",
"next",
"s",
"+",
"e",
".",
"count",
"(",
"\"\\n\"",
")",
"if",
"e",
".",
"is_a?",
"(",
"String",
")",
"next",
"s",
"end",
"end"
] | Returns the number of lines in the comment.
@return [Integer] | [
"Returns",
"the",
"number",
"of",
"lines",
"in",
"the",
"comment",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/tree/comment_node.rb#L63-L68 | train |
sass/ruby-sass | lib/sass/plugin.rb | Sass.Plugin.force_update_stylesheets | def force_update_stylesheets(individual_files = [])
Compiler.new(
options.dup.merge(
:never_update => false,
:always_update => true,
:cache => false)).update_stylesheets(individual_files)
end | ruby | def force_update_stylesheets(individual_files = [])
Compiler.new(
options.dup.merge(
:never_update => false,
:always_update => true,
:cache => false)).update_stylesheets(individual_files)
end | [
"def",
"force_update_stylesheets",
"(",
"individual_files",
"=",
"[",
"]",
")",
"Compiler",
".",
"new",
"(",
"options",
".",
"dup",
".",
"merge",
"(",
":never_update",
"=>",
"false",
",",
":always_update",
"=>",
"true",
",",
":cache",
"=>",
"false",
")",
")",
".",
"update_stylesheets",
"(",
"individual_files",
")",
"end"
] | Updates all stylesheets, even those that aren't out-of-date.
Ignores the cache.
@param individual_files [Array<(String, String)>]
A list of files to check for updates
**in addition to those specified by the
{file:SASS_REFERENCE.md#template_location-option `:template_location` option}.**
The first string in each pair is the location of the Sass/SCSS file,
the second is the location of the CSS file that it should be compiled to.
@see #update_stylesheets | [
"Updates",
"all",
"stylesheets",
"even",
"those",
"that",
"aren",
"t",
"out",
"-",
"of",
"-",
"date",
".",
"Ignores",
"the",
"cache",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/plugin.rb#L95-L101 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.ie_hex_str | def ie_hex_str(color)
assert_type color, :Color, :color
alpha = Sass::Util.round(color.alpha * 255).to_s(16).rjust(2, '0')
identifier("##{alpha}#{color.send(:hex_str)[1..-1]}".upcase)
end | ruby | def ie_hex_str(color)
assert_type color, :Color, :color
alpha = Sass::Util.round(color.alpha * 255).to_s(16).rjust(2, '0')
identifier("##{alpha}#{color.send(:hex_str)[1..-1]}".upcase)
end | [
"def",
"ie_hex_str",
"(",
"color",
")",
"assert_type",
"color",
",",
":Color",
",",
":color",
"alpha",
"=",
"Sass",
"::",
"Util",
".",
"round",
"(",
"color",
".",
"alpha",
"*",
"255",
")",
".",
"to_s",
"(",
"16",
")",
".",
"rjust",
"(",
"2",
",",
"'0'",
")",
"identifier",
"(",
"\"##{alpha}#{color.send(:hex_str)[1..-1]}\"",
".",
"upcase",
")",
"end"
] | Converts a color into the format understood by IE filters.
@example
ie-hex-str(#abc) => #FFAABBCC
ie-hex-str(#3322BB) => #FF3322BB
ie-hex-str(rgba(0, 255, 0, 0.5)) => #8000FF00
@overload ie_hex_str($color)
@param $color [Sass::Script::Value::Color]
@return [Sass::Script::Value::String] The IE-formatted string
representation of the color
@raise [ArgumentError] if `$color` isn't a color | [
"Converts",
"a",
"color",
"into",
"the",
"format",
"understood",
"by",
"IE",
"filters",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1155-L1159 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.adjust_color | def adjust_color(color, kwargs)
assert_type color, :Color, :color
with = Sass::Util.map_hash(
"red" => [-255..255, ""],
"green" => [-255..255, ""],
"blue" => [-255..255, ""],
"hue" => nil,
"saturation" => [-100..100, "%"],
"lightness" => [-100..100, "%"],
"alpha" => [-1..1, ""]
) do |name, (range, units)|
val = kwargs.delete(name)
next unless val
assert_type val, :Number, name
Sass::Util.check_range("$#{name}: Amount", range, val, units) if range
adjusted = color.send(name) + val.value
adjusted = [0, Sass::Util.restrict(adjusted, range)].max if range
[name.to_sym, adjusted]
end
unless kwargs.empty?
name, val = kwargs.to_a.first
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
end
color.with(with)
end | ruby | def adjust_color(color, kwargs)
assert_type color, :Color, :color
with = Sass::Util.map_hash(
"red" => [-255..255, ""],
"green" => [-255..255, ""],
"blue" => [-255..255, ""],
"hue" => nil,
"saturation" => [-100..100, "%"],
"lightness" => [-100..100, "%"],
"alpha" => [-1..1, ""]
) do |name, (range, units)|
val = kwargs.delete(name)
next unless val
assert_type val, :Number, name
Sass::Util.check_range("$#{name}: Amount", range, val, units) if range
adjusted = color.send(name) + val.value
adjusted = [0, Sass::Util.restrict(adjusted, range)].max if range
[name.to_sym, adjusted]
end
unless kwargs.empty?
name, val = kwargs.to_a.first
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
end
color.with(with)
end | [
"def",
"adjust_color",
"(",
"color",
",",
"kwargs",
")",
"assert_type",
"color",
",",
":Color",
",",
":color",
"with",
"=",
"Sass",
"::",
"Util",
".",
"map_hash",
"(",
"\"red\"",
"=>",
"[",
"-",
"255",
"..",
"255",
",",
"\"\"",
"]",
",",
"\"green\"",
"=>",
"[",
"-",
"255",
"..",
"255",
",",
"\"\"",
"]",
",",
"\"blue\"",
"=>",
"[",
"-",
"255",
"..",
"255",
",",
"\"\"",
"]",
",",
"\"hue\"",
"=>",
"nil",
",",
"\"saturation\"",
"=>",
"[",
"-",
"100",
"..",
"100",
",",
"\"%\"",
"]",
",",
"\"lightness\"",
"=>",
"[",
"-",
"100",
"..",
"100",
",",
"\"%\"",
"]",
",",
"\"alpha\"",
"=>",
"[",
"-",
"1",
"..",
"1",
",",
"\"\"",
"]",
")",
"do",
"|",
"name",
",",
"(",
"range",
",",
"units",
")",
"|",
"val",
"=",
"kwargs",
".",
"delete",
"(",
"name",
")",
"next",
"unless",
"val",
"assert_type",
"val",
",",
":Number",
",",
"name",
"Sass",
"::",
"Util",
".",
"check_range",
"(",
"\"$#{name}: Amount\"",
",",
"range",
",",
"val",
",",
"units",
")",
"if",
"range",
"adjusted",
"=",
"color",
".",
"send",
"(",
"name",
")",
"+",
"val",
".",
"value",
"adjusted",
"=",
"[",
"0",
",",
"Sass",
"::",
"Util",
".",
"restrict",
"(",
"adjusted",
",",
"range",
")",
"]",
".",
"max",
"if",
"range",
"[",
"name",
".",
"to_sym",
",",
"adjusted",
"]",
"end",
"unless",
"kwargs",
".",
"empty?",
"name",
",",
"val",
"=",
"kwargs",
".",
"to_a",
".",
"first",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Unknown argument $#{name} (#{val})\"",
")",
"end",
"color",
".",
"with",
"(",
"with",
")",
"end"
] | Increases or decreases one or more properties of a color. This can change
the red, green, blue, hue, saturation, value, and alpha properties. The
properties are specified as keyword arguments, and are added to or
subtracted from the color's current value for that property.
All properties are optional. You can't specify both RGB properties
(`$red`, `$green`, `$blue`) and HSL properties (`$hue`, `$saturation`,
`$value`) at the same time.
@example
adjust-color(#102030, $blue: 5) => #102035
adjust-color(#102030, $red: -5, $blue: 5) => #0b2035
adjust-color(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)
@overload adjust_color($color, [$red], [$green], [$blue], [$hue], [$saturation], [$lightness], [$alpha])
@param $color [Sass::Script::Value::Color]
@param $red [Sass::Script::Value::Number] The adjustment to make on the
red component, between -255 and 255 inclusive
@param $green [Sass::Script::Value::Number] The adjustment to make on the
green component, between -255 and 255 inclusive
@param $blue [Sass::Script::Value::Number] The adjustment to make on the
blue component, between -255 and 255 inclusive
@param $hue [Sass::Script::Value::Number] The adjustment to make on the
hue component, in degrees
@param $saturation [Sass::Script::Value::Number] The adjustment to make on
the saturation component, between `-100%` and `100%` inclusive
@param $lightness [Sass::Script::Value::Number] The adjustment to make on
the lightness component, between `-100%` and `100%` inclusive
@param $alpha [Sass::Script::Value::Number] The adjustment to make on the
alpha component, between -1 and 1 inclusive
@return [Sass::Script::Value::Color]
@raise [ArgumentError] if any parameter is the wrong type or out-of
bounds, or if RGB properties and HSL properties are adjusted at the
same time | [
"Increases",
"or",
"decreases",
"one",
"or",
"more",
"properties",
"of",
"a",
"color",
".",
"This",
"can",
"change",
"the",
"red",
"green",
"blue",
"hue",
"saturation",
"value",
"and",
"alpha",
"properties",
".",
"The",
"properties",
"are",
"specified",
"as",
"keyword",
"arguments",
"and",
"are",
"added",
"to",
"or",
"subtracted",
"from",
"the",
"color",
"s",
"current",
"value",
"for",
"that",
"property",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1195-L1221 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.change_color | def change_color(color, kwargs)
assert_type color, :Color, :color
with = Sass::Util.map_hash(
'red' => ['Red value', 0..255],
'green' => ['Green value', 0..255],
'blue' => ['Blue value', 0..255],
'hue' => [],
'saturation' => ['Saturation', 0..100, '%'],
'lightness' => ['Lightness', 0..100, '%'],
'alpha' => ['Alpha channel', 0..1]
) do |name, (desc, range, unit)|
val = kwargs.delete(name)
next unless val
assert_type val, :Number, name
if range
val = Sass::Util.check_range(desc, range, val, unit)
else
val = val.value
end
[name.to_sym, val]
end
unless kwargs.empty?
name, val = kwargs.to_a.first
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
end
color.with(with)
end | ruby | def change_color(color, kwargs)
assert_type color, :Color, :color
with = Sass::Util.map_hash(
'red' => ['Red value', 0..255],
'green' => ['Green value', 0..255],
'blue' => ['Blue value', 0..255],
'hue' => [],
'saturation' => ['Saturation', 0..100, '%'],
'lightness' => ['Lightness', 0..100, '%'],
'alpha' => ['Alpha channel', 0..1]
) do |name, (desc, range, unit)|
val = kwargs.delete(name)
next unless val
assert_type val, :Number, name
if range
val = Sass::Util.check_range(desc, range, val, unit)
else
val = val.value
end
[name.to_sym, val]
end
unless kwargs.empty?
name, val = kwargs.to_a.first
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
end
color.with(with)
end | [
"def",
"change_color",
"(",
"color",
",",
"kwargs",
")",
"assert_type",
"color",
",",
":Color",
",",
":color",
"with",
"=",
"Sass",
"::",
"Util",
".",
"map_hash",
"(",
"'red'",
"=>",
"[",
"'Red value'",
",",
"0",
"..",
"255",
"]",
",",
"'green'",
"=>",
"[",
"'Green value'",
",",
"0",
"..",
"255",
"]",
",",
"'blue'",
"=>",
"[",
"'Blue value'",
",",
"0",
"..",
"255",
"]",
",",
"'hue'",
"=>",
"[",
"]",
",",
"'saturation'",
"=>",
"[",
"'Saturation'",
",",
"0",
"..",
"100",
",",
"'%'",
"]",
",",
"'lightness'",
"=>",
"[",
"'Lightness'",
",",
"0",
"..",
"100",
",",
"'%'",
"]",
",",
"'alpha'",
"=>",
"[",
"'Alpha channel'",
",",
"0",
"..",
"1",
"]",
")",
"do",
"|",
"name",
",",
"(",
"desc",
",",
"range",
",",
"unit",
")",
"|",
"val",
"=",
"kwargs",
".",
"delete",
"(",
"name",
")",
"next",
"unless",
"val",
"assert_type",
"val",
",",
":Number",
",",
"name",
"if",
"range",
"val",
"=",
"Sass",
"::",
"Util",
".",
"check_range",
"(",
"desc",
",",
"range",
",",
"val",
",",
"unit",
")",
"else",
"val",
"=",
"val",
".",
"value",
"end",
"[",
"name",
".",
"to_sym",
",",
"val",
"]",
"end",
"unless",
"kwargs",
".",
"empty?",
"name",
",",
"val",
"=",
"kwargs",
".",
"to_a",
".",
"first",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Unknown argument $#{name} (#{val})\"",
")",
"end",
"color",
".",
"with",
"(",
"with",
")",
"end"
] | Changes one or more properties of a color. This can change the red, green,
blue, hue, saturation, value, and alpha properties. The properties are
specified as keyword arguments, and replace the color's current value for
that property.
All properties are optional. You can't specify both RGB properties
(`$red`, `$green`, `$blue`) and HSL properties (`$hue`, `$saturation`,
`$value`) at the same time.
@example
change-color(#102030, $blue: 5) => #102005
change-color(#102030, $red: 120, $blue: 5) => #782005
change-color(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)
@overload change_color($color, [$red], [$green], [$blue], [$hue], [$saturation], [$lightness], [$alpha])
@param $color [Sass::Script::Value::Color]
@param $red [Sass::Script::Value::Number] The new red component for the
color, within 0 and 255 inclusive
@param $green [Sass::Script::Value::Number] The new green component for
the color, within 0 and 255 inclusive
@param $blue [Sass::Script::Value::Number] The new blue component for the
color, within 0 and 255 inclusive
@param $hue [Sass::Script::Value::Number] The new hue component for the
color, in degrees
@param $saturation [Sass::Script::Value::Number] The new saturation
component for the color, between `0%` and `100%` inclusive
@param $lightness [Sass::Script::Value::Number] The new lightness
component for the color, within `0%` and `100%` inclusive
@param $alpha [Sass::Script::Value::Number] The new alpha component for
the color, within 0 and 1 inclusive
@return [Sass::Script::Value::Color]
@raise [ArgumentError] if any parameter is the wrong type or out-of
bounds, or if RGB properties and HSL properties are adjusted at the
same time | [
"Changes",
"one",
"or",
"more",
"properties",
"of",
"a",
"color",
".",
"This",
"can",
"change",
"the",
"red",
"green",
"blue",
"hue",
"saturation",
"value",
"and",
"alpha",
"properties",
".",
"The",
"properties",
"are",
"specified",
"as",
"keyword",
"arguments",
"and",
"replace",
"the",
"color",
"s",
"current",
"value",
"for",
"that",
"property",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1327-L1357 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.mix | def mix(color1, color2, weight = number(50))
assert_type color1, :Color, :color1
assert_type color2, :Color, :color2
assert_type weight, :Number, :weight
Sass::Util.check_range("Weight", 0..100, weight, '%')
# This algorithm factors in both the user-provided weight (w) and the
# difference between the alpha values of the two colors (a) to decide how
# to perform the weighted average of the two RGB values.
#
# It works by first normalizing both parameters to be within [-1, 1],
# where 1 indicates "only use color1", -1 indicates "only use color2", and
# all values in between indicated a proportionately weighted average.
#
# Once we have the normalized variables w and a, we apply the formula
# (w + a)/(1 + w*a) to get the combined weight (in [-1, 1]) of color1.
# This formula has two especially nice properties:
#
# * When either w or a are -1 or 1, the combined weight is also that number
# (cases where w * a == -1 are undefined, and handled as a special case).
#
# * When a is 0, the combined weight is w, and vice versa.
#
# Finally, the weight of color1 is renormalized to be within [0, 1]
# and the weight of color2 is given by 1 minus the weight of color1.
p = (weight.value / 100.0).to_f
w = p * 2 - 1
a = color1.alpha - color2.alpha
w1 = ((w * a == -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0
w2 = 1 - w1
rgba = color1.rgb.zip(color2.rgb).map {|v1, v2| v1 * w1 + v2 * w2}
rgba << color1.alpha * p + color2.alpha * (1 - p)
rgb_color(*rgba)
end | ruby | def mix(color1, color2, weight = number(50))
assert_type color1, :Color, :color1
assert_type color2, :Color, :color2
assert_type weight, :Number, :weight
Sass::Util.check_range("Weight", 0..100, weight, '%')
# This algorithm factors in both the user-provided weight (w) and the
# difference between the alpha values of the two colors (a) to decide how
# to perform the weighted average of the two RGB values.
#
# It works by first normalizing both parameters to be within [-1, 1],
# where 1 indicates "only use color1", -1 indicates "only use color2", and
# all values in between indicated a proportionately weighted average.
#
# Once we have the normalized variables w and a, we apply the formula
# (w + a)/(1 + w*a) to get the combined weight (in [-1, 1]) of color1.
# This formula has two especially nice properties:
#
# * When either w or a are -1 or 1, the combined weight is also that number
# (cases where w * a == -1 are undefined, and handled as a special case).
#
# * When a is 0, the combined weight is w, and vice versa.
#
# Finally, the weight of color1 is renormalized to be within [0, 1]
# and the weight of color2 is given by 1 minus the weight of color1.
p = (weight.value / 100.0).to_f
w = p * 2 - 1
a = color1.alpha - color2.alpha
w1 = ((w * a == -1 ? w : (w + a) / (1 + w * a)) + 1) / 2.0
w2 = 1 - w1
rgba = color1.rgb.zip(color2.rgb).map {|v1, v2| v1 * w1 + v2 * w2}
rgba << color1.alpha * p + color2.alpha * (1 - p)
rgb_color(*rgba)
end | [
"def",
"mix",
"(",
"color1",
",",
"color2",
",",
"weight",
"=",
"number",
"(",
"50",
")",
")",
"assert_type",
"color1",
",",
":Color",
",",
":color1",
"assert_type",
"color2",
",",
":Color",
",",
":color2",
"assert_type",
"weight",
",",
":Number",
",",
":weight",
"Sass",
"::",
"Util",
".",
"check_range",
"(",
"\"Weight\"",
",",
"0",
"..",
"100",
",",
"weight",
",",
"'%'",
")",
"p",
"=",
"(",
"weight",
".",
"value",
"/",
"100.0",
")",
".",
"to_f",
"w",
"=",
"p",
"*",
"2",
"-",
"1",
"a",
"=",
"color1",
".",
"alpha",
"-",
"color2",
".",
"alpha",
"w1",
"=",
"(",
"(",
"w",
"*",
"a",
"==",
"-",
"1",
"?",
"w",
":",
"(",
"w",
"+",
"a",
")",
"/",
"(",
"1",
"+",
"w",
"*",
"a",
")",
")",
"+",
"1",
")",
"/",
"2.0",
"w2",
"=",
"1",
"-",
"w1",
"rgba",
"=",
"color1",
".",
"rgb",
".",
"zip",
"(",
"color2",
".",
"rgb",
")",
".",
"map",
"{",
"|",
"v1",
",",
"v2",
"|",
"v1",
"*",
"w1",
"+",
"v2",
"*",
"w2",
"}",
"rgba",
"<<",
"color1",
".",
"alpha",
"*",
"p",
"+",
"color2",
".",
"alpha",
"*",
"(",
"1",
"-",
"p",
")",
"rgb_color",
"(",
"*",
"rgba",
")",
"end"
] | Mixes two colors together. Specifically, takes the average of each of the
RGB components, optionally weighted by the given percentage. The opacity
of the colors is also considered when weighting the components.
The weight specifies the amount of the first color that should be included
in the returned color. The default, `50%`, means that half the first color
and half the second color should be used. `25%` means that a quarter of
the first color and three quarters of the second color should be used.
@example
mix(#f00, #00f) => #7f007f
mix(#f00, #00f, 25%) => #3f00bf
mix(rgba(255, 0, 0, 0.5), #00f) => rgba(63, 0, 191, 0.75)
@overload mix($color1, $color2, $weight: 50%)
@param $color1 [Sass::Script::Value::Color]
@param $color2 [Sass::Script::Value::Color]
@param $weight [Sass::Script::Value::Number] The relative weight of each
color. Closer to `100%` gives more weight to `$color1`, closer to `0%`
gives more weight to `$color2`
@return [Sass::Script::Value::Color]
@raise [ArgumentError] if `$weight` is out of bounds or any parameter is
the wrong type | [
"Mixes",
"two",
"colors",
"together",
".",
"Specifically",
"takes",
"the",
"average",
"of",
"each",
"of",
"the",
"RGB",
"components",
"optionally",
"weighted",
"by",
"the",
"given",
"percentage",
".",
"The",
"opacity",
"of",
"the",
"colors",
"is",
"also",
"considered",
"when",
"weighting",
"the",
"components",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1382-L1418 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.quote | def quote(string)
assert_type string, :String, :string
if string.type != :string
quoted_string(string.value)
else
string
end
end | ruby | def quote(string)
assert_type string, :String, :string
if string.type != :string
quoted_string(string.value)
else
string
end
end | [
"def",
"quote",
"(",
"string",
")",
"assert_type",
"string",
",",
":String",
",",
":string",
"if",
"string",
".",
"type",
"!=",
":string",
"quoted_string",
"(",
"string",
".",
"value",
")",
"else",
"string",
"end",
"end"
] | Add quotes to a string if the string isn't quoted,
or returns the same string if it is.
@see #unquote
@example
quote("foo") => "foo"
quote(foo) => "foo"
@overload quote($string)
@param $string [Sass::Script::Value::String]
@return [Sass::Script::Value::String]
@raise [ArgumentError] if `$string` isn't a string | [
"Add",
"quotes",
"to",
"a",
"string",
"if",
"the",
"string",
"isn",
"t",
"quoted",
"or",
"returns",
"the",
"same",
"string",
"if",
"it",
"is",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1524-L1531 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.to_upper_case | def to_upper_case(string)
assert_type string, :String, :string
Sass::Script::Value::String.new(Sass::Util.upcase(string.value), string.type)
end | ruby | def to_upper_case(string)
assert_type string, :String, :string
Sass::Script::Value::String.new(Sass::Util.upcase(string.value), string.type)
end | [
"def",
"to_upper_case",
"(",
"string",
")",
"assert_type",
"string",
",",
":String",
",",
":string",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
".",
"new",
"(",
"Sass",
"::",
"Util",
".",
"upcase",
"(",
"string",
".",
"value",
")",
",",
"string",
".",
"type",
")",
"end"
] | Converts a string to upper case.
@example
to-upper-case(abcd) => ABCD
@overload to_upper_case($string)
@param $string [Sass::Script::Value::String]
@return [Sass::Script::Value::String]
@raise [ArgumentError] if `$string` isn't a string | [
"Converts",
"a",
"string",
"to",
"upper",
"case",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1659-L1662 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.to_lower_case | def to_lower_case(string)
assert_type string, :String, :string
Sass::Script::Value::String.new(Sass::Util.downcase(string.value), string.type)
end | ruby | def to_lower_case(string)
assert_type string, :String, :string
Sass::Script::Value::String.new(Sass::Util.downcase(string.value), string.type)
end | [
"def",
"to_lower_case",
"(",
"string",
")",
"assert_type",
"string",
",",
":String",
",",
":string",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
".",
"new",
"(",
"Sass",
"::",
"Util",
".",
"downcase",
"(",
"string",
".",
"value",
")",
",",
"string",
".",
"type",
")",
"end"
] | Convert a string to lower case,
@example
to-lower-case(ABCD) => abcd
@overload to_lower_case($string)
@param $string [Sass::Script::Value::String]
@return [Sass::Script::Value::String]
@raise [ArgumentError] if `$string` isn't a string | [
"Convert",
"a",
"string",
"to",
"lower",
"case"
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1674-L1677 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.type_of | def type_of(value)
value.check_deprecated_interp if value.is_a?(Sass::Script::Value::String)
identifier(value.class.name.gsub(/Sass::Script::Value::/, '').downcase)
end | ruby | def type_of(value)
value.check_deprecated_interp if value.is_a?(Sass::Script::Value::String)
identifier(value.class.name.gsub(/Sass::Script::Value::/, '').downcase)
end | [
"def",
"type_of",
"(",
"value",
")",
"value",
".",
"check_deprecated_interp",
"if",
"value",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
")",
"identifier",
"(",
"value",
".",
"class",
".",
"name",
".",
"gsub",
"(",
"/",
"/",
",",
"''",
")",
".",
"downcase",
")",
"end"
] | Returns the type of a value.
@example
type-of(100px) => number
type-of(asdf) => string
type-of("asdf") => string
type-of(true) => bool
type-of(#fff) => color
type-of(blue) => color
type-of(null) => null
type-of(a b c) => list
type-of((a: 1, b: 2)) => map
type-of(get-function("foo")) => function
@overload type_of($value)
@param $value [Sass::Script::Value::Base] The value to inspect
@return [Sass::Script::Value::String] The unquoted string name of the
value's type | [
"Returns",
"the",
"type",
"of",
"a",
"value",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1698-L1701 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.comparable | def comparable(number1, number2)
assert_type number1, :Number, :number1
assert_type number2, :Number, :number2
bool(number1.comparable_to?(number2))
end | ruby | def comparable(number1, number2)
assert_type number1, :Number, :number1
assert_type number2, :Number, :number2
bool(number1.comparable_to?(number2))
end | [
"def",
"comparable",
"(",
"number1",
",",
"number2",
")",
"assert_type",
"number1",
",",
":Number",
",",
":number1",
"assert_type",
"number2",
",",
":Number",
",",
":number2",
"bool",
"(",
"number1",
".",
"comparable_to?",
"(",
"number2",
")",
")",
"end"
] | Returns whether two numbers can added, subtracted, or compared.
@example
comparable(2px, 1px) => true
comparable(100px, 3em) => false
comparable(10cm, 3mm) => true
@overload comparable($number1, $number2)
@param $number1 [Sass::Script::Value::Number]
@param $number2 [Sass::Script::Value::Number]
@return [Sass::Script::Value::Bool]
@raise [ArgumentError] if either parameter is the wrong type | [
"Returns",
"whether",
"two",
"numbers",
"can",
"added",
"subtracted",
"or",
"compared",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1836-L1840 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.percentage | def percentage(number)
unless number.is_a?(Sass::Script::Value::Number) && number.unitless?
raise ArgumentError.new("$number: #{number.inspect} is not a unitless number")
end
number(number.value * 100, '%')
end | ruby | def percentage(number)
unless number.is_a?(Sass::Script::Value::Number) && number.unitless?
raise ArgumentError.new("$number: #{number.inspect} is not a unitless number")
end
number(number.value * 100, '%')
end | [
"def",
"percentage",
"(",
"number",
")",
"unless",
"number",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"Number",
")",
"&&",
"number",
".",
"unitless?",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"$number: #{number.inspect} is not a unitless number\"",
")",
"end",
"number",
"(",
"number",
".",
"value",
"*",
"100",
",",
"'%'",
")",
"end"
] | Converts a unitless number to a percentage.
@example
percentage(0.2) => 20%
percentage(100px / 50px) => 200%
@overload percentage($number)
@param $number [Sass::Script::Value::Number]
@return [Sass::Script::Value::Number]
@raise [ArgumentError] if `$number` isn't a unitless number | [
"Converts",
"a",
"unitless",
"number",
"to",
"a",
"percentage",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1852-L1857 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.min | def min(*numbers)
numbers.each {|n| assert_type n, :Number}
numbers.inject {|min, num| min.lt(num).to_bool ? min : num}
end | ruby | def min(*numbers)
numbers.each {|n| assert_type n, :Number}
numbers.inject {|min, num| min.lt(num).to_bool ? min : num}
end | [
"def",
"min",
"(",
"*",
"numbers",
")",
"numbers",
".",
"each",
"{",
"|",
"n",
"|",
"assert_type",
"n",
",",
":Number",
"}",
"numbers",
".",
"inject",
"{",
"|",
"min",
",",
"num",
"|",
"min",
".",
"lt",
"(",
"num",
")",
".",
"to_bool",
"?",
"min",
":",
"num",
"}",
"end"
] | Finds the minimum of several numbers. This function takes any number of
arguments.
@example
min(1px, 4px) => 1px
min(5em, 3em, 4em) => 3em
@overload min($numbers...)
@param $numbers [[Sass::Script::Value::Number]]
@return [Sass::Script::Value::Number]
@raise [ArgumentError] if any argument isn't a number, or if not all of
the arguments have comparable units | [
"Finds",
"the",
"minimum",
"of",
"several",
"numbers",
".",
"This",
"function",
"takes",
"any",
"number",
"of",
"arguments",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1927-L1930 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.max | def max(*values)
values.each {|v| assert_type v, :Number}
values.inject {|max, val| max.gt(val).to_bool ? max : val}
end | ruby | def max(*values)
values.each {|v| assert_type v, :Number}
values.inject {|max, val| max.gt(val).to_bool ? max : val}
end | [
"def",
"max",
"(",
"*",
"values",
")",
"values",
".",
"each",
"{",
"|",
"v",
"|",
"assert_type",
"v",
",",
":Number",
"}",
"values",
".",
"inject",
"{",
"|",
"max",
",",
"val",
"|",
"max",
".",
"gt",
"(",
"val",
")",
".",
"to_bool",
"?",
"max",
":",
"val",
"}",
"end"
] | Finds the maximum of several numbers. This function takes any number of
arguments.
@example
max(1px, 4px) => 4px
max(5em, 3em, 4em) => 5em
@overload max($numbers...)
@param $numbers [[Sass::Script::Value::Number]]
@return [Sass::Script::Value::Number]
@raise [ArgumentError] if any argument isn't a number, or if not all of
the arguments have comparable units | [
"Finds",
"the",
"maximum",
"of",
"several",
"numbers",
".",
"This",
"function",
"takes",
"any",
"number",
"of",
"arguments",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1944-L1947 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.set_nth | def set_nth(list, n, value)
assert_type n, :Number, :n
Sass::Script::Value::List.assert_valid_index(list, n)
index = n.to_i > 0 ? n.to_i - 1 : n.to_i
new_list = list.to_a.dup
new_list[index] = value
list.with_contents(new_list)
end | ruby | def set_nth(list, n, value)
assert_type n, :Number, :n
Sass::Script::Value::List.assert_valid_index(list, n)
index = n.to_i > 0 ? n.to_i - 1 : n.to_i
new_list = list.to_a.dup
new_list[index] = value
list.with_contents(new_list)
end | [
"def",
"set_nth",
"(",
"list",
",",
"n",
",",
"value",
")",
"assert_type",
"n",
",",
":Number",
",",
":n",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"List",
".",
"assert_valid_index",
"(",
"list",
",",
"n",
")",
"index",
"=",
"n",
".",
"to_i",
">",
"0",
"?",
"n",
".",
"to_i",
"-",
"1",
":",
"n",
".",
"to_i",
"new_list",
"=",
"list",
".",
"to_a",
".",
"dup",
"new_list",
"[",
"index",
"]",
"=",
"value",
"list",
".",
"with_contents",
"(",
"new_list",
")",
"end"
] | Return a new list, based on the list provided, but with the nth
element changed to the value given.
Note that unlike some languages, the first item in a Sass list is number
1, the second number 2, and so forth.
Negative index values address elements in reverse order, starting with the last element
in the list.
@example
set-nth($list: 10px 20px 30px, $n: 2, $value: -20px) => 10px -20px 30px
@overload set-nth($list, $n, $value)
@param $list [Sass::Script::Value::Base] The list that will be copied, having the element
at index `$n` changed.
@param $n [Sass::Script::Value::Number] The index of the item to set.
Negative indices count from the end of the list.
@param $value [Sass::Script::Value::Base] The new value at index `$n`.
@return [Sass::Script::Value::List]
@raise [ArgumentError] if `$n` isn't an integer between 1 and the length
of `$list` | [
"Return",
"a",
"new",
"list",
"based",
"on",
"the",
"list",
"provided",
"but",
"with",
"the",
"nth",
"element",
"changed",
"to",
"the",
"value",
"given",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L1986-L1993 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.nth | def nth(list, n)
assert_type n, :Number, :n
Sass::Script::Value::List.assert_valid_index(list, n)
index = n.to_i > 0 ? n.to_i - 1 : n.to_i
list.to_a[index]
end | ruby | def nth(list, n)
assert_type n, :Number, :n
Sass::Script::Value::List.assert_valid_index(list, n)
index = n.to_i > 0 ? n.to_i - 1 : n.to_i
list.to_a[index]
end | [
"def",
"nth",
"(",
"list",
",",
"n",
")",
"assert_type",
"n",
",",
":Number",
",",
":n",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"List",
".",
"assert_valid_index",
"(",
"list",
",",
"n",
")",
"index",
"=",
"n",
".",
"to_i",
">",
"0",
"?",
"n",
".",
"to_i",
"-",
"1",
":",
"n",
".",
"to_i",
"list",
".",
"to_a",
"[",
"index",
"]",
"end"
] | Gets the nth item in a list.
Note that unlike some languages, the first item in a Sass list is number
1, the second number 2, and so forth.
This can return the nth pair in a map as well.
Negative index values address elements in reverse order, starting with the last element in
the list.
@example
nth(10px 20px 30px, 1) => 10px
nth((Helvetica, Arial, sans-serif), 3) => sans-serif
nth((width: 10px, length: 20px), 2) => length, 20px
@overload nth($list, $n)
@param $list [Sass::Script::Value::Base]
@param $n [Sass::Script::Value::Number] The index of the item to get.
Negative indices count from the end of the list.
@return [Sass::Script::Value::Base]
@raise [ArgumentError] if `$n` isn't an integer between 1 and the length
of `$list` | [
"Gets",
"the",
"nth",
"item",
"in",
"a",
"list",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2017-L2023 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.join | def join(list1, list2,
separator = identifier("auto"), bracketed = identifier("auto"),
kwargs = nil, *rest)
if separator.is_a?(Hash)
kwargs = separator
separator = identifier("auto")
elsif bracketed.is_a?(Hash)
kwargs = bracketed
bracketed = identifier("auto")
elsif rest.last.is_a?(Hash)
rest.unshift kwargs
kwargs = rest.pop
end
unless rest.empty?
# Add 4 to rest.length because we don't want to count the kwargs hash,
# which is always passed.
raise ArgumentError.new("wrong number of arguments (#{rest.length + 4} for 2..4)")
end
if kwargs
separator = kwargs.delete("separator") || separator
bracketed = kwargs.delete("bracketed") || bracketed
unless kwargs.empty?
name, val = kwargs.to_a.first
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
end
end
assert_type separator, :String, :separator
unless %w(auto space comma).include?(separator.value)
raise ArgumentError.new("Separator name must be space, comma, or auto")
end
list(list1.to_a + list2.to_a,
separator:
if separator.value == 'auto'
list1.separator || list2.separator || :space
else
separator.value.to_sym
end,
bracketed:
if bracketed.is_a?(Sass::Script::Value::String) && bracketed.value == 'auto'
list1.bracketed
else
bracketed.to_bool
end)
end | ruby | def join(list1, list2,
separator = identifier("auto"), bracketed = identifier("auto"),
kwargs = nil, *rest)
if separator.is_a?(Hash)
kwargs = separator
separator = identifier("auto")
elsif bracketed.is_a?(Hash)
kwargs = bracketed
bracketed = identifier("auto")
elsif rest.last.is_a?(Hash)
rest.unshift kwargs
kwargs = rest.pop
end
unless rest.empty?
# Add 4 to rest.length because we don't want to count the kwargs hash,
# which is always passed.
raise ArgumentError.new("wrong number of arguments (#{rest.length + 4} for 2..4)")
end
if kwargs
separator = kwargs.delete("separator") || separator
bracketed = kwargs.delete("bracketed") || bracketed
unless kwargs.empty?
name, val = kwargs.to_a.first
raise ArgumentError.new("Unknown argument $#{name} (#{val})")
end
end
assert_type separator, :String, :separator
unless %w(auto space comma).include?(separator.value)
raise ArgumentError.new("Separator name must be space, comma, or auto")
end
list(list1.to_a + list2.to_a,
separator:
if separator.value == 'auto'
list1.separator || list2.separator || :space
else
separator.value.to_sym
end,
bracketed:
if bracketed.is_a?(Sass::Script::Value::String) && bracketed.value == 'auto'
list1.bracketed
else
bracketed.to_bool
end)
end | [
"def",
"join",
"(",
"list1",
",",
"list2",
",",
"separator",
"=",
"identifier",
"(",
"\"auto\"",
")",
",",
"bracketed",
"=",
"identifier",
"(",
"\"auto\"",
")",
",",
"kwargs",
"=",
"nil",
",",
"*",
"rest",
")",
"if",
"separator",
".",
"is_a?",
"(",
"Hash",
")",
"kwargs",
"=",
"separator",
"separator",
"=",
"identifier",
"(",
"\"auto\"",
")",
"elsif",
"bracketed",
".",
"is_a?",
"(",
"Hash",
")",
"kwargs",
"=",
"bracketed",
"bracketed",
"=",
"identifier",
"(",
"\"auto\"",
")",
"elsif",
"rest",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"rest",
".",
"unshift",
"kwargs",
"kwargs",
"=",
"rest",
".",
"pop",
"end",
"unless",
"rest",
".",
"empty?",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"wrong number of arguments (#{rest.length + 4} for 2..4)\"",
")",
"end",
"if",
"kwargs",
"separator",
"=",
"kwargs",
".",
"delete",
"(",
"\"separator\"",
")",
"||",
"separator",
"bracketed",
"=",
"kwargs",
".",
"delete",
"(",
"\"bracketed\"",
")",
"||",
"bracketed",
"unless",
"kwargs",
".",
"empty?",
"name",
",",
"val",
"=",
"kwargs",
".",
"to_a",
".",
"first",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Unknown argument $#{name} (#{val})\"",
")",
"end",
"end",
"assert_type",
"separator",
",",
":String",
",",
":separator",
"unless",
"%w(",
"auto",
"space",
"comma",
")",
".",
"include?",
"(",
"separator",
".",
"value",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Separator name must be space, comma, or auto\"",
")",
"end",
"list",
"(",
"list1",
".",
"to_a",
"+",
"list2",
".",
"to_a",
",",
"separator",
":",
"if",
"separator",
".",
"value",
"==",
"'auto'",
"list1",
".",
"separator",
"||",
"list2",
".",
"separator",
"||",
":space",
"else",
"separator",
".",
"value",
".",
"to_sym",
"end",
",",
"bracketed",
":",
"if",
"bracketed",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
")",
"&&",
"bracketed",
".",
"value",
"==",
"'auto'",
"list1",
".",
"bracketed",
"else",
"bracketed",
".",
"to_bool",
"end",
")",
"end"
] | Joins together two lists into one.
Unless `$separator` is passed, if one list is comma-separated and one is
space-separated, the first parameter's separator is used for the resulting
list. If both lists have fewer than two items, spaces are used for the
resulting list.
Unless `$bracketed` is passed, the resulting list is bracketed if the
first parameter is.
Like all list functions, `join()` returns a new list rather than modifying
its arguments in place.
@example
join(10px 20px, 30px 40px) => 10px 20px 30px 40px
join((blue, red), (#abc, #def)) => blue, red, #abc, #def
join(10px, 20px) => 10px 20px
join(10px, 20px, comma) => 10px, 20px
join((blue, red), (#abc, #def), space) => blue red #abc #def
join([10px], 20px) => [10px 20px]
@overload join($list1, $list2, $separator: auto, $bracketed: auto)
@param $list1 [Sass::Script::Value::Base]
@param $list2 [Sass::Script::Value::Base]
@param $separator [Sass::Script::Value::String] The list separator to use.
If this is `comma` or `space`, that separator will be used. If this is
`auto` (the default), the separator is determined as explained above.
@param $bracketed [Sass::Script::Value::Base] Whether the resulting list
will be bracketed. If this is `auto` (the default), the separator is
determined as explained above.
@return [Sass::Script::Value::List] | [
"Joins",
"together",
"two",
"lists",
"into",
"one",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2056-L2104 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.append | def append(list, val, separator = identifier("auto"))
assert_type separator, :String, :separator
unless %w(auto space comma).include?(separator.value)
raise ArgumentError.new("Separator name must be space, comma, or auto")
end
list.with_contents(list.to_a + [val],
separator:
if separator.value == 'auto'
list.separator || :space
else
separator.value.to_sym
end)
end | ruby | def append(list, val, separator = identifier("auto"))
assert_type separator, :String, :separator
unless %w(auto space comma).include?(separator.value)
raise ArgumentError.new("Separator name must be space, comma, or auto")
end
list.with_contents(list.to_a + [val],
separator:
if separator.value == 'auto'
list.separator || :space
else
separator.value.to_sym
end)
end | [
"def",
"append",
"(",
"list",
",",
"val",
",",
"separator",
"=",
"identifier",
"(",
"\"auto\"",
")",
")",
"assert_type",
"separator",
",",
":String",
",",
":separator",
"unless",
"%w(",
"auto",
"space",
"comma",
")",
".",
"include?",
"(",
"separator",
".",
"value",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Separator name must be space, comma, or auto\"",
")",
"end",
"list",
".",
"with_contents",
"(",
"list",
".",
"to_a",
"+",
"[",
"val",
"]",
",",
"separator",
":",
"if",
"separator",
".",
"value",
"==",
"'auto'",
"list",
".",
"separator",
"||",
":space",
"else",
"separator",
".",
"value",
".",
"to_sym",
"end",
")",
"end"
] | Appends a single value onto the end of a list.
Unless the `$separator` argument is passed, if the list had only one item,
the resulting list will be space-separated.
Like all list functions, `append()` returns a new list rather than
modifying its argument in place.
@example
append(10px 20px, 30px) => 10px 20px 30px
append((blue, red), green) => blue, red, green
append(10px 20px, 30px 40px) => 10px 20px (30px 40px)
append(10px, 20px, comma) => 10px, 20px
append((blue, red), green, space) => blue red green
@overload append($list, $val, $separator: auto)
@param $list [Sass::Script::Value::Base]
@param $val [Sass::Script::Value::Base]
@param $separator [Sass::Script::Value::String] The list separator to use.
If this is `comma` or `space`, that separator will be used. If this is
`auto` (the default), the separator is determined as explained above.
@return [Sass::Script::Value::List] | [
"Appends",
"a",
"single",
"value",
"onto",
"the",
"end",
"of",
"a",
"list",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2131-L2143 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.zip | def zip(*lists)
length = nil
values = []
lists.each do |list|
array = list.to_a
values << array.dup
length = length.nil? ? array.length : [length, array.length].min
end
values.each do |value|
value.slice!(length)
end
new_list_value = values.first.zip(*values[1..-1])
list(new_list_value.map {|list| list(list, :space)}, :comma)
end | ruby | def zip(*lists)
length = nil
values = []
lists.each do |list|
array = list.to_a
values << array.dup
length = length.nil? ? array.length : [length, array.length].min
end
values.each do |value|
value.slice!(length)
end
new_list_value = values.first.zip(*values[1..-1])
list(new_list_value.map {|list| list(list, :space)}, :comma)
end | [
"def",
"zip",
"(",
"*",
"lists",
")",
"length",
"=",
"nil",
"values",
"=",
"[",
"]",
"lists",
".",
"each",
"do",
"|",
"list",
"|",
"array",
"=",
"list",
".",
"to_a",
"values",
"<<",
"array",
".",
"dup",
"length",
"=",
"length",
".",
"nil?",
"?",
"array",
".",
"length",
":",
"[",
"length",
",",
"array",
".",
"length",
"]",
".",
"min",
"end",
"values",
".",
"each",
"do",
"|",
"value",
"|",
"value",
".",
"slice!",
"(",
"length",
")",
"end",
"new_list_value",
"=",
"values",
".",
"first",
".",
"zip",
"(",
"*",
"values",
"[",
"1",
"..",
"-",
"1",
"]",
")",
"list",
"(",
"new_list_value",
".",
"map",
"{",
"|",
"list",
"|",
"list",
"(",
"list",
",",
":space",
")",
"}",
",",
":comma",
")",
"end"
] | Combines several lists into a single multidimensional list. The nth value
of the resulting list is a space separated list of the source lists' nth
values.
The length of the resulting list is the length of the
shortest list.
@example
zip(1px 1px 3px, solid dashed solid, red green blue)
=> 1px solid red, 1px dashed green, 3px solid blue
@overload zip($lists...)
@param $lists [[Sass::Script::Value::Base]]
@return [Sass::Script::Value::List] | [
"Combines",
"several",
"lists",
"into",
"a",
"single",
"multidimensional",
"list",
".",
"The",
"nth",
"value",
"of",
"the",
"resulting",
"list",
"is",
"a",
"space",
"separated",
"list",
"of",
"the",
"source",
"lists",
"nth",
"values",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2160-L2173 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.index | def index(list, value)
index = list.to_a.index {|e| e.eq(value).to_bool}
index ? number(index + 1) : null
end | ruby | def index(list, value)
index = list.to_a.index {|e| e.eq(value).to_bool}
index ? number(index + 1) : null
end | [
"def",
"index",
"(",
"list",
",",
"value",
")",
"index",
"=",
"list",
".",
"to_a",
".",
"index",
"{",
"|",
"e",
"|",
"e",
".",
"eq",
"(",
"value",
")",
".",
"to_bool",
"}",
"index",
"?",
"number",
"(",
"index",
"+",
"1",
")",
":",
"null",
"end"
] | Returns the position of a value within a list. If the value isn't found,
returns `null` instead.
Note that unlike some languages, the first item in a Sass list is number
1, the second number 2, and so forth.
This can return the position of a pair in a map as well.
@example
index(1px solid red, solid) => 2
index(1px solid red, dashed) => null
index((width: 10px, height: 20px), (height 20px)) => 2
@overload index($list, $value)
@param $list [Sass::Script::Value::Base]
@param $value [Sass::Script::Value::Base]
@return [Sass::Script::Value::Number, Sass::Script::Value::Null] The
1-based index of `$value` in `$list`, or `null` | [
"Returns",
"the",
"position",
"of",
"a",
"value",
"within",
"a",
"list",
".",
"If",
"the",
"value",
"isn",
"t",
"found",
"returns",
"null",
"instead",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2193-L2196 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.map_remove | def map_remove(map, *keys)
assert_type map, :Map, :map
hash = map.to_h.dup
hash.delete_if {|key, _| keys.include?(key)}
map(hash)
end | ruby | def map_remove(map, *keys)
assert_type map, :Map, :map
hash = map.to_h.dup
hash.delete_if {|key, _| keys.include?(key)}
map(hash)
end | [
"def",
"map_remove",
"(",
"map",
",",
"*",
"keys",
")",
"assert_type",
"map",
",",
":Map",
",",
":map",
"hash",
"=",
"map",
".",
"to_h",
".",
"dup",
"hash",
".",
"delete_if",
"{",
"|",
"key",
",",
"_",
"|",
"keys",
".",
"include?",
"(",
"key",
")",
"}",
"map",
"(",
"hash",
")",
"end"
] | Returns a new map with keys removed.
Like all map functions, `map-merge()` returns a new map rather than
modifying its arguments in place.
@example
map-remove(("foo": 1, "bar": 2), "bar") => ("foo": 1)
map-remove(("foo": 1, "bar": 2, "baz": 3), "bar", "baz") => ("foo": 1)
map-remove(("foo": 1, "bar": 2), "baz") => ("foo": 1, "bar": 2)
@overload map_remove($map, $keys...)
@param $map [Sass::Script::Value::Map]
@param $keys [[Sass::Script::Value::Base]]
@return [Sass::Script::Value::Map]
@raise [ArgumentError] if `$map` is not a map | [
"Returns",
"a",
"new",
"map",
"with",
"keys",
"removed",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2287-L2292 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.map_has_key | def map_has_key(map, key)
assert_type map, :Map, :map
bool(map.to_h.has_key?(key))
end | ruby | def map_has_key(map, key)
assert_type map, :Map, :map
bool(map.to_h.has_key?(key))
end | [
"def",
"map_has_key",
"(",
"map",
",",
"key",
")",
"assert_type",
"map",
",",
":Map",
",",
":map",
"bool",
"(",
"map",
".",
"to_h",
".",
"has_key?",
"(",
"key",
")",
")",
"end"
] | Returns whether a map has a value associated with a given key.
@example
map-has-key(("foo": 1, "bar": 2), "foo") => true
map-has-key(("foo": 1, "bar": 2), "baz") => false
@overload map_has_key($map, $key)
@param $map [Sass::Script::Value::Map]
@param $key [Sass::Script::Value::Base]
@return [Sass::Script::Value::Bool]
@raise [ArgumentError] if `$map` is not a map | [
"Returns",
"whether",
"a",
"map",
"has",
"a",
"value",
"associated",
"with",
"a",
"given",
"key",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2335-L2338 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.unique_id | def unique_id
generator = Sass::Script::Functions.random_number_generator
Thread.current[:sass_last_unique_id] ||= generator.rand(36**8)
# avoid the temptation of trying to guess the next unique value.
value = (Thread.current[:sass_last_unique_id] += (generator.rand(10) + 1))
# the u makes this a legal identifier if it would otherwise start with a number.
identifier("u" + value.to_s(36).rjust(8, '0'))
end | ruby | def unique_id
generator = Sass::Script::Functions.random_number_generator
Thread.current[:sass_last_unique_id] ||= generator.rand(36**8)
# avoid the temptation of trying to guess the next unique value.
value = (Thread.current[:sass_last_unique_id] += (generator.rand(10) + 1))
# the u makes this a legal identifier if it would otherwise start with a number.
identifier("u" + value.to_s(36).rjust(8, '0'))
end | [
"def",
"unique_id",
"generator",
"=",
"Sass",
"::",
"Script",
"::",
"Functions",
".",
"random_number_generator",
"Thread",
".",
"current",
"[",
":sass_last_unique_id",
"]",
"||=",
"generator",
".",
"rand",
"(",
"36",
"**",
"8",
")",
"value",
"=",
"(",
"Thread",
".",
"current",
"[",
":sass_last_unique_id",
"]",
"+=",
"(",
"generator",
".",
"rand",
"(",
"10",
")",
"+",
"1",
")",
")",
"identifier",
"(",
"\"u\"",
"+",
"value",
".",
"to_s",
"(",
"36",
")",
".",
"rjust",
"(",
"8",
",",
"'0'",
")",
")",
"end"
] | Returns a unique CSS identifier. The identifier is returned as an unquoted
string. The identifier returned is only guaranteed to be unique within the
scope of a single Sass run.
@overload unique_id()
@return [Sass::Script::Value::String] | [
"Returns",
"a",
"unique",
"CSS",
"identifier",
".",
"The",
"identifier",
"is",
"returned",
"as",
"an",
"unquoted",
"string",
".",
"The",
"identifier",
"returned",
"is",
"only",
"guaranteed",
"to",
"be",
"unique",
"within",
"the",
"scope",
"of",
"a",
"single",
"Sass",
"run",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2389-L2396 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.variable_exists | def variable_exists(name)
assert_type name, :String, :name
bool(environment.caller.var(name.value))
end | ruby | def variable_exists(name)
assert_type name, :String, :name
bool(environment.caller.var(name.value))
end | [
"def",
"variable_exists",
"(",
"name",
")",
"assert_type",
"name",
",",
":String",
",",
":name",
"bool",
"(",
"environment",
".",
"caller",
".",
"var",
"(",
"name",
".",
"value",
")",
")",
"end"
] | Check whether a variable with the given name exists in the current
scope or in the global scope.
@example
$a-false-value: false;
variable-exists(a-false-value) => true
variable-exists(a-null-value) => true
variable-exists(nonexistent) => false
@overload variable_exists($name)
@param $name [Sass::Script::Value::String] The name of the variable to
check. The name should not include the `$`.
@return [Sass::Script::Value::Bool] Whether the variable is defined in
the current scope. | [
"Check",
"whether",
"a",
"variable",
"with",
"the",
"given",
"name",
"exists",
"in",
"the",
"current",
"scope",
"or",
"in",
"the",
"global",
"scope",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2486-L2489 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.function_exists | def function_exists(name)
assert_type name, :String, :name
exists = Sass::Script::Functions.callable?(name.value.tr("-", "_"))
exists ||= environment.caller.function(name.value)
bool(exists)
end | ruby | def function_exists(name)
assert_type name, :String, :name
exists = Sass::Script::Functions.callable?(name.value.tr("-", "_"))
exists ||= environment.caller.function(name.value)
bool(exists)
end | [
"def",
"function_exists",
"(",
"name",
")",
"assert_type",
"name",
",",
":String",
",",
":name",
"exists",
"=",
"Sass",
"::",
"Script",
"::",
"Functions",
".",
"callable?",
"(",
"name",
".",
"value",
".",
"tr",
"(",
"\"-\"",
",",
"\"_\"",
")",
")",
"exists",
"||=",
"environment",
".",
"caller",
".",
"function",
"(",
"name",
".",
"value",
")",
"bool",
"(",
"exists",
")",
"end"
] | Check whether a function with the given name exists.
@example
function-exists(lighten) => true
@function myfunc { @return "something"; }
function-exists(myfunc) => true
@overload function_exists($name)
@param name [Sass::Script::Value::String] The name of the function to
check or a function reference.
@return [Sass::Script::Value::Bool] Whether the function is defined. | [
"Check",
"whether",
"a",
"function",
"with",
"the",
"given",
"name",
"exists",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2528-L2533 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.content_exists | def content_exists
# frames.last is the stack frame for this function,
# so we use frames[-2] to get the frame before that.
mixin_frame = environment.stack.frames[-2]
unless mixin_frame && mixin_frame.type == :mixin
raise Sass::SyntaxError.new("Cannot call content-exists() except within a mixin.")
end
bool(!environment.caller.content.nil?)
end | ruby | def content_exists
# frames.last is the stack frame for this function,
# so we use frames[-2] to get the frame before that.
mixin_frame = environment.stack.frames[-2]
unless mixin_frame && mixin_frame.type == :mixin
raise Sass::SyntaxError.new("Cannot call content-exists() except within a mixin.")
end
bool(!environment.caller.content.nil?)
end | [
"def",
"content_exists",
"mixin_frame",
"=",
"environment",
".",
"stack",
".",
"frames",
"[",
"-",
"2",
"]",
"unless",
"mixin_frame",
"&&",
"mixin_frame",
".",
"type",
"==",
":mixin",
"raise",
"Sass",
"::",
"SyntaxError",
".",
"new",
"(",
"\"Cannot call content-exists() except within a mixin.\"",
")",
"end",
"bool",
"(",
"!",
"environment",
".",
"caller",
".",
"content",
".",
"nil?",
")",
"end"
] | Check whether a mixin was passed a content block.
Unless `content-exists()` is called directly from a mixin, an error will be raised.
@example
@mixin needs-content {
@if not content-exists() {
@error "You must pass a content block!"
}
@content;
}
@overload content_exists()
@return [Sass::Script::Value::Bool] Whether a content block was passed to the mixin. | [
"Check",
"whether",
"a",
"mixin",
"was",
"passed",
"a",
"content",
"block",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2568-L2576 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.inspect | def inspect(value)
value.check_deprecated_interp if value.is_a?(Sass::Script::Value::String)
unquoted_string(value.to_sass)
end | ruby | def inspect(value)
value.check_deprecated_interp if value.is_a?(Sass::Script::Value::String)
unquoted_string(value.to_sass)
end | [
"def",
"inspect",
"(",
"value",
")",
"value",
".",
"check_deprecated_interp",
"if",
"value",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
")",
"unquoted_string",
"(",
"value",
".",
"to_sass",
")",
"end"
] | Return a string containing the value as its Sass representation.
@overload inspect($value)
@param $value [Sass::Script::Value::Base] The value to inspect.
@return [Sass::Script::Value::String] A representation of the value as
it would be written in Sass. | [
"Return",
"a",
"string",
"containing",
"the",
"value",
"as",
"its",
"Sass",
"representation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2585-L2588 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.selector_unify | def selector_unify(selector1, selector2)
selector1 = parse_selector(selector1, :selector1)
selector2 = parse_selector(selector2, :selector2)
return null unless (unified = selector1.unify(selector2))
unified.to_sass_script
end | ruby | def selector_unify(selector1, selector2)
selector1 = parse_selector(selector1, :selector1)
selector2 = parse_selector(selector2, :selector2)
return null unless (unified = selector1.unify(selector2))
unified.to_sass_script
end | [
"def",
"selector_unify",
"(",
"selector1",
",",
"selector2",
")",
"selector1",
"=",
"parse_selector",
"(",
"selector1",
",",
":selector1",
")",
"selector2",
"=",
"parse_selector",
"(",
"selector2",
",",
":selector2",
")",
"return",
"null",
"unless",
"(",
"unified",
"=",
"selector1",
".",
"unify",
"(",
"selector2",
")",
")",
"unified",
".",
"to_sass_script",
"end"
] | Unifies two selectors into a single selector that matches only
elements matched by both input selectors. Returns `null` if
there is no such selector.
Like the selector unification done for `@extend`, this doesn't
guarantee that the output selector will match *all* elements
matched by both input selectors. For example, if `.a .b` is
unified with `.x .y`, `.a .x .b.y, .x .a .b.y` will be returned,
but `.a.x .b.y` will not. This avoids exponential output size
while matching all elements that are likely to exist in
practice.
@example
selector-unify(".a", ".b") => .a.b
selector-unify(".a .b", ".x .y") => .a .x .b.y, .x .a .b.y
selector-unify(".a.b", ".b.c") => .a.b.c
selector-unify("#a", "#b") => null
@overload selector_unify($selector1, $selector2)
@param $selector1 [Sass::Script::Value::String, Sass::Script::Value::List]
The first selector to be unified. This can be either a
string, a list of strings, or a list of lists of strings as
returned by `&`.
@param $selector2 [Sass::Script::Value::String, Sass::Script::Value::List]
The second selector to be unified. This can be either a
string, a list of strings, or a list of lists of strings as
returned by `&`.
@return [Sass::Script::Value::List, Sass::Script::Value::Null]
A list of lists of strings representing the result of the
unification, or null if no unification exists. This is in
the same format as a selector returned by `&`. | [
"Unifies",
"two",
"selectors",
"into",
"a",
"single",
"selector",
"that",
"matches",
"only",
"elements",
"matched",
"by",
"both",
"input",
"selectors",
".",
"Returns",
"null",
"if",
"there",
"is",
"no",
"such",
"selector",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2830-L2835 | train |
sass/ruby-sass | lib/sass/script/functions.rb | Sass::Script.Functions.numeric_transformation | def numeric_transformation(value)
assert_type value, :Number, :value
Sass::Script::Value::Number.new(
yield(value.value), value.numerator_units, value.denominator_units)
end | ruby | def numeric_transformation(value)
assert_type value, :Number, :value
Sass::Script::Value::Number.new(
yield(value.value), value.numerator_units, value.denominator_units)
end | [
"def",
"numeric_transformation",
"(",
"value",
")",
"assert_type",
"value",
",",
":Number",
",",
":value",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"Number",
".",
"new",
"(",
"yield",
"(",
"value",
".",
"value",
")",
",",
"value",
".",
"numerator_units",
",",
"value",
".",
"denominator_units",
")",
"end"
] | This method implements the pattern of transforming a numeric value into
another numeric value with the same units.
It yields a number to a block to perform the operation and return a number | [
"This",
"method",
"implements",
"the",
"pattern",
"of",
"transforming",
"a",
"numeric",
"value",
"into",
"another",
"numeric",
"value",
"with",
"the",
"same",
"units",
".",
"It",
"yields",
"a",
"number",
"to",
"a",
"block",
"to",
"perform",
"the",
"operation",
"and",
"return",
"a",
"number"
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/functions.rb#L2895-L2899 | train |
sass/ruby-sass | lib/sass/media.rb | Sass::Media.Query.merge | def merge(other)
m1, t1 = resolved_modifier.downcase, resolved_type.downcase
m2, t2 = other.resolved_modifier.downcase, other.resolved_type.downcase
t1 = t2 if t1.empty?
t2 = t1 if t2.empty?
if (m1 == 'not') ^ (m2 == 'not')
return if t1 == t2
type = m1 == 'not' ? t2 : t1
mod = m1 == 'not' ? m2 : m1
elsif m1 == 'not' && m2 == 'not'
# CSS has no way of representing "neither screen nor print"
return unless t1 == t2
type = t1
mod = 'not'
elsif t1 != t2
return
else # t1 == t2, neither m1 nor m2 are "not"
type = t1
mod = m1.empty? ? m2 : m1
end
Query.new([mod], [type], other.expressions + expressions)
end | ruby | def merge(other)
m1, t1 = resolved_modifier.downcase, resolved_type.downcase
m2, t2 = other.resolved_modifier.downcase, other.resolved_type.downcase
t1 = t2 if t1.empty?
t2 = t1 if t2.empty?
if (m1 == 'not') ^ (m2 == 'not')
return if t1 == t2
type = m1 == 'not' ? t2 : t1
mod = m1 == 'not' ? m2 : m1
elsif m1 == 'not' && m2 == 'not'
# CSS has no way of representing "neither screen nor print"
return unless t1 == t2
type = t1
mod = 'not'
elsif t1 != t2
return
else # t1 == t2, neither m1 nor m2 are "not"
type = t1
mod = m1.empty? ? m2 : m1
end
Query.new([mod], [type], other.expressions + expressions)
end | [
"def",
"merge",
"(",
"other",
")",
"m1",
",",
"t1",
"=",
"resolved_modifier",
".",
"downcase",
",",
"resolved_type",
".",
"downcase",
"m2",
",",
"t2",
"=",
"other",
".",
"resolved_modifier",
".",
"downcase",
",",
"other",
".",
"resolved_type",
".",
"downcase",
"t1",
"=",
"t2",
"if",
"t1",
".",
"empty?",
"t2",
"=",
"t1",
"if",
"t2",
".",
"empty?",
"if",
"(",
"m1",
"==",
"'not'",
")",
"^",
"(",
"m2",
"==",
"'not'",
")",
"return",
"if",
"t1",
"==",
"t2",
"type",
"=",
"m1",
"==",
"'not'",
"?",
"t2",
":",
"t1",
"mod",
"=",
"m1",
"==",
"'not'",
"?",
"m2",
":",
"m1",
"elsif",
"m1",
"==",
"'not'",
"&&",
"m2",
"==",
"'not'",
"return",
"unless",
"t1",
"==",
"t2",
"type",
"=",
"t1",
"mod",
"=",
"'not'",
"elsif",
"t1",
"!=",
"t2",
"return",
"else",
"type",
"=",
"t1",
"mod",
"=",
"m1",
".",
"empty?",
"?",
"m2",
":",
"m1",
"end",
"Query",
".",
"new",
"(",
"[",
"mod",
"]",
",",
"[",
"type",
"]",
",",
"other",
".",
"expressions",
"+",
"expressions",
")",
"end"
] | Merges this query with another. The returned query queries for
the intersection between the two inputs.
Both queries should be resolved.
@param other [Query]
@return [Query?] The merged query, or nil if there is no intersection. | [
"Merges",
"this",
"query",
"with",
"another",
".",
"The",
"returned",
"query",
"queries",
"for",
"the",
"intersection",
"between",
"the",
"two",
"inputs",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/media.rb#L123-L144 | train |
sass/ruby-sass | lib/sass/media.rb | Sass::Media.Query.to_css | def to_css
css = ''
css << resolved_modifier
css << ' ' unless resolved_modifier.empty?
css << resolved_type
css << ' and ' unless resolved_type.empty? || expressions.empty?
css << expressions.map do |e|
# It's possible for there to be script nodes in Expressions even when
# we're converting to CSS in the case where we parsed the document as
# CSS originally (as in css_test.rb).
e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.to_sass : c.to_s}.join
end.join(' and ')
css
end | ruby | def to_css
css = ''
css << resolved_modifier
css << ' ' unless resolved_modifier.empty?
css << resolved_type
css << ' and ' unless resolved_type.empty? || expressions.empty?
css << expressions.map do |e|
# It's possible for there to be script nodes in Expressions even when
# we're converting to CSS in the case where we parsed the document as
# CSS originally (as in css_test.rb).
e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.to_sass : c.to_s}.join
end.join(' and ')
css
end | [
"def",
"to_css",
"css",
"=",
"''",
"css",
"<<",
"resolved_modifier",
"css",
"<<",
"' '",
"unless",
"resolved_modifier",
".",
"empty?",
"css",
"<<",
"resolved_type",
"css",
"<<",
"' and '",
"unless",
"resolved_type",
".",
"empty?",
"||",
"expressions",
".",
"empty?",
"css",
"<<",
"expressions",
".",
"map",
"do",
"|",
"e",
"|",
"e",
".",
"map",
"{",
"|",
"c",
"|",
"c",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Tree",
"::",
"Node",
")",
"?",
"c",
".",
"to_sass",
":",
"c",
".",
"to_s",
"}",
".",
"join",
"end",
".",
"join",
"(",
"' and '",
")",
"css",
"end"
] | Returns the CSS for the media query.
@return [String] | [
"Returns",
"the",
"CSS",
"for",
"the",
"media",
"query",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/media.rb#L149-L162 | train |
sass/ruby-sass | lib/sass/media.rb | Sass::Media.Query.deep_copy | def deep_copy
Query.new(
modifier.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
type.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
expressions.map {|e| e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c}})
end | ruby | def deep_copy
Query.new(
modifier.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
type.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c},
expressions.map {|e| e.map {|c| c.is_a?(Sass::Script::Tree::Node) ? c.deep_copy : c}})
end | [
"def",
"deep_copy",
"Query",
".",
"new",
"(",
"modifier",
".",
"map",
"{",
"|",
"c",
"|",
"c",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Tree",
"::",
"Node",
")",
"?",
"c",
".",
"deep_copy",
":",
"c",
"}",
",",
"type",
".",
"map",
"{",
"|",
"c",
"|",
"c",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Tree",
"::",
"Node",
")",
"?",
"c",
".",
"deep_copy",
":",
"c",
"}",
",",
"expressions",
".",
"map",
"{",
"|",
"e",
"|",
"e",
".",
"map",
"{",
"|",
"c",
"|",
"c",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Tree",
"::",
"Node",
")",
"?",
"c",
".",
"deep_copy",
":",
"c",
"}",
"}",
")",
"end"
] | Returns a deep copy of this query and all its children.
@return [Query] | [
"Returns",
"a",
"deep",
"copy",
"of",
"this",
"query",
"and",
"all",
"its",
"children",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/media.rb#L194-L199 | train |
sass/ruby-sass | lib/sass/script/tree/list_literal.rb | Sass::Script::Tree.ListLiteral.element_needs_parens? | def element_needs_parens?(element)
if element.is_a?(ListLiteral)
return false if element.elements.length < 2
return false if element.bracketed
return Sass::Script::Parser.precedence_of(element.separator || :space) <=
Sass::Script::Parser.precedence_of(separator || :space)
end
return false unless separator == :space
if element.is_a?(UnaryOperation)
return element.operator == :minus || element.operator == :plus
end
return false unless element.is_a?(Operation)
return true unless element.operator == :div
!(is_literal_number?(element.operand1) && is_literal_number?(element.operand2))
end | ruby | def element_needs_parens?(element)
if element.is_a?(ListLiteral)
return false if element.elements.length < 2
return false if element.bracketed
return Sass::Script::Parser.precedence_of(element.separator || :space) <=
Sass::Script::Parser.precedence_of(separator || :space)
end
return false unless separator == :space
if element.is_a?(UnaryOperation)
return element.operator == :minus || element.operator == :plus
end
return false unless element.is_a?(Operation)
return true unless element.operator == :div
!(is_literal_number?(element.operand1) && is_literal_number?(element.operand2))
end | [
"def",
"element_needs_parens?",
"(",
"element",
")",
"if",
"element",
".",
"is_a?",
"(",
"ListLiteral",
")",
"return",
"false",
"if",
"element",
".",
"elements",
".",
"length",
"<",
"2",
"return",
"false",
"if",
"element",
".",
"bracketed",
"return",
"Sass",
"::",
"Script",
"::",
"Parser",
".",
"precedence_of",
"(",
"element",
".",
"separator",
"||",
":space",
")",
"<=",
"Sass",
"::",
"Script",
"::",
"Parser",
".",
"precedence_of",
"(",
"separator",
"||",
":space",
")",
"end",
"return",
"false",
"unless",
"separator",
"==",
":space",
"if",
"element",
".",
"is_a?",
"(",
"UnaryOperation",
")",
"return",
"element",
".",
"operator",
"==",
":minus",
"||",
"element",
".",
"operator",
"==",
":plus",
"end",
"return",
"false",
"unless",
"element",
".",
"is_a?",
"(",
"Operation",
")",
"return",
"true",
"unless",
"element",
".",
"operator",
"==",
":div",
"!",
"(",
"is_literal_number?",
"(",
"element",
".",
"operand1",
")",
"&&",
"is_literal_number?",
"(",
"element",
".",
"operand2",
")",
")",
"end"
] | Returns whether an element in the list should be wrapped in parentheses
when serialized to Sass. | [
"Returns",
"whether",
"an",
"element",
"in",
"the",
"list",
"should",
"be",
"wrapped",
"in",
"parentheses",
"when",
"serialized",
"to",
"Sass",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/list_literal.rb#L87-L104 | train |
sass/ruby-sass | lib/sass/script/tree/list_literal.rb | Sass::Script::Tree.ListLiteral.is_literal_number? | def is_literal_number?(value)
value.is_a?(Literal) &&
value.value.is_a?((Sass::Script::Value::Number)) &&
!value.value.original.nil?
end | ruby | def is_literal_number?(value)
value.is_a?(Literal) &&
value.value.is_a?((Sass::Script::Value::Number)) &&
!value.value.original.nil?
end | [
"def",
"is_literal_number?",
"(",
"value",
")",
"value",
".",
"is_a?",
"(",
"Literal",
")",
"&&",
"value",
".",
"value",
".",
"is_a?",
"(",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"Number",
")",
")",
"&&",
"!",
"value",
".",
"value",
".",
"original",
".",
"nil?",
"end"
] | Returns whether a value is a number literal that shouldn't be divided. | [
"Returns",
"whether",
"a",
"value",
"is",
"a",
"number",
"literal",
"that",
"shouldn",
"t",
"be",
"divided",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/list_literal.rb#L107-L111 | train |
sass/ruby-sass | lib/sass/css.rb | Sass.CSS.build_tree | def build_tree
root = Sass::SCSS::CssParser.new(@template, @options[:filename], nil).parse
parse_selectors(root)
expand_commas(root)
nest_seqs(root)
parent_ref_rules(root)
flatten_rules(root)
bubble_subject(root)
fold_commas(root)
dump_selectors(root)
root
end | ruby | def build_tree
root = Sass::SCSS::CssParser.new(@template, @options[:filename], nil).parse
parse_selectors(root)
expand_commas(root)
nest_seqs(root)
parent_ref_rules(root)
flatten_rules(root)
bubble_subject(root)
fold_commas(root)
dump_selectors(root)
root
end | [
"def",
"build_tree",
"root",
"=",
"Sass",
"::",
"SCSS",
"::",
"CssParser",
".",
"new",
"(",
"@template",
",",
"@options",
"[",
":filename",
"]",
",",
"nil",
")",
".",
"parse",
"parse_selectors",
"(",
"root",
")",
"expand_commas",
"(",
"root",
")",
"nest_seqs",
"(",
"root",
")",
"parent_ref_rules",
"(",
"root",
")",
"flatten_rules",
"(",
"root",
")",
"bubble_subject",
"(",
"root",
")",
"fold_commas",
"(",
"root",
")",
"dump_selectors",
"(",
"root",
")",
"root",
"end"
] | Parses the CSS template and applies various transformations
@return [Tree::Node] The root node of the parsed tree | [
"Parses",
"the",
"CSS",
"template",
"and",
"applies",
"various",
"transformations"
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/css.rb#L76-L87 | train |
sass/ruby-sass | lib/sass/css.rb | Sass.CSS.nest_seqs | def nest_seqs(root)
current_rule = nil
root.children.map! do |child|
unless child.is_a?(Tree::RuleNode)
nest_seqs(child) if child.is_a?(Tree::DirectiveNode)
next child
end
seq = first_seq(child)
seq.members.reject! {|sseq| sseq == "\n"}
first, rest = seq.members.first, seq.members[1..-1]
if current_rule.nil? || first_sseq(current_rule) != first
current_rule = Tree::RuleNode.new([])
current_rule.parsed_rules = make_seq(first)
end
if rest.empty?
current_rule.children += child.children
else
child.parsed_rules = make_seq(*rest)
current_rule << child
end
current_rule
end
root.children.compact!
root.children.uniq!
root.children.each {|v| nest_seqs(v)}
end | ruby | def nest_seqs(root)
current_rule = nil
root.children.map! do |child|
unless child.is_a?(Tree::RuleNode)
nest_seqs(child) if child.is_a?(Tree::DirectiveNode)
next child
end
seq = first_seq(child)
seq.members.reject! {|sseq| sseq == "\n"}
first, rest = seq.members.first, seq.members[1..-1]
if current_rule.nil? || first_sseq(current_rule) != first
current_rule = Tree::RuleNode.new([])
current_rule.parsed_rules = make_seq(first)
end
if rest.empty?
current_rule.children += child.children
else
child.parsed_rules = make_seq(*rest)
current_rule << child
end
current_rule
end
root.children.compact!
root.children.uniq!
root.children.each {|v| nest_seqs(v)}
end | [
"def",
"nest_seqs",
"(",
"root",
")",
"current_rule",
"=",
"nil",
"root",
".",
"children",
".",
"map!",
"do",
"|",
"child",
"|",
"unless",
"child",
".",
"is_a?",
"(",
"Tree",
"::",
"RuleNode",
")",
"nest_seqs",
"(",
"child",
")",
"if",
"child",
".",
"is_a?",
"(",
"Tree",
"::",
"DirectiveNode",
")",
"next",
"child",
"end",
"seq",
"=",
"first_seq",
"(",
"child",
")",
"seq",
".",
"members",
".",
"reject!",
"{",
"|",
"sseq",
"|",
"sseq",
"==",
"\"\\n\"",
"}",
"first",
",",
"rest",
"=",
"seq",
".",
"members",
".",
"first",
",",
"seq",
".",
"members",
"[",
"1",
"..",
"-",
"1",
"]",
"if",
"current_rule",
".",
"nil?",
"||",
"first_sseq",
"(",
"current_rule",
")",
"!=",
"first",
"current_rule",
"=",
"Tree",
"::",
"RuleNode",
".",
"new",
"(",
"[",
"]",
")",
"current_rule",
".",
"parsed_rules",
"=",
"make_seq",
"(",
"first",
")",
"end",
"if",
"rest",
".",
"empty?",
"current_rule",
".",
"children",
"+=",
"child",
".",
"children",
"else",
"child",
".",
"parsed_rules",
"=",
"make_seq",
"(",
"*",
"rest",
")",
"current_rule",
"<<",
"child",
"end",
"current_rule",
"end",
"root",
".",
"children",
".",
"compact!",
"root",
".",
"children",
".",
"uniq!",
"root",
".",
"children",
".",
"each",
"{",
"|",
"v",
"|",
"nest_seqs",
"(",
"v",
")",
"}",
"end"
] | Make rules use nesting so that
foo
color: green
foo bar
color: red
foo baz
color: blue
becomes
foo
color: green
bar
color: red
baz
color: blue
@param root [Tree::Node] The parent node | [
"Make",
"rules",
"use",
"nesting",
"so",
"that"
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/css.rb#L153-L183 | train |
sass/ruby-sass | lib/sass/css.rb | Sass.CSS.parent_ref_rules | def parent_ref_rules(root)
current_rule = nil
root.children.map! do |child|
unless child.is_a?(Tree::RuleNode)
parent_ref_rules(child) if child.is_a?(Tree::DirectiveNode)
next child
end
sseq = first_sseq(child)
next child unless sseq.is_a?(Sass::Selector::SimpleSequence)
firsts, rest = [sseq.members.first], sseq.members[1..-1]
firsts.push rest.shift if firsts.first.is_a?(Sass::Selector::Parent)
last_simple_subject = rest.empty? && sseq.subject?
if current_rule.nil? || first_sseq(current_rule).members != firsts ||
!!first_sseq(current_rule).subject? != !!last_simple_subject
current_rule = Tree::RuleNode.new([])
current_rule.parsed_rules = make_sseq(last_simple_subject, *firsts)
end
if rest.empty?
current_rule.children += child.children
else
rest.unshift Sass::Selector::Parent.new
child.parsed_rules = make_sseq(sseq.subject?, *rest)
current_rule << child
end
current_rule
end
root.children.compact!
root.children.uniq!
root.children.each {|v| parent_ref_rules(v)}
end | ruby | def parent_ref_rules(root)
current_rule = nil
root.children.map! do |child|
unless child.is_a?(Tree::RuleNode)
parent_ref_rules(child) if child.is_a?(Tree::DirectiveNode)
next child
end
sseq = first_sseq(child)
next child unless sseq.is_a?(Sass::Selector::SimpleSequence)
firsts, rest = [sseq.members.first], sseq.members[1..-1]
firsts.push rest.shift if firsts.first.is_a?(Sass::Selector::Parent)
last_simple_subject = rest.empty? && sseq.subject?
if current_rule.nil? || first_sseq(current_rule).members != firsts ||
!!first_sseq(current_rule).subject? != !!last_simple_subject
current_rule = Tree::RuleNode.new([])
current_rule.parsed_rules = make_sseq(last_simple_subject, *firsts)
end
if rest.empty?
current_rule.children += child.children
else
rest.unshift Sass::Selector::Parent.new
child.parsed_rules = make_sseq(sseq.subject?, *rest)
current_rule << child
end
current_rule
end
root.children.compact!
root.children.uniq!
root.children.each {|v| parent_ref_rules(v)}
end | [
"def",
"parent_ref_rules",
"(",
"root",
")",
"current_rule",
"=",
"nil",
"root",
".",
"children",
".",
"map!",
"do",
"|",
"child",
"|",
"unless",
"child",
".",
"is_a?",
"(",
"Tree",
"::",
"RuleNode",
")",
"parent_ref_rules",
"(",
"child",
")",
"if",
"child",
".",
"is_a?",
"(",
"Tree",
"::",
"DirectiveNode",
")",
"next",
"child",
"end",
"sseq",
"=",
"first_sseq",
"(",
"child",
")",
"next",
"child",
"unless",
"sseq",
".",
"is_a?",
"(",
"Sass",
"::",
"Selector",
"::",
"SimpleSequence",
")",
"firsts",
",",
"rest",
"=",
"[",
"sseq",
".",
"members",
".",
"first",
"]",
",",
"sseq",
".",
"members",
"[",
"1",
"..",
"-",
"1",
"]",
"firsts",
".",
"push",
"rest",
".",
"shift",
"if",
"firsts",
".",
"first",
".",
"is_a?",
"(",
"Sass",
"::",
"Selector",
"::",
"Parent",
")",
"last_simple_subject",
"=",
"rest",
".",
"empty?",
"&&",
"sseq",
".",
"subject?",
"if",
"current_rule",
".",
"nil?",
"||",
"first_sseq",
"(",
"current_rule",
")",
".",
"members",
"!=",
"firsts",
"||",
"!",
"!",
"first_sseq",
"(",
"current_rule",
")",
".",
"subject?",
"!=",
"!",
"!",
"last_simple_subject",
"current_rule",
"=",
"Tree",
"::",
"RuleNode",
".",
"new",
"(",
"[",
"]",
")",
"current_rule",
".",
"parsed_rules",
"=",
"make_sseq",
"(",
"last_simple_subject",
",",
"*",
"firsts",
")",
"end",
"if",
"rest",
".",
"empty?",
"current_rule",
".",
"children",
"+=",
"child",
".",
"children",
"else",
"rest",
".",
"unshift",
"Sass",
"::",
"Selector",
"::",
"Parent",
".",
"new",
"child",
".",
"parsed_rules",
"=",
"make_sseq",
"(",
"sseq",
".",
"subject?",
",",
"*",
"rest",
")",
"current_rule",
"<<",
"child",
"end",
"current_rule",
"end",
"root",
".",
"children",
".",
"compact!",
"root",
".",
"children",
".",
"uniq!",
"root",
".",
"children",
".",
"each",
"{",
"|",
"v",
"|",
"parent_ref_rules",
"(",
"v",
")",
"}",
"end"
] | Make rules use parent refs so that
foo
color: green
foo.bar
color: blue
becomes
foo
color: green
&.bar
color: blue
@param root [Tree::Node] The parent node | [
"Make",
"rules",
"use",
"parent",
"refs",
"so",
"that"
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/css.rb#L200-L235 | train |
sass/ruby-sass | lib/sass/css.rb | Sass.CSS.flatten_rules | def flatten_rules(root)
root.children.each do |child|
case child
when Tree::RuleNode
flatten_rule(child)
when Tree::DirectiveNode
flatten_rules(child)
end
end
end | ruby | def flatten_rules(root)
root.children.each do |child|
case child
when Tree::RuleNode
flatten_rule(child)
when Tree::DirectiveNode
flatten_rules(child)
end
end
end | [
"def",
"flatten_rules",
"(",
"root",
")",
"root",
".",
"children",
".",
"each",
"do",
"|",
"child",
"|",
"case",
"child",
"when",
"Tree",
"::",
"RuleNode",
"flatten_rule",
"(",
"child",
")",
"when",
"Tree",
"::",
"DirectiveNode",
"flatten_rules",
"(",
"child",
")",
"end",
"end",
"end"
] | Flatten rules so that
foo
bar
color: red
becomes
foo bar
color: red
and
foo
&.bar
color: blue
becomes
foo.bar
color: blue
@param root [Tree::Node] The parent node | [
"Flatten",
"rules",
"so",
"that"
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/css.rb#L260-L269 | train |
sass/ruby-sass | lib/sass/css.rb | Sass.CSS.flatten_rule | def flatten_rule(rule)
while rule.children.size == 1 && rule.children.first.is_a?(Tree::RuleNode)
child = rule.children.first
if first_simple_sel(child).is_a?(Sass::Selector::Parent)
rule.parsed_rules = child.parsed_rules.resolve_parent_refs(rule.parsed_rules)
else
rule.parsed_rules = make_seq(*(first_seq(rule).members + first_seq(child).members))
end
rule.children = child.children
end
flatten_rules(rule)
end | ruby | def flatten_rule(rule)
while rule.children.size == 1 && rule.children.first.is_a?(Tree::RuleNode)
child = rule.children.first
if first_simple_sel(child).is_a?(Sass::Selector::Parent)
rule.parsed_rules = child.parsed_rules.resolve_parent_refs(rule.parsed_rules)
else
rule.parsed_rules = make_seq(*(first_seq(rule).members + first_seq(child).members))
end
rule.children = child.children
end
flatten_rules(rule)
end | [
"def",
"flatten_rule",
"(",
"rule",
")",
"while",
"rule",
".",
"children",
".",
"size",
"==",
"1",
"&&",
"rule",
".",
"children",
".",
"first",
".",
"is_a?",
"(",
"Tree",
"::",
"RuleNode",
")",
"child",
"=",
"rule",
".",
"children",
".",
"first",
"if",
"first_simple_sel",
"(",
"child",
")",
".",
"is_a?",
"(",
"Sass",
"::",
"Selector",
"::",
"Parent",
")",
"rule",
".",
"parsed_rules",
"=",
"child",
".",
"parsed_rules",
".",
"resolve_parent_refs",
"(",
"rule",
".",
"parsed_rules",
")",
"else",
"rule",
".",
"parsed_rules",
"=",
"make_seq",
"(",
"*",
"(",
"first_seq",
"(",
"rule",
")",
".",
"members",
"+",
"first_seq",
"(",
"child",
")",
".",
"members",
")",
")",
"end",
"rule",
".",
"children",
"=",
"child",
".",
"children",
"end",
"flatten_rules",
"(",
"rule",
")",
"end"
] | Flattens a single rule.
@param rule [Tree::RuleNode] The candidate for flattening
@see #flatten_rules | [
"Flattens",
"a",
"single",
"rule",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/css.rb#L275-L289 | train |
sass/ruby-sass | lib/sass/tree/visitors/base.rb | Sass::Tree::Visitors.Base.visit | def visit(node)
if respond_to?(node.class.visit_method, true)
send(node.class.visit_method, node) {visit_children(node)}
else
visit_children(node)
end
end | ruby | def visit(node)
if respond_to?(node.class.visit_method, true)
send(node.class.visit_method, node) {visit_children(node)}
else
visit_children(node)
end
end | [
"def",
"visit",
"(",
"node",
")",
"if",
"respond_to?",
"(",
"node",
".",
"class",
".",
"visit_method",
",",
"true",
")",
"send",
"(",
"node",
".",
"class",
".",
"visit_method",
",",
"node",
")",
"{",
"visit_children",
"(",
"node",
")",
"}",
"else",
"visit_children",
"(",
"node",
")",
"end",
"end"
] | Runs the visitor on the given node.
This can be overridden by subclasses that need to do something for each node.
@param node [Tree::Node] The node to visit.
@return [Object] The return value of the `visit_*` method for this node. | [
"Runs",
"the",
"visitor",
"on",
"the",
"given",
"node",
".",
"This",
"can",
"be",
"overridden",
"by",
"subclasses",
"that",
"need",
"to",
"do",
"something",
"for",
"each",
"node",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/tree/visitors/base.rb#L34-L40 | train |
sass/ruby-sass | lib/sass/exec/sass_convert.rb | Sass::Exec.SassConvert.process_result | def process_result
require 'sass'
if @options[:recursive]
process_directory
return
end
super
input = @options[:input]
if File.directory?(input)
raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)"
end
output = @options[:output]
output = input if @options[:in_place]
process_file(input, output)
end | ruby | def process_result
require 'sass'
if @options[:recursive]
process_directory
return
end
super
input = @options[:input]
if File.directory?(input)
raise "Error: '#{input.path}' is a directory (did you mean to use --recursive?)"
end
output = @options[:output]
output = input if @options[:in_place]
process_file(input, output)
end | [
"def",
"process_result",
"require",
"'sass'",
"if",
"@options",
"[",
":recursive",
"]",
"process_directory",
"return",
"end",
"super",
"input",
"=",
"@options",
"[",
":input",
"]",
"if",
"File",
".",
"directory?",
"(",
"input",
")",
"raise",
"\"Error: '#{input.path}' is a directory (did you mean to use --recursive?)\"",
"end",
"output",
"=",
"@options",
"[",
":output",
"]",
"output",
"=",
"input",
"if",
"@options",
"[",
":in_place",
"]",
"process_file",
"(",
"input",
",",
"output",
")",
"end"
] | Processes the options set by the command-line arguments,
and runs the CSS compiler appropriately. | [
"Processes",
"the",
"options",
"set",
"by",
"the",
"command",
"-",
"line",
"arguments",
"and",
"runs",
"the",
"CSS",
"compiler",
"appropriately",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/exec/sass_convert.rb#L36-L52 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.mod | 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 | ruby | 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 | [
"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 | [
"The",
"SassScript",
"%",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L190-L197 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.eq | 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 | ruby | 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 | [
"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 | [
"The",
"SassScript",
"==",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L203-L216 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.gt | def gt(other)
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
operate(other, :>)
end | ruby | def gt(other)
raise NoMethodError.new(nil, :gt) unless other.is_a?(Number)
operate(other, :>)
end | [
"def",
"gt",
"(",
"other",
")",
"raise",
"NoMethodError",
".",
"new",
"(",
"nil",
",",
":gt",
")",
"unless",
"other",
".",
"is_a?",
"(",
"Number",
")",
"operate",
"(",
"other",
",",
":>",
")",
"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.
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 | [
"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",
".",
"The",
"SassScript",
">",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L235-L238 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.gte | def gte(other)
raise NoMethodError.new(nil, :gte) unless other.is_a?(Number)
operate(other, :>=)
end | ruby | def gte(other)
raise NoMethodError.new(nil, :gte) unless other.is_a?(Number)
operate(other, :>=)
end | [
"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 | [
"The",
"SassScript",
">",
"=",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L245-L248 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.lt | def lt(other)
raise NoMethodError.new(nil, :lt) unless other.is_a?(Number)
operate(other, :<)
end | ruby | def lt(other)
raise NoMethodError.new(nil, :lt) unless other.is_a?(Number)
operate(other, :<)
end | [
"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 | [
"The",
"SassScript",
"<",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L255-L258 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.lte | def lte(other)
raise NoMethodError.new(nil, :lte) unless other.is_a?(Number)
operate(other, :<=)
end | ruby | def lte(other)
raise NoMethodError.new(nil, :lte) unless other.is_a?(Number)
operate(other, :<=)
end | [
"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 | [
"The",
"SassScript",
"<",
"=",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L265-L268 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.inspect | 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 | ruby | 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 | [
"def",
"inspect",
"(",
"opts",
"=",
"{",
"}",
")",
"return",
"original",
"if",
"original",
"value",
"=",
"self",
".",
"class",
".",
"round",
"(",
"self",
".",
"value",
")",
"str",
"=",
"value",
".",
"to_s",
"str",
"=",
"(",
"\"%0.#{self.class.precision}f\"",
"%",
"value",
")",
".",
"gsub",
"(",
"/",
"/",
",",
"''",
")",
"if",
"str",
".",
"include?",
"(",
"'e'",
")",
"if",
"str",
"=~",
"/",
"\\.",
"/",
"str",
"=",
"$1",
"end",
"if",
"@options",
"&&",
"options",
"[",
":style",
"]",
"==",
":compressed",
"str",
".",
"sub!",
"(",
"/",
"\\.",
"/",
",",
"'\\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 | [
"Returns",
"a",
"readable",
"representation",
"of",
"this",
"number",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L285-L307 | train |
sass/ruby-sass | lib/sass/script/value/number.rb | Sass::Script::Value.Number.is_unit? | def is_unit?(unit)
if unit
denominator_units.size == 0 && numerator_units.size == 1 && numerator_units.first == unit
else
unitless?
end
end | ruby | def is_unit?(unit)
if unit
denominator_units.size == 0 && numerator_units.size == 1 && numerator_units.first == unit
else
unitless?
end
end | [
"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. | [
"Checks",
"whether",
"the",
"number",
"has",
"the",
"numerator",
"unit",
"specified",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/number.rb#L337-L343 | train |
sass/ruby-sass | lib/sass/script/value/base.rb | Sass::Script::Value.Base.plus | def plus(other)
type = other.is_a?(Sass::Script::Value::String) ? other.type : :identifier
Sass::Script::Value::String.new(to_s(:quote => :none) + other.to_s(:quote => :none), type)
end | ruby | def plus(other)
type = other.is_a?(Sass::Script::Value::String) ? other.type : :identifier
Sass::Script::Value::String.new(to_s(:quote => :none) + other.to_s(:quote => :none), type)
end | [
"def",
"plus",
"(",
"other",
")",
"type",
"=",
"other",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
")",
"?",
"other",
".",
"type",
":",
":identifier",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"String",
".",
"new",
"(",
"to_s",
"(",
":quote",
"=>",
":none",
")",
"+",
"other",
".",
"to_s",
"(",
":quote",
"=>",
":none",
")",
",",
"type",
")",
"end"
] | The SassScript `+` operation.
@param other [Value] The right-hand side of the operator
@return [Script::Value::String] A string containing both values
without any separation | [
"The",
"SassScript",
"+",
"operation",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/base.rb#L99-L102 | train |
sass/ruby-sass | lib/sass/script/value/base.rb | Sass::Script::Value.Base.with_contents | def with_contents(contents, separator: self.separator, bracketed: self.bracketed)
Sass::Script::Value::List.new(contents, separator: separator, bracketed: bracketed)
end | ruby | def with_contents(contents, separator: self.separator, bracketed: self.bracketed)
Sass::Script::Value::List.new(contents, separator: separator, bracketed: bracketed)
end | [
"def",
"with_contents",
"(",
"contents",
",",
"separator",
":",
"self",
".",
"separator",
",",
"bracketed",
":",
"self",
".",
"bracketed",
")",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"List",
".",
"new",
"(",
"contents",
",",
"separator",
":",
"separator",
",",
"bracketed",
":",
"bracketed",
")",
"end"
] | Creates a new list containing `contents` but with the same brackets and
separators as this object, when interpreted as a list.
@param contents [Array<Value>] The contents of the new list.
@param separator [Symbol] The separator of the new list. Defaults to \{#separator}.
@param bracketed [Boolean] Whether the new list is bracketed. Defaults to \{#bracketed}.
@return [Sass::Script::Value::List] | [
"Creates",
"a",
"new",
"list",
"containing",
"contents",
"but",
"with",
"the",
"same",
"brackets",
"and",
"separators",
"as",
"this",
"object",
"when",
"interpreted",
"as",
"a",
"list",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/base.rb#L244-L246 | train |
sass/ruby-sass | lib/sass/script/tree/variable.rb | Sass::Script::Tree.Variable._perform | def _perform(environment)
val = environment.var(name)
raise Sass::SyntaxError.new("Undefined variable: \"$#{name}\".") unless val
if val.is_a?(Sass::Script::Value::Number) && val.original
val = val.dup
val.original = nil
end
val
end | ruby | def _perform(environment)
val = environment.var(name)
raise Sass::SyntaxError.new("Undefined variable: \"$#{name}\".") unless val
if val.is_a?(Sass::Script::Value::Number) && val.original
val = val.dup
val.original = nil
end
val
end | [
"def",
"_perform",
"(",
"environment",
")",
"val",
"=",
"environment",
".",
"var",
"(",
"name",
")",
"raise",
"Sass",
"::",
"SyntaxError",
".",
"new",
"(",
"\"Undefined variable: \\\"$#{name}\\\".\"",
")",
"unless",
"val",
"if",
"val",
".",
"is_a?",
"(",
"Sass",
"::",
"Script",
"::",
"Value",
"::",
"Number",
")",
"&&",
"val",
".",
"original",
"val",
"=",
"val",
".",
"dup",
"val",
".",
"original",
"=",
"nil",
"end",
"val",
"end"
] | Evaluates the variable.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript
@return [Sass::Script::Value] The SassScript object that is the value of the variable
@raise [Sass::SyntaxError] if the variable is undefined | [
"Evaluates",
"the",
"variable",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/tree/variable.rb#L47-L55 | train |
sass/ruby-sass | lib/sass/exec/base.rb | Sass::Exec.Base.get_line | def get_line(exception)
# SyntaxErrors have weird line reporting
# when there's trailing whitespace
if exception.is_a?(::SyntaxError)
return (exception.message.scan(/:(\d+)/).first || ["??"]).first
end
(exception.backtrace[0].scan(/:(\d+)/).first || ["??"]).first
end | ruby | def get_line(exception)
# SyntaxErrors have weird line reporting
# when there's trailing whitespace
if exception.is_a?(::SyntaxError)
return (exception.message.scan(/:(\d+)/).first || ["??"]).first
end
(exception.backtrace[0].scan(/:(\d+)/).first || ["??"]).first
end | [
"def",
"get_line",
"(",
"exception",
")",
"if",
"exception",
".",
"is_a?",
"(",
"::",
"SyntaxError",
")",
"return",
"(",
"exception",
".",
"message",
".",
"scan",
"(",
"/",
"\\d",
"/",
")",
".",
"first",
"||",
"[",
"\"??\"",
"]",
")",
".",
"first",
"end",
"(",
"exception",
".",
"backtrace",
"[",
"0",
"]",
".",
"scan",
"(",
"/",
"\\d",
"/",
")",
".",
"first",
"||",
"[",
"\"??\"",
"]",
")",
".",
"first",
"end"
] | Finds the line of the source template
on which an exception was raised.
@param exception [Exception] The exception
@return [String] The line number | [
"Finds",
"the",
"line",
"of",
"the",
"source",
"template",
"on",
"which",
"an",
"exception",
"was",
"raised",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/exec/base.rb#L67-L74 | train |
sass/ruby-sass | lib/sass/exec/base.rb | Sass::Exec.Base.encoding_option | def encoding_option(opts)
encoding_desc = 'Specify the default encoding for input files.'
opts.on('-E', '--default-encoding ENCODING', encoding_desc) do |encoding|
Encoding.default_external = encoding
end
end | ruby | def encoding_option(opts)
encoding_desc = 'Specify the default encoding for input files.'
opts.on('-E', '--default-encoding ENCODING', encoding_desc) do |encoding|
Encoding.default_external = encoding
end
end | [
"def",
"encoding_option",
"(",
"opts",
")",
"encoding_desc",
"=",
"'Specify the default encoding for input files.'",
"opts",
".",
"on",
"(",
"'-E'",
",",
"'--default-encoding ENCODING'",
",",
"encoding_desc",
")",
"do",
"|",
"encoding",
"|",
"Encoding",
".",
"default_external",
"=",
"encoding",
"end",
"end"
] | Set an option for specifying `Encoding.default_external`.
@param opts [OptionParser] | [
"Set",
"an",
"option",
"for",
"specifying",
"Encoding",
".",
"default_external",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/exec/base.rb#L90-L95 | train |
sass/ruby-sass | lib/sass/exec/base.rb | Sass::Exec.Base.color | def color(color, str)
raise "[BUG] Unrecognized color #{color}" unless COLORS[color]
# Almost any real Unix terminal will support color,
# so we just filter for Windows terms (which don't set TERM)
# and not-real terminals, which aren't ttys.
return str if ENV["TERM"].nil? || ENV["TERM"].empty? || !STDOUT.tty?
"\e[#{COLORS[color]}m#{str}\e[0m"
end | ruby | def color(color, str)
raise "[BUG] Unrecognized color #{color}" unless COLORS[color]
# Almost any real Unix terminal will support color,
# so we just filter for Windows terms (which don't set TERM)
# and not-real terminals, which aren't ttys.
return str if ENV["TERM"].nil? || ENV["TERM"].empty? || !STDOUT.tty?
"\e[#{COLORS[color]}m#{str}\e[0m"
end | [
"def",
"color",
"(",
"color",
",",
"str",
")",
"raise",
"\"[BUG] Unrecognized color #{color}\"",
"unless",
"COLORS",
"[",
"color",
"]",
"return",
"str",
"if",
"ENV",
"[",
"\"TERM\"",
"]",
".",
"nil?",
"||",
"ENV",
"[",
"\"TERM\"",
"]",
".",
"empty?",
"||",
"!",
"STDOUT",
".",
"tty?",
"\"\\e[#{COLORS[color]}m#{str}\\e[0m\"",
"end"
] | Wraps the given string in terminal escapes
causing it to have the given color.
If terminal escapes aren't supported on this platform,
just returns the string instead.
@param color [Symbol] The name of the color to use.
Can be `:red`, `:green`, or `:yellow`.
@param str [String] The string to wrap in the given color.
@return [String] The wrapped string. | [
"Wraps",
"the",
"given",
"string",
"in",
"terminal",
"escapes",
"causing",
"it",
"to",
"have",
"the",
"given",
"color",
".",
"If",
"terminal",
"escapes",
"aren",
"t",
"supported",
"on",
"this",
"platform",
"just",
"returns",
"the",
"string",
"instead",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/exec/base.rb#L148-L156 | train |
sass/ruby-sass | lib/sass/script/value/helpers.rb | Sass::Script::Value.Helpers.hsl_color | def hsl_color(hue, saturation, lightness, alpha = nil)
attrs = {:hue => hue, :saturation => saturation, :lightness => lightness}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end | ruby | def hsl_color(hue, saturation, lightness, alpha = nil)
attrs = {:hue => hue, :saturation => saturation, :lightness => lightness}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end | [
"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 | [
"Construct",
"a",
"Sass",
"Color",
"from",
"hsl",
"values",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/helpers.rb#L34-L38 | train |
sass/ruby-sass | lib/sass/script/value/helpers.rb | Sass::Script::Value.Helpers.rgb_color | def rgb_color(red, green, blue, alpha = nil)
attrs = {:red => red, :green => green, :blue => blue}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end | ruby | def rgb_color(red, green, blue, alpha = nil)
attrs = {:red => red, :green => green, :blue => blue}
attrs[:alpha] = alpha if alpha
Color.new(attrs)
end | [
"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 | [
"Construct",
"a",
"Sass",
"Color",
"from",
"rgb",
"values",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/helpers.rb#L48-L52 | train |
sass/ruby-sass | lib/sass/script/value/helpers.rb | Sass::Script::Value.Helpers.parse_selector | 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 | ruby | 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 | [
"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. | [
"Parses",
"a",
"user",
"-",
"provided",
"selector",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/helpers.rb#L145-L154 | train |
sass/ruby-sass | lib/sass/script/value/helpers.rb | Sass::Script::Value.Helpers.parse_complex_selector | 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 | ruby | 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 | [
"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. | [
"Parses",
"a",
"user",
"-",
"provided",
"complex",
"selector",
"."
] | 7a50eae567260a23d3bbf4d5aaf1a76db43dec32 | https://github.com/sass/ruby-sass/blob/7a50eae567260a23d3bbf4d5aaf1a76db43dec32/lib/sass/script/value/helpers.rb#L170-L177 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.