Class: Sass::Script::Functions::EvaluationContext

Inherits:
Object
  • Object
show all
Includes:
Sass::Script::Functions
Defined in:
lib/sass/script/functions.rb

Overview

The context in which methods in Sass::Script::Functions are evaluated. That means that all instance methods of EvaluationContext are available to use in functions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sass::Script::Functions

#abs, #adjust_color, #adjust_hue, #alpha, #append, #blue, #ceil, #change_color, #comparable, #complement, #darken, declare, #desaturate, #floor, #grayscale, #green, #hsl, #hsla, #hue, #if, #index, #invert, #join, #length, #lighten, #lightness, #mix, #nth, #opacify, #opacity, #percentage, #quote, #red, #rgb, #rgba, #round, #saturate, #saturation, #scale_color, signature, #transparentize, #type_of, #unit, #unitless, #unquote, #zip

Constructor Details

#initialize(options) ⇒ EvaluationContext

Returns a new instance of EvaluationContext.

Parameters:

  • options ({Symbol => Object})


306
307
308
# File 'lib/sass/script/functions.rb', line 306

def initialize(options)
  @options = options
end

Instance Attribute Details

#options{Symbol => Object} (readonly)

The options hash for the Engine that is processing the function call

Returns:

  • ({Symbol => Object})


303
304
305
# File 'lib/sass/script/functions.rb', line 303

def options
  @options
end

Instance Method Details

#assert_type(value, type, name = nil)

Asserts that the type of a given SassScript value is the expected type (designated by a symbol).

Valid types are :Bool, :Color, :Number, and :String. Note that :String will match both double-quoted strings and unquoted identifiers.

Examples:

assert_type value, :String
assert_type value, :Number

Parameters:

  • value (Sass::Script::Literal)

    A SassScript value

  • type (Symbol)

    The name of the type the value is expected to be

  • name (String, nil) (defaults to: nil)

    The name of the argument.

Raises:

  • (ArgumentError)


323
324
325
326
327
328
# File 'lib/sass/script/functions.rb', line 323

def assert_type(value, type, name = nil)
  return if value.is_a?(Sass::Script.const_get(type))
  err = "#{value.inspect} is not a #{type.to_s.downcase}"
  err = "$#{name}: " + err if name
  raise ArgumentError.new(err)
end