### Home Classes Methods

### In Files

- lib/sass/script/funcall.rb

### Parent

Node

### Methods

- ::new
- #_perform
- #children
- #deep_copy
- #inspect
- #to_literal
- #to_sass

### Class/Module Index

Quicksearch

- Sass
- 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::Generic
- Sass::Exec::Sass
- Sass::Exec::SassConvert
- Sass::Exec::Scss
- 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::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::ArgList
- Sass::Script::Bool
- Sass::Script::Color
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Funcall
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Interpolation
- Sass::Script::Lexer
- Sass::Script::List
- Sass::Script::Literal
- Sass::Script::Node
- Sass::Script::Null
- Sass::Script::Number
- Sass::Script::Operation
- Sass::Script::Parser
- Sass::Script::String
- Sass::Script::StringInterpolation
- Sass::Script::UnaryOperation
- Sass::Script::Variable
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Interpolation
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::SelectorPseudoClass
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::Shared
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- 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::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::MultibyteStringScanner
- Sass::Util::StaticConditionalContext
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object

No matching classes.

# Sass::Script::Funcall

A SassScript parse node representing a function call.

A function call either calls one of the functions in {Script::Functions}, or if no function with the given name exists it returns a string representation of the function call.

### Attributes

args[R]

The arguments to the function.

@return [Array<Script::Node>]

keywords[R]

The keyword arguments to the function.

@return [{String => Script::Node}]

name[R]

The name of the function.

@return [String]

splat[RW]

The splat argument for this function, if one exists.

@return [Script::Node?]

### Public Class Methods

new(name, args, keywords, splat) click to toggle source

@param name [String] See {#name} @param args [Array<Script::Node>] See {#args} @param splat [Script::Node] See {#splat} @param keywords [{String => Script::Node}] See {#keywords}

    # File lib/sass/script/funcall.rb, line 35
    def initialize(name, args, keywords, splat)
      @name = name
      @args = args
      @keywords = keywords
      @splat = splat
      super()
    end

### Public Instance Methods

children() click to toggle source

Returns the arguments to the function.

@return [Array<Node>] @see Node#children

    # File lib/sass/script/funcall.rb, line 77
    def children
      res = @args + @keywords.values
      res << @splat if @splat
      res
    end

deep_copy() click to toggle source

@see Node#deep_copy

    # File lib/sass/script/funcall.rb, line 84
    def deep_copy
      node = dup
      node.instance_variable_set('@args', args.map {|a| a.deep_copy})
      node.instance_variable_set('@keywords', Hash[keywords.map {|k, v| [k, v.deep_copy]}])
      node
    end

inspect() click to toggle source

@return [String] A string representation of the function call

    # File lib/sass/script/funcall.rb, line 44
    def inspect
      args = @args.map {|a| a.inspect}.join(', ')
      keywords = Sass::Util.hash_to_a(@keywords).
          map {|k, v| "$#{k}: #{v.inspect}"}.join(', ')
      if self.splat
        splat = (args.empty? && keywords.empty?) ? "" : ", "
        splat = "#{splat}#{self.splat.inspect}..."
      end
      "#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})"
    end

to_sass(opts = {}) click to toggle source

@see Node#to_sass

    # File lib/sass/script/funcall.rb, line 56
    def to_sass(opts = {})
      arg_to_sass = lambda do |arg|
        sass = arg.to_sass(opts)
        sass = "(#{sass})" if arg.is_a?(Sass::Script::List) && arg.separator == :comma
        sass
      end

      args = @args.map(&arg_to_sass).join(', ')
      keywords = Sass::Util.hash_to_a(@keywords).
        map {|k, v| "$#{dasherize(k, opts)}: #{arg_to_sass[v]}"}.join(', ')
      if self.splat
        splat = (args.empty? && keywords.empty?) ? "" : ", "
        splat = "#{splat}#{arg_to_sass[self.splat]}..."
      end
      "#{dasherize(name, opts)}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})"
    end

### Protected Instance Methods

_perform(environment) click to toggle source

Evaluates the function call.

@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Literal] The SassScript object that is the value of the function call @raise [Sass::SyntaxError] if the function call raises an ArgumentError

    # File lib/sass/script/funcall.rb, line 98
    def _perform(environment)
      args = @args.map {|a| a.perform(environment)}
      splat = @splat.perform(environment) if @splat
      if fn = environment.function(@name)
        keywords = Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
        return without_original(perform_sass_fn(fn, args, keywords, splat))
      end

      ruby_name = @name.tr('-', '_')
      args = construct_ruby_args(ruby_name, args, splat, environment)

      unless Functions.callable?(ruby_name)
        without_original(opts(to_literal(args)))
      else
        without_original(opts(Functions::EvaluationContext.new(environment.options).
            send(ruby_name, *args)))
      end
    rescue ArgumentError => e
      message = e.message

      # If this is a legitimate Ruby-raised argument error, re-raise it.
      # Otherwise, it's an error in the user's stylesheet, so wrap it.
      if Sass::Util.rbx?
        # Rubinius has a different error report string than vanilla Ruby. It
        # also doesn't put the actual method for which the argument error was
        # thrown in the backtrace, nor does it include `send`, so we look for
        # `_perform`.
        if e.message =~ /^method '([^']+)': given (\d+), expected (\d+)/
          error_name, given, expected = $1, $2, $3
          raise e if error_name != ruby_name || e.backtrace[0] !~ /:in `_perform'$/
          message = "wrong number of arguments (#{given} for #{expected})"
        end
      elsif Sass::Util.jruby?
        if Sass::Util.jruby1_6?
          should_maybe_raise = e.message =~ /^wrong number of arguments \((\d+) for (\d+)\)/ &&
            # The one case where JRuby does include the Ruby name of the function
            # is manually-thrown ArgumentErrors, which are indistinguishable from
            # legitimate ArgumentErrors. We treat both of these as
            # Sass::SyntaxErrors even though it can hide Ruby errors.
            e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
        else
          should_maybe_raise = e.message =~ /^wrong number of arguments calling `[^`]+` \((\d+) for (\d+)\)/
          given, expected = $1, $2
        end

        if should_maybe_raise
          # JRuby 1.7 includes __send__ before send and _perform.
          trace = e.backtrace.dup
          raise e if !Sass::Util.jruby1_6? && trace.shift !~ /:in `__send__'$/

          # JRuby (as of 1.7.2) doesn't put the actual method
          # for which the argument error was thrown in the backtrace, so we
          # detect whether our send threw an argument error.
          if !(trace[0] =~ /:in `send'$/ && trace[1] =~ /:in `_perform'$/)
            raise e
          elsif !Sass::Util.jruby1_6?
            # JRuby 1.7 doesn't use standard formatting for its ArgumentErrors.
            message = "wrong number of arguments (#{given} for #{expected})"
          end
        end
      elsif e.message =~ /^wrong number of arguments \(\d+ for \d+\)/ &&
          e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
        raise e
      end
      raise Sass::SyntaxError.new("#{message} for `#{name}'")
    end

to_literal(args) click to toggle source

This method is factored out from `_perform` so that compass can override it with a cross-browser implementation for functions that require vendor prefixes in the generated css.

    # File lib/sass/script/funcall.rb, line 168
    def to_literal(args)
      Script::String.new("#{name}(#{args.join(', ')})")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.