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

Inherits:
Object
  • Object
show all
Includes:
Sass::Script::Functions, Value::Helpers
Defined in:
/usr/local/google-old/home/code/sass-site/.sass/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.

Constant Summary

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Value::Helpers

#bool, #hex_color, #hsl_color, #list, #map, #null, #number, #quoted_string, #rgb_color, #unquoted_string

Methods included from Sass::Script::Functions

#abs, #adjust_color, #adjust_hue, #alpha, #append, #blue, #call, #ceil, #change_color, #comparable, #complement, #counter, #counters, #darken, declare, #desaturate, #feature_exists, #floor, #function_exists, #global_variable_exists, #grayscale, #green, #hsl, #hsla, #hue, #ie_hex_str, #if, #index, #inspect, #invert, #join, #keywords, #length, #lighten, #lightness, #list_separator, #map_get, #map_has_key, #map_keys, #map_merge, #map_remove, #map_values, #max, #min, #mix, #mixin_exists, #nth, #opacify, #opacity, #percentage, #quote, #random, random_number_generator, random_seed=, #red, #rgb, #rgba, #round, #saturate, #saturation, #scale_color, #set_nth, signature, #str_index, #str_insert, #str_length, #str_slice, #to_lower_case, #to_upper_case, #transparentize, #type_of, #unique_id, #unit, #unitless, #unquote, #variable_exists, #zip

Constructor Details

- (EvaluationContext) initialize(environment)

Returns a new instance of EvaluationContext

Parameters:



458
459
460
461
# File '/usr/local/google-old/home/code/sass-site/.sass/lib/sass/script/functions.rb', line 458

def initialize(environment)
  @environment = environment
  @options = environment.options
end

Instance Attribute Details

- (Environment) environment (readonly)

The environment for this function. This environment’s Environment#parent is the global environment, and its Environment#caller is a read-only view of the local environment of the caller of this function.

Returns:



450
451
452
# File '/usr/local/google-old/home/code/sass-site/.sass/lib/sass/script/functions.rb', line 450

def environment
  @environment
end

- ({Symbol => Object}) options (readonly)

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

Returns:

  • ({Symbol => Object})


455
456
457
# File '/usr/local/google-old/home/code/sass-site/.sass/lib/sass/script/functions.rb', line 455

def options
  @options
end

Instance Method Details

- assert_integer(number, name = nil)

Asserts that the value is an integer.

Examples:

assert_integer 2px
assert_integer 2.5px
  => SyntaxError: "Expected 2.5px to be an integer"
assert_integer 2.5px, "width"
  => SyntaxError: "Expected width to be an integer but got 2.5px"

Parameters:

  • number (Sass::Script::Value::Base)

    The value to be validated.

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

    The name of the parameter being validated.

Raises:

  • (ArgumentError)

    if number is not an integer or is not a number.



519
520
521
522
523
524
525
526
527
# File '/usr/local/google-old/home/code/sass-site/.sass/lib/sass/script/functions.rb', line 519

def assert_integer(number, name = nil)
  assert_type number, :Number, name
  return if number.int?
  if name
    raise ArgumentError.new("Expected $#{name} to be an integer but got #{number}")
  else
    raise ArgumentError.new("Expected #{number} to be an integer")
  end
end

- 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::Value::Base)

    A SassScript value

  • type (Symbol)

    The name of the type the value is expected to be

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

    The name of the argument.

Raises:

  • (ArgumentError)

    if value is not of the correct type.



477
478
479
480
481
482
483
484
# File '/usr/local/google-old/home/code/sass-site/.sass/lib/sass/script/functions.rb', line 477

def assert_type(value, type, name = nil)
  klass = Sass::Script::Value.const_get(type)
  return if value.is_a?(klass)
  return if value.is_a?(Sass::Script::Value::List) && type == :Map && value.is_pseudo_map?
  err = "#{value.inspect} is not a #{TYPE_NAMES[type] || type.to_s.downcase}"
  err = "$#{name.to_s.gsub('_', '-')}: " + err if name
  raise ArgumentError.new(err)
end

- assert_unit(number, unit, name = nil)

Asserts that the unit of the number is as expected.

Examples:

assert_unit number, "px"
assert_unit number, nil

Parameters:

  • number (Sass::Script::Value::Number)

    The number to be validated.

  • unit (::String)

    The unit that the number must have. If nil, the number must be unitless.

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

    The name of the parameter being validated.

Raises:

  • (ArgumentError)

    if number is not of the correct unit or is not a number.



497
498
499
500
501
502
503
504
505
506
# File '/usr/local/google-old/home/code/sass-site/.sass/lib/sass/script/functions.rb', line 497

def assert_unit(number, unit, name = nil)
  assert_type number, :Number, name
  return if number.is_unit?(unit)
  expectation = unit ? "have a unit of #{unit}" : "be unitless"
  if name
    raise ArgumentError.new("Expected $#{name} to #{expectation} but got #{number}")
  else
    raise ArgumentError.new("Expected #{number} to #{expectation}")
  end
end