Class: Sass::Script::Functions::EvaluationContext
- Inherits:
-
Object
- Object
- Sass::Script::Functions::EvaluationContext
- Includes:
- Sass::Script::Functions, Value::Helpers
- Defined in:
- .ruby-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
- TYPE_NAMES =
The human-readable names for [Sass::Script::Value::Base]. The default is just the downcased name of the type.
{:ArgList => 'variable argument list'}
Instance Attribute Summary (collapse)
-
#environment ⇒ Environment
readonly
The environment for this function.
-
#options ⇒ {Symbol => Object}
readonly
The options hash for the Engine that is processing the function call.
Instance Method Summary (collapse)
-
#assert_integer(number, name = nil) ⇒ Object
Asserts that the value is an integer.
-
#assert_type(value, type, name = nil) ⇒ Object
Asserts that the type of a given SassScript value is the expected type (designated by a symbol).
-
#assert_unit(number, unit, name = nil) ⇒ Object
Asserts that the unit of the number is as expected.
-
#initialize(environment) ⇒ EvaluationContext
constructor
A new instance of EvaluationContext.
-
#perform(node, env = environment.caller) ⇒ Object
Performs a node that has been delayed for execution.
Methods included from Value::Helpers
#bool, #calc?, #hex_color, #hsl_color, #list, #map, #null, #number, #parse_complex_selector, #parse_compound_selector, #parse_selector, #quoted_string, #rgb_color, #special_number?, #unquoted_string, #var?
Methods included from Sass::Script::Functions
#abs, #adjust_color, #adjust_hue, #alpha, #append, #blue, #call, #ceil, #change_color, #comparable, #complement, #content_exists, #counter, #counters, #darken, declare, #desaturate, #feature_exists, #floor, #function_exists, #get_function, #global_variable_exists, #grayscale, #green, #hsl, #hsla, #hue, #ie_hex_str, #if, #index, #inspect, #invert, #is_bracketed, #is_superselector, #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, #selector_append, #selector_extend, #selector_nest, #selector_parse, #selector_replace, #selector_unify, #set_nth, signature, #simple_selectors, #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
#initialize(environment) ⇒ EvaluationContext
Returns a new instance of EvaluationContext
519 520 521 522 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 519 def initialize(environment) @environment = environment @options = environment. end |
Constructor Details
#initialize(environment) ⇒ EvaluationContext
Returns a new instance of EvaluationContext
519 520 521 522 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 519 def initialize(environment) @environment = environment @options = environment. 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.
511 512 513 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 511 def environment @environment end |
#options ⇒ {Symbol => Object} (readonly)
The options hash for the Engine that is processing the function call
516 517 518 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 516 def @options end |
Instance Method Details
#assert_integer(number, name = nil) ⇒ Object
Asserts that the value is an integer.
593 594 595 596 597 598 599 600 601 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 593 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) ⇒ Object
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.
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 538 def assert_type(value, type, name = nil) valid_types = Array(type) found_type = valid_types.find do |t| value.is_a?(Sass::Script::Value.const_get(t)) || t == :Map && value.is_a?(Sass::Script::Value::List) && value.value.empty? end if found_type value.check_deprecated_interp if found_type == :String return end err = if valid_types.size == 1 "#{value.inspect} is not a #{TYPE_NAMES[type] || type.to_s.downcase}" else type_names = valid_types.map {|t| TYPE_NAMES[t] || t.to_s.downcase} "#{value.inspect} is not any of #{type_names.join(', ')}" end err = "$#{name.to_s.tr('_', '-')}: " + err if name raise ArgumentError.new(err) end |
#assert_unit(number, unit, name = nil) ⇒ Object
Asserts that the unit of the number is as expected.
571 572 573 574 575 576 577 578 579 580 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 571 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 |
#perform(node, env = environment.caller) ⇒ Object
Performs a node that has been delayed for execution.
613 614 615 616 617 618 619 |
# File '.ruby-sass/lib/sass/script/functions.rb', line 613 def perform(node, env = environment.caller) if node.is_a?(Sass::Script::Value::Base) node else node.perform(env) end end |