util.rb

Path: lib/sass/util.rb
Last Update: Sat Feb 23 07:13:03 +0000 2019

Required files

erb   set   enumerator   stringio   rbconfig   thread   sass/root   sass/util/subset_map   tempfile  

Methods

Constants

ATOMIC_WRITE_MUTEX = Mutex.new   @private

Public Instance methods

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.

A version of `Enumerable#enum_cons` that works in Ruby 1.8 and 1.9.

@param enum [Enumerable] The enumerable to get the enumerator for @param n [Fixnum] The size of each cons @return [Enumerator] The consed enumerator

A version of `Enumerable#enum_slice` that works in Ruby 1.8 and 1.9.

@param enum [Enumerable] The enumerable to get the enumerator for @param n [Fixnum] The size of each slice @return [Enumerator] The consed enumerator

A version of `Enumerable#enum_with_index` that works in Ruby 1.8 and 1.9.

@param enum [Enumerable] The enumerable to get the enumerator for @return [Enumerator] The with-index enumerator

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.

Extracts the non-string vlaues from an array containing both strings and non-strings. These values are replaced with escape sequences. This can be undone using \{inject_values}.

This is useful e.g. when we want to do string manipulation on an interpolated string.

The precise format of the resulting string is not guaranteed. However, it is guaranteed that newlines and whitespace won‘t be affected.

@param arr [Array] The array from which values are extracted. @return [(String, Array)] The resulting string, and an array of extracted values.

Flattens the first `n` nested arrays in a cross-version manner.

@param arr [Array] The array to flatten @param n [Fixnum] The number of levels to flatten @return [Array] The flattened array

Checks to see if a class has a given method. For example:

    Sass::Util.has?(:public_instance_method, String, :gsub) #=> true

Method collections like `Class#instance_methods` return strings in Ruby 1.8 and symbols in Ruby 1.9 and on, so this handles checking for them in a compatible way.

@param attr [to_s] The (singular) name of the method-collection method

  (e.g. `:instance_methods`, `:private_methods`)

@param klass [Module] The class to check the methods of which to check @param method [String, Symbol] The name of the method do check for @return [Boolean] Whether or not the given collection has the given method

Undoes \{extract_values} by transforming a string with escape sequences into an array of strings and non-string values.

@param str [String] The string with escape sequences. @param values [Array] The array of values to inject. @return [Array] The array of strings and values.

Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2. This is necessary so that the precompiled Haml template can be `encode`d into `@options[:encoding]` before being evaluated.

@param obj {Object} @return {String}

Returns the ASCII code of the given character.

@param c [String] All characters but the first are ignored. @return [Fixnum] The ASCII code of `c`.

Tests the hash-equality of two sets in a cross-version manner. Aggravatingly, this is order-dependent in Ruby 1.8.6.

@param set1 [Set] @param set2 [Set] @return [Boolean] Whether or not the sets are hashcode equal

Returns the hash code for a set in a cross-version manner. Aggravatingly, this is order-dependent in Ruby 1.8.6.

@param set [Set] @return [Fixnum] The order-independent hashcode of `set`

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.

[Validate]