### Home Classes Methods

### In Files

- lib/sass/script/functions.rb

### Parent

Object

### Methods

- ::new
- #assert_integer
- #assert_type
- #assert_unit
- #perform

### Included Modules

- Sass::Script::Functions
- Sass::Script::Value::Helpers

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Script::Value::String
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Script::Functions::EvaluationContext

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

### Constants

TYPE_NAMES

  The human-readable names for [Sass::Script::Value::Base]. The default is just the downcased name of the type.

### Attributes

environment[R]

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.

@return [Environment]

options[R]

The options hash for the {Sass::Engine} that is processing the function call

@return [{Symbol => Object}]

### Public Class Methods

new(environment) click to toggle source

@param environment [Environment] See {#environment}

    # File lib/sass/script/functions.rb, line 502
    def initialize(environment)
      @environment = environment
      @options = environment.options
    end

### Public Instance Methods

assert_integer(number, name = nil) click to toggle source

Asserts that the value is an integer.

@example

    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"

@param number [Sass::Script::Value::Base] The value to be validated. @param name [::String] The name of the parameter being validated. @raise [ArgumentError] if number is not an integer or is not a number.

    # File lib/sass/script/functions.rb, line 563
    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) click to toggle source

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.

@example

    assert_type value, :String
    assert_type value, :Number

@param value [Sass::Script::Value::Base] A SassScript value @param type [Symbol] The name of the type the value is expected to be @param name [String, Symbol, nil] The name of the argument. @raise [ArgumentError] if value is not of the correct type.

    # File lib/sass/script/functions.rb, line 521
    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.value.empty?
      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) click to toggle source

Asserts that the unit of the number is as expected.

@example

    assert_unit number, "px"
    assert_unit number, nil

@param number [Sass::Script::Value::Number] The number to be validated. @param unit [::String]

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

@param name [::String] The name of the parameter being validated. @raise [ArgumentError] if number is not of the correct unit or is not a number.

    # File lib/sass/script/functions.rb, line 541
    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) click to toggle source

Performs a node that has been delayed for execution.

@private @param node [Sass::Script::Tree::Node,

    Sass::Script::Value::Base] When this is a tree node, it's
    performed in the caller's environment. When it's a value
    (which can happen when the value had to be performed already
    -- like for a splat), it's returned as-is.

@param env [Sass::Environment] The environment within which to perform the node.

    Defaults to the (read-only) environment of the caller.

    # File lib/sass/script/functions.rb, line 583
    def perform(node, env = environment.caller)
      if node.is_a?(Sass::Script::Value::Base)
        node
      else
        node.perform(env)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.