module SassC::Util
def abstract(obj)
-
(NotImplementedError)
-
Parameters:
-
obj
(Object
) -- `self`
def abstract(obj) raise NotImplementedError.new("#{obj.class} must implement ##{caller_info[2]}") end
def caller_info(entry = nil)
-
([String, Integer, (String, nil)])
-
Parameters:
-
entry
(String
) -- An entry in the `#caller` list, or a similarly formatted string
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 clamp(value, min, max)
Restricts the numeric `value` to be within `min` and `max`, inclusive.
def clamp(value, min, max) return min if value < min return max if value > max return value end
def deprecated(obj, message = nil)
-
message
(String
) -- A message describing what to do instead. -
obj
(Object
) -- `self`
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}" SassC::Util.sass_warn full_message end
def ironruby?
-
(Boolean)
-
def ironruby? return @ironruby if defined?(@ironruby) @ironruby = RUBY_ENGINE == "ironruby" end
def jruby?
-
(Boolean)
-
def jruby? return @jruby if defined?(@jruby) @jruby = RUBY_PLATFORM =~ /java/ end
def jruby_version
-
(Array
-)
def jruby_version @jruby_version ||= ::JRUBY_VERSION.split(".").map {|s| s.to_i} end
def map_keys(hash)
- See: #map_hash -
See: #map_vals -
Returns:
-
(Hash)
- The mapped hash
Other tags:
- Yieldreturn: - The new value for the key
Other tags:
- Yieldparam: key - The key that should be mapped
Other tags:
- Yield: - A block in which the keys are transformed
Parameters:
-
hash
(Hash
) -- The hash to map
def map_keys(hash) map_hash(hash) {|k, v| [yield(k), v]} end
def paths(arrs)
-
(Array
-)
Parameters:
-
arrs
(Array
) --
def paths(arrs) arrs.inject([[]]) do |paths, arr| arr.map {|e| paths.map {|path| path + [e]}}.flatten(1) end end
def rails_env
-
(String, nil)
-
def rails_env return ::Rails.env.to_s if defined?(::Rails.env) return RAILS_ENV.to_s if defined?(RAILS_ENV) nil end
def rails_root
-
(String, nil)
-
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 rbx?
-
(Boolean)
-
def rbx? return @rbx if defined?(@rbx) @rbx = RUBY_ENGINE == "rbx" end
def relative_path_from(path, from)
-
(Pathname?)
-
Parameters:
-
from
(String, Pathname
) -- -
path
(String, Pathname
) --
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 round(value)
-
(Numeric)
-
Parameters:
-
value
(Numeric
) --
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 < SassC::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
def sass_warn(msg)
-
msg
(String
) --
def sass_warn(msg) Sass.logger.warn("#{msg}\n") end
def silence_sass_warnings
- Yield: - A block in which no Sass warnings will be printed
def silence_sass_warnings old_level, Sass.logger.log_level = Sass.logger.log_level, :error yield ensure SassC.logger.log_level = old_level end
def windows?
-
(Boolean)
-
def windows? return @windows if defined?(@windows) @windows = (RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i) end