code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def 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]
deep_copy
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/media.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/media.rb
Apache-2.0
def check_for_updates return unless !Sass::Plugin.checked_for_updates || Sass::Plugin.options[:always_update] || Sass::Plugin.options[:always_check] update_stylesheets end
Same as \{#update\_stylesheets}, but respects \{#checked\_for\_updates} and the {file:SASS_REFERENCE.md#always_update-option `:always_update`} and {file:SASS_REFERENCE.md#always_check-option `:always_check`} options. @see #update_stylesheets
check_for_updates
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
Apache-2.0
def compiler @compiler ||= Compiler.new end
Returns the singleton compiler instance. This compiler has been pre-configured according to the plugin configuration. @return [Sass::Plugin::Compiler]
compiler
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
Apache-2.0
def update_stylesheets(individual_files = []) return if options[:never_update] compiler.update_stylesheets(individual_files) 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)>] 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.
update_stylesheets
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
Apache-2.0
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
force_update_stylesheets
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
Apache-2.0
def method_missing(method, *args, &block) if compiler.respond_to?(method) compiler.send(method, *args, &block) else super end end
All other method invocations are proxied to the \{#compiler}. @see #compiler @see Sass::Plugin::Compiler
method_missing
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/plugin.rb
Apache-2.0
def initialize(options = {}) @options = options end
@param options [{Symbol => Object}] An options hash.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/repl.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/repl.rb
Apache-2.0
def run environment = Environment.new @line = 0 loop do @line += 1 unless (text = Readline.readline('>> ')) puts return end Readline::HISTORY << text parse_input(environment, text) end end
Starts the read-eval-print loop.
run
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/repl.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/repl.rb
Apache-2.0
def initialize(suffix = nil) @suffix = suffix end
@param name [String, nil] See \{#suffix}
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def unify(sels) raise Sass::SyntaxError.new("[BUG] Cannot unify parent selectors.") end
Always raises an exception. @raise [Sass::SyntaxError] Parent selectors should be resolved before unification @see Selector#unify
unify
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def initialize(name) @name = name end
@param name [String] The class name
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def initialize(name) @name = name end
@param name [String] The id name
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def unify(sels) return if sels.any? {|sel2| sel2.is_a?(Id) && name != sel2.name} super end
Returns `nil` if `sels` contains an {Id} selector with a different name than this one. @see Selector#unify
unify
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def initialize(name) @name = name end
@param name [String] The placeholder name
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def initialize(namespace) @namespace = namespace end
@param namespace [String, nil] See \{#namespace}
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def unify(sels) name = case sels.first when Universal; :universal when Element; sels.first.name else return [self] + sels unless namespace.nil? || namespace == '*' return sels unless sels.empty? return [self] end ns, accept = unify_namespaces(namespace, sels.first.namespace) return unless accept [name == :universal ? Universal.new(ns) : Element.new(name, ns)] + sels[1..-1] end
Unification of a universal selector is somewhat complicated, especially when a namespace is specified. If there is no namespace specified or any namespace is specified (namespace `"*"`), then `sel` is returned without change (unless it's empty, in which case `"*"` is required). If a namespace is specified but `sel` does not specify a namespace, then the given namespace is applied to `sel`, either by adding this {Universal} selector or applying this namespace to an existing {Element} selector. If both this selector *and* `sel` specify namespaces, those namespaces are unified via {Simple#unify_namespaces} and the unified namespace is used, if possible. @todo There are lots of cases that this documentation specifies; make sure we thoroughly test **all of them**. @todo Keep track of whether a default namespace has been declared and handle namespace-unspecified selectors accordingly. @todo If any branch of a CommaSequence ends up being just `"*"`, then all other branches should be eliminated @see Selector#unify
unify
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def initialize(name, namespace) @name = name @namespace = namespace end
@param name [String] The element name @param namespace [String, nil] See \{#namespace}
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def unify(sels) case sels.first when Universal; when Element; return unless name == sels.first.name else return [self] + sels end ns, accept = unify_namespaces(namespace, sels.first.namespace) return unless accept [Element.new(name, ns)] + sels[1..-1] end
Unification of an element selector is somewhat complicated, especially when a namespace is specified. First, if `sel` contains another {Element} with a different \{#name}, then the selectors can't be unified and `nil` is returned. Otherwise, if `sel` doesn't specify a namespace, or it specifies any namespace (via `"*"`), then it's returned with this element selector (e.g. `.foo` becomes `a.foo` or `svg|a.foo`). Similarly, if this selector doesn't specify a namespace, the namespace from `sel` is used. If both this selector *and* `sel` specify namespaces, those namespaces are unified via {Simple#unify_namespaces} and the unified namespace is used, if possible. @todo There are lots of cases that this documentation specifies; make sure we thoroughly test **all of them**. @todo Keep track of whether a default namespace has been declared and handle namespace-unspecified selectors accordingly. @see Selector#unify
unify
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def initialize(name, namespace, operator, value, flags) @name = name @namespace = namespace @operator = operator @value = value @flags = flags end
@param name [String] The attribute name @param namespace [String, nil] See \{#namespace} @param operator [String] The matching operator, e.g. `"="` or `"^="` @param value [String] See \{#value} @param flags [String] See \{#flags}
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/selector.rb
Apache-2.0
def handle_interpolation(str) scan = Sass::Util::MultibyteStringScanner.new(str) yield scan while scan.scan(/(.*?)(\\*)\#\{/m) scan.rest end
Scans through a string looking for the interoplation-opening `#{` and, when it's found, yields the scanner to the calling code so it can handle it properly. The scanner will have any backslashes immediately in front of the `#{` as the second capture group (`scan[2]`), and the text prior to that as the first (`scan[1]`). @yieldparam scan [StringScanner] The scanner scanning through the string @return [String] The text remaining in the scanner after all `#{`s have been processed
handle_interpolation
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/shared.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/shared.rb
Apache-2.0
def balance(scanner, start, finish, count = 0) str = '' scanner = Sass::Util::MultibyteStringScanner.new(scanner) unless scanner.is_a? StringScanner regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE) while scanner.scan(regexp) str << scanner.matched count += 1 if scanner.matched[-1] == start count -= 1 if scanner.matched[-1] == finish return [str, scanner.rest] if count == 0 end end
Moves a scanner through a balanced pair of characters. For example: Foo (Bar (Baz bang) bop) (Bang (bop bip)) ^ ^ from to @param scanner [StringScanner] The string scanner to move @param start [Character] The character opening the balanced pair. A `Fixnum` in 1.8, a `String` in 1.9 @param finish [Character] The character closing the balanced pair. A `Fixnum` in 1.8, a `String` in 1.9 @param count [Integer] The number of opening characters matched before calling this method @return [(String, String)] The string matched within the balanced pair and the rest of the string. `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.
balance
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/shared.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/shared.rb
Apache-2.0
def human_indentation(indentation, was = false) if !indentation.include?(?\t) noun = 'space' elsif !indentation.include?(?\s) noun = 'tab' else return indentation.inspect + (was ? ' was' : '') end singular = indentation.length == 1 if was was = singular ? ' was' : ' were' else was = '' end "#{indentation.length} #{noun}#{'s' unless singular}#{was}" end
Formats a string for use in error messages about indentation. @param indentation [String] The string used for indentation @param was [Boolean] Whether or not to add `"was"` or `"were"` (depending on how many characters were in `indentation`) @return [String] The name of the indentation (e.g. `"12 spaces"`, `"1 tab"`)
human_indentation
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/shared.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/shared.rb
Apache-2.0
def is_import? type == :import end
Whether this frame represents an import. @return [Boolean]
is_import?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def is_mixin? type == :mixin end
Whether this frame represents a mixin. @return [Boolean]
is_mixin?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def is_base? type == :base end
Whether this is the base frame. @return [Boolean]
is_base?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def with_base(filename, line) with_frame(filename, line, :base) {yield} end
Pushes a base frame onto the stack. @param filename [String] See \{Frame#filename}. @param line [String] See \{Frame#line}. @yield [] A block in which the new frame is on the stack.
with_base
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def with_import(filename, line) with_frame(filename, line, :import) {yield} end
Pushes an import frame onto the stack. @param filename [String] See \{Frame#filename}. @param line [String] See \{Frame#line}. @yield [] A block in which the new frame is on the stack.
with_import
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def with_mixin(filename, line, name) with_frame(filename, line, :mixin, name) {yield} end
Pushes a mixin frame onto the stack. @param filename [String] See \{Frame#filename}. @param line [String] See \{Frame#line}. @param name [String] See \{Frame#name}. @yield [] A block in which the new frame is on the stack.
with_mixin
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def with_function(filename, line, name) with_frame(filename, line, :function, name) {yield} end
Pushes a function frame onto the stack. @param filename [String] See \{Frame#filename}. @param line [String] See \{Frame#line}. @param name [String] See \{Frame#name}. @yield [] A block in which the new frame is on the stack.
with_function
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def with_directive(filename, line, name) with_frame(filename, line, :directive, name) {yield} end
Pushes a function frame onto the stack. @param filename [String] See \{Frame#filename}. @param line [String] See \{Frame#line}. @param name [String] See \{Frame#name}. @yield [] A block in which the new frame is on the stack.
with_directive
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/stack.rb
Apache-2.0
def scope(file) File.join(Sass::ROOT_DIR, file) end
Returns the path of a file relative to the Sass root directory. @param file [String] The filename relative to the Sass root @return [String] The filename relative to the the working directory
scope
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def map_keys(hash) map_hash(hash) {|k, v| [yield(k), v]} end
Maps the keys in a hash according to a block. @example map_keys({:foo => "bar", :baz => "bang"}) {|k| k.to_s} #=> {"foo" => "bar", "baz" => "bang"} @param hash [Hash] The hash to map @yield [key] A block in which the keys are transformed @yieldparam key [Object] The key that should be mapped @yieldreturn [Object] The new value for the key @return [Hash] The mapped hash @see #map_vals @see #map_hash
map_keys
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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
map_vals
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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
map_hash
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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`
powerset
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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]
restrict
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def round(value) # If the number is within epsilon of X.5, round up (or down for negative # numbers). mod = value % 1 mod_is_half = (mod - 0.5).abs < Script::Value::Number.epsilon if value > 0 !mod_is_half && mod < 0.5 ? value.floor : value.ceil else mod_is_half || mod < 0.5 ? value.floor : value.ceil end end
Like [Fixnum.round], but leaves rooms for slight floating-point differences. @param value [Numeric] @return [Numeric]
round
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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
merge_adjacent_strings
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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`.
replace_subseq
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def intersperse(enum, val) enum.inject([]) {|a, e| a << e << val}[0...-1] end
Intersperses a value in an enumerable, as would be done with `Array#join` but without concatenating the array together afterwards. @param enum [Enumerable] @param val @return [Array]
intersperse
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
substitute
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def strip_string_array(arr) arr.first.lstrip! if arr.first.is_a?(String) arr[-1] = Sass::Util.rstrip_except_escapes(arr[-1]) if arr.last.is_a?(String) arr end
Destructively strips whitespace from the beginning and end of the first and last elements, respectively, in the array (if those elements are strings). Preserves CSS escapes at the end of the array. @param arr [Array] @return [Array] `arr`
strip_string_array
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def normalize_ident_escapes(ident, start: true) ident.gsub(/(^)?(#{Sass::SCSS::RX::ESCAPE})/) do |s| at_start = start && $1 char = escaped_char(s) next char if char =~ (at_start ? Sass::SCSS::RX::NMSTART : Sass::SCSS::RX::NMCHAR) if char =~ (at_start ? /[\x0-\x1F\x7F0-9]/ : /[\x0-\x1F\x7F]/) "\\#{char.ord.to_s(16)} " else "\\#{char}" end end end
Normalizes identifier escapes. See https://github.com/sass/language/blob/master/accepted/identifier-escapes.md. @param ident [String] @return [String]
normalize_ident_escapes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def escaped_char(escape) if escape =~ /^\\([0-9a-fA-F]{1,6})[ \t\r\n\f]?/ $1.to_i(16).chr(Encoding::UTF_8) else escape[1] end end
Returns the character encoded by the given escape sequence. @param escape [String] @return [String]
escaped_char
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def rstrip_except_escapes(string) string.sub(/(?<!\\)\s+$/, '') end
Like [String#rstrip], but preserves escaped whitespace at the end of the string. @param string [String] @return [String]
rstrip_except_escapes
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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]]
paths
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
lcs
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def upcase(string) return string.upcase unless ruby2_4? string.upcase(:ascii) end
Like `String.upcase`, but only ever upcases ASCII letters.
upcase
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def downcase(string) return string.downcase unless ruby2_4? string.downcase(:ascii) end
Like `String.downcase`, but only ever downcases ASCII letters.
downcase
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def array_minus(minuend, subtrahend) return minuend - subtrahend unless rbx? set = Set.new(minuend) - subtrahend minuend.select {|e| set.include?(e)} end
Returns a sub-array of `minuend` containing only elements that are also in `subtrahend`. Ensures that the return value has the same order as `minuend`, even on Rubinius where that's not guaranteed by `Array#-`. @param minuend [Array] @param subtrahend [Array] @return [Array]
array_minus
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def max(val1, val2) val1 > val2 ? val1 : val2 end
Returns the maximum of `val1` and `val2`. We use this over \{Array.max} to avoid unnecessary garbage collection.
max
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def min(val1, val2) val1 <= val2 ? val1 : val2 end
Returns the minimum of `val1` and `val2`. We use this over \{Array.min} to avoid unnecessary garbage collection.
min
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def undefined_conversion_error_char(e) # Rubinius (as of 2.0.0.rc1) pre-quotes the error character. return e.error_char if rbx? # JRuby (as of 1.7.2) doesn't have an error_char field on # Encoding::UndefinedConversionError. return e.error_char.dump unless jruby? e.message[/^"[^"]+"/] # " end
Returns a string description of the character that caused an `Encoding::UndefinedConversionError`. @param e [Encoding::UndefinedConversionError] @return [String]
undefined_conversion_error_char
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def check_range(name, range, value, unit = '') grace = (-0.00001..0.00001) str = value.to_s value = value.value if value.is_a?(Sass::Script::Value::Number) return value if range.include?(value) return range.first if grace.include?(value - range.first) return range.last if grace.include?(value - range.last) raise ArgumentError.new( "#{name} #{str} must be between #{range.first}#{unit} and #{range.last}#{unit}") end
Asserts that `value` falls within `range` (inclusive), leaving room for slight floating-point errors. @param name [String] The name of the value. Used in the error message. @param range [Range] The allowed range of values. @param value [Numeric, Sass::Script::Value::Number] The value to check. @param unit [String] The unit of the value. Used in error reporting. @return [Numeric] `value` adjusted to fall within range, if it was outside by a floating-point margin.
check_range
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def subsequence?(seq1, seq2) i = j = 0 loop do return true if i == seq1.size return false if j == seq2.size i += 1 if seq1[i] == seq2[j] j += 1 end end
Returns whether or not `seq1` is a subsequence of `seq2`. That is, whether or not `seq2` contains every element in `seq1` in the same order (and possibly more elements besides). @param seq1 [Array] @param seq2 [Array] @return [Boolean]
subsequence?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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
caller_info
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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]
version_gt
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def version_geq(v1, v2) version_gt(v1, v2) || !version_gt(v2, v1) end
Returns whether one version string represents the same or a more recent version than another. @param v1 [String] A version string. @param v2 [String] Another version string. @return [Boolean]
version_geq
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def abstract(obj) raise NotImplementedError.new("#{obj.class} must implement ##{caller_info[2]}") end
Throws a NotImplementedError for an abstract method. @param obj [Object] `self` @raise [NotImplementedError]
abstract
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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.
deprecated
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
silence_sass_warnings
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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]
rails_root
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def rails_env return ::Rails.env.to_s if defined?(::Rails.env) return RAILS_ENV.to_s if defined?(RAILS_ENV) nil end
Returns the environment of the Rails application, if this is running in a Rails context. Returns `nil` if no such environment is defined. @return [String, nil]
rails_env
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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]
ap_geq?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def av_template_class(name) return ActionView.const_get("Template#{name}") if ActionView.const_defined?("Template#{name}") ActionView::Template.const_get(name.to_s) end
Returns an ActionView::Template* class. In pre-3.0 versions of Rails, most of these classes were of the form `ActionView::TemplateFoo`, while afterwards they were of the form `ActionView;:Template::Foo`. @param name [#to_s] The name of the class to get. For example, `:Error` will return `ActionView::TemplateError` or `ActionView::Template::Error`.
av_template_class
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def windows? return @windows if defined?(@windows) @windows = (RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i) end
# Cross-OS Compatibility These methods are cached because some of them are called quite frequently and even basic checks like String#== are too costly to be called repeatedly. Whether or not this is running on Windows. @return [Boolean]
windows?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def ironruby? return @ironruby if defined?(@ironruby) @ironruby = RUBY_ENGINE == "ironruby" end
Whether or not this is running on IronRuby. @return [Boolean]
ironruby?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def rbx? return @rbx if defined?(@rbx) @rbx = RUBY_ENGINE == "rbx" end
Whether or not this is running on Rubinius. @return [Boolean]
rbx?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def jruby? return @jruby if defined?(@jruby) @jruby = RUBY_PLATFORM =~ /java/ end
Whether or not this is running on JRuby. @return [Boolean]
jruby?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def jruby_version @jruby_version ||= ::JRUBY_VERSION.split(".").map {|s| s.to_i} end
Returns an array of ints representing the JRuby version number. @return [Array<Integer>]
jruby_version
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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]
glob
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def pathname(path) path = path.tr("/", "\\") if windows? Pathname.new(path) end
Like `Pathname.new`, but normalizes Windows paths to always use backslash separators. `Pathname#relative_path_from` can break if the two pathnames aren't consistent in their slash style. @param path [String] @return [Pathname]
pathname
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def cleanpath(path) path = Pathname.new(path) unless path.is_a?(Pathname) pathname(path.cleanpath.to_s) end
Like `Pathname#cleanpath`, but normalizes Windows paths to always use backslash separators. Normally, `Pathname#cleanpath` actually does the reverse -- it will convert backslashes to forward slashes, which can break `Pathname#relative_path_from`. @param path [String, Pathname] @return [Pathname]
cleanpath
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
Returns `path` with all symlinks resolved. @param path [String, Pathname] @return [Pathname]
realpath
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
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
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?]
relative_path_from
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def file_uri_from_path(path) path = path.to_s if path.is_a?(Pathname) path = path.tr('\\', '/') if windows? path = URI::DEFAULT_PARSER.escape(path) return path.start_with?('/') ? "file://" + path : path unless windows? return "file:///" + path.tr("\\", "/") if path =~ %r{^[a-zA-Z]:[/\\]} return "file:" + path.tr("\\", "/") if path =~ %r{\\\\[^\\]+\\[^\\/]+} path.tr("\\", "/") end
Converts `path` to a "file:" URI. This handles Windows paths correctly. @param path [String, Pathname] @return [String]
file_uri_from_path
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def retry_on_windows return yield unless windows? begin yield rescue SystemCallError sleep 0.1 yield end end
Retries a filesystem operation if it fails on Windows. Windows has weird and flaky locking rules that can cause operations to fail. @yield [] The filesystem operation.
retry_on_windows
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def destructure(val) val || [] end
Prepare a value for a destructuring assignment (e.g. `a, b = val`). This works around a performance bug when using ActiveSupport, and only needs to be called when `val` is likely to be `nil` reasonably often. See [this bug report](http://redmine.ruby-lang.org/issues/4917). @param val [Object] @return [Object]
destructure
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def ruby2_4? return @ruby2_4 if defined?(@ruby2_4) @ruby2_4 = if RUBY_VERSION_COMPONENTS[0] == 2 RUBY_VERSION_COMPONENTS[1] >= 4 else RUBY_VERSION_COMPONENTS[0] > 2 end end
# Cross-Ruby-Version Compatibility Whether or not this is running under Ruby 2.4 or higher. @return [Boolean]
ruby2_4?
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/util.rb
Apache-2.0
def version return @@version if defined?(@@version) numbers = File.read(Sass::Util.scope('VERSION')).strip.split('.'). map {|n| n =~ /^[0-9]+$/ ? n.to_i : n} name = File.read(Sass::Util.scope('VERSION_NAME')).strip @@version = { :major => numbers[0], :minor => numbers[1], :teeny => numbers[2], :name => name } if (date = version_date) @@version[:date] = date end if numbers[3].is_a?(String) @@version[:teeny] = -1 @@version[:prerelease] = numbers[3] @@version[:prerelease_number] = numbers[4] end @@version[:number] = numbers.join('.') @@version[:string] = @@version[:number].dup if (rev = revision_number) @@version[:rev] = rev unless rev[0] == ?( @@version[:string] << "." << rev[0...7] end end @@version end
Returns a hash representing the version of Sass. The `:major`, `:minor`, and `:teeny` keys have their respective numbers as Integers. The `:name` key has the name of the version. The `:string` key contains a human-readable string representation of the version. The `:number` key is the major, minor, and teeny keys separated by periods. The `:date` key, which is not guaranteed to be defined, is the `DateTime` at which this release was cut. If Sass is checked out from Git, the `:rev` key will have the revision hash. For example: { :string => "2.1.0.9616393", :rev => "9616393b8924ef36639c7e82aa88a51a24d16949", :number => "2.1.0", :date => DateTime.parse("Apr 30 13:52:01 2009 -0700"), :major => 2, :minor => 1, :teeny => 0 } If a prerelease version of Sass is being used, the `:string` and `:number` fields will reflect the full version (e.g. `"2.2.beta.1"`), and the `:teeny` field will be `-1`. A `:prerelease` key will contain the name of the prerelease (e.g. `"beta"`), and a `:prerelease_number` key will contain the rerelease number. For example: { :string => "3.0.beta.1", :number => "3.0.beta.1", :date => DateTime.parse("Mar 31 00:38:04 2010 -0700"), :major => 3, :minor => 0, :teeny => -1, :prerelease => "beta", :prerelease_number => 1 } @return [{Symbol => String/Integer}] The version hash
version
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/version.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/version.rb
Apache-2.0
def _store(key, version, sha, contents) raise "#{self.class} must implement #_store." end
Store cached contents for later retrieval Must be implemented by all CacheStore subclasses Note: cache contents contain binary data. @param key [String] The key to store the contents under @param version [String] The current sass version. Cached contents must not be retrieved across different versions of sass. @param sha [String] The sha of the sass source. Cached contents must not be retrieved if the sha has changed. @param contents [String] The contents to store.
_store
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
Apache-2.0
def _retrieve(key, version, sha) raise "#{self.class} must implement #_retrieve." end
Retrieved cached contents. Must be implemented by all subclasses. Note: if the key exists but the sha or version have changed, then the key may be deleted by the cache store, if it wants to do so. @param key [String] The key to retrieve @param version [String] The current sass version. Cached contents must not be retrieved across different versions of sass. @param sha [String] The sha of the sass source. Cached contents must not be retrieved if the sha has changed. @return [String] The contents that were previously stored. @return [NilClass] when the cache key is not found or the version or sha have changed.
_retrieve
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
Apache-2.0
def store(key, sha, root) _store(key, Sass::VERSION, sha, Marshal.dump(root)) rescue TypeError, LoadError => e Sass::Util.sass_warn "Warning. Error encountered while saving cache #{path_to(key)}: #{e}" nil end
Store a {Sass::Tree::RootNode}. @param key [String] The key to store it under. @param sha [String] The checksum for the contents that are being stored. @param root [Object] The root node to cache.
store
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
Apache-2.0
def retrieve(key, sha) contents = _retrieve(key, Sass::VERSION, sha) Marshal.load(contents) if contents rescue EOFError, TypeError, ArgumentError, LoadError => e Sass::Util.sass_warn "Warning. Error encountered while reading cache #{path_to(key)}: #{e}" nil end
Retrieve a {Sass::Tree::RootNode}. @param key [String] The key the root element was stored under. @param sha [String] The checksum of the root element's content. @return [Object] The cached object.
retrieve
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
Apache-2.0
def key(sass_dirname, sass_basename) dir = Digest::SHA1.hexdigest(sass_dirname) filename = "#{sass_basename}c" "#{dir}/#{filename}" end
Return the key for the sass file. The `(sass_dirname, sass_basename)` pair should uniquely identify the Sass document, but otherwise there are no restrictions on their content. @param sass_dirname [String] The fully-expanded location of the Sass file. This corresponds to the directory name on a filesystem. @param sass_basename [String] The name of the Sass file that is being referenced. This corresponds to the basename on a filesystem.
key
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/base.rb
Apache-2.0
def initialize(*caches) @caches = caches end
Create a new cache chaining the given caches. @param caches [Array<Sass::CacheStores::Base>] The caches to chain.
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/chain.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/chain.rb
Apache-2.0
def path_to(key) key = key.gsub(/[<>:\\|?*%]/) {|c| "%%%03d" % c.ord} File.join(cache_location, key) end
Returns the path to a file for the given key. @param key [String] @return [String] The path to the cache file.
path_to
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/filesystem.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/cache_stores/filesystem.rb
Apache-2.0
def initialize(args) @args = args @options = {} end
@param args [Array<String>] The command-line arguments
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
def parse! begin parse rescue Exception => e # Exit code 65 indicates invalid data per # http://www.freebsd.org/cgi/man.cgi?query=sysexits. Setting it via # at_exit is a bit of a hack, but it allows us to rethrow when --trace # is active and get both the built-in exception formatting and the # correct exit code. at_exit {exit Sass::Util.windows? ? 13 : 65} if e.is_a?(Sass::SyntaxError) raise e if @options[:trace] || e.is_a?(SystemExit) if e.is_a?(Sass::SyntaxError) $stderr.puts e.sass_backtrace_str("standard input") else $stderr.print "#{e.class}: " unless e.class == RuntimeError $stderr.puts e.message.to_s end $stderr.puts " Use --trace for backtrace." exit 1 end exit 0 end
Parses the command-line arguments and runs the executable. Calls `Kernel#exit` at the end, so it never returns. @see #parse
parse!
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
def parse @opts = OptionParser.new(&method(:set_opts)) @opts.parse!(@args) process_result @options end
Parses the command-line arguments and runs the executable. This does not handle exceptions or exit the program. @see #parse!
parse
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
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
Finds the line of the source template on which an exception was raised. @param exception [Exception] The exception @return [String] The line number
get_line
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
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]
encoding_option
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
def process_result input, output = @options[:input], @options[:output] args = @args.dup input ||= begin filename = args.shift @options[:filename] = filename open_file(filename) || $stdin end @options[:output_filename] = args.shift output ||= @options[:output_filename] || $stdout @options[:input], @options[:output] = input, output end
Processes the options set by the command-line arguments. In particular, sets `@options[:input]` and `@options[:output]` to appropriate IO streams. This is meant to be overridden by subclasses so they can run their respective programs.
process_result
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
def puts_action(name, color, arg) return if @options[:for_engine][:quiet] printf color(color, "%11s %s\n"), name, arg STDOUT.flush end
Prints a status message about performing the given action, colored using the given color (via terminal escapes) if possible. @param name [#to_s] A short name for the action being performed. Shouldn't be longer than 11 characters. @param color [Symbol] The name of the color to use for this action. Can be `:red`, `:green`, or `:yellow`.
puts_action
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
def puts(*args) return if @options[:for_engine][:quiet] Kernel.puts(*args) end
Same as `Kernel.puts`, but doesn't print anything if the `--quiet` option is set. @param args [Array] Passed on to `Kernel.puts`
puts
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
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
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.
color
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/base.rb
Apache-2.0
def initialize(args) super require 'sass' @options[:for_tree] = {} @options[:for_engine] = {:cache => false, :read_cache => true} end
@param args [Array<String>] The command-line arguments
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_convert.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_convert.rb
Apache-2.0
def set_opts(opts) opts.banner = <<END Usage: sass-convert [options] [INPUT] [OUTPUT] Description: Converts between CSS, indented syntax, and SCSS files. For example, this can convert from the indented syntax to SCSS, or from CSS to SCSS (adding appropriate nesting). END common_options(opts) style(opts) input_and_output(opts) miscellaneous(opts) end
Tells optparse how to parse the arguments. @param opts [OptionParser]
set_opts
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_convert.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_convert.rb
Apache-2.0
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.
process_result
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_convert.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_convert.rb
Apache-2.0
def initialize(args, default_syntax) super(args) @options[:sourcemap] = :auto @options[:for_engine] = { :load_paths => default_sass_path } @default_syntax = default_syntax end
@param args [Array<String>] The command-line arguments
initialize
ruby
collabnix/kubelabs
.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_scss.rb
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/sass-3.7.4/lib/sass/exec/sass_scss.rb
Apache-2.0