class Sass::Script::Tree::Funcall
A SassScript parse node representing a function call.
A function call either calls one of the functions in {Sass::Script::Functions}, or if no function with the given name exists it returns a string representation of the function call.
Attributes
The arguments to the function.
@return [Array<Node>]
The callable to be invoked
@return [Sass::Callable] or nil if no callable is provided.
The keyword arguments to the function.
@return [Sass::Util::NormalizedMap<Node>]
The second splat argument for this function, if one exists.
If this exists, it’s always a map of keyword arguments, and {#splat} is always either a list or an arglist.
@return [Node?]
The name of the function.
@return [String]
The first splat argument for this function, if one exists.
This could be a list of positional arguments, a map of keyword arguments, or an arglist containing both.
@return [Node?]
Public Class Methods
Source
# File lib/sass/script/tree/funcall.rb, line 52 def initialize(name_or_callable, args, keywords, splat, kwarg_splat) if name_or_callable.is_a?(Sass::Callable) @callable = name_or_callable @name = name_or_callable.name else @callable = nil @name = name_or_callable end @args = args @keywords = keywords @splat = splat @kwarg_splat = kwarg_splat super() end
@param name_or_callable [String, Sass::Callable] See {#name} @param args [Array<Node>] See {#args} @param keywords [Sass::Util::NormalizedMap<Node>] See {#keywords} @param splat [Node] See {#splat} @param kwarg_splat [Node] See {#kwarg_splat}
Public Instance Methods
Source
# File lib/sass/script/tree/funcall.rb, line 103 def children res = @args + @keywords.values res << @splat if @splat res << @kwarg_splat if @kwarg_splat res end
Returns the arguments to the function.
@return [Array<Node>] @see Node#children
Source
# File lib/sass/script/tree/funcall.rb, line 111 def deep_copy node = dup node.instance_variable_set('@args', args.map {|a| a.deep_copy}) copied_keywords = Sass::Util::NormalizedMap.new @keywords.as_stored.each {|k, v| copied_keywords[k] = v.deep_copy} node.instance_variable_set('@keywords', copied_keywords) node end
@see Node#deep_copy
Source
# File lib/sass/script/tree/funcall.rb, line 68 def inspect args = @args.map {|a| a.inspect}.join(', ') keywords = @keywords.as_stored.to_a.map {|k, v| "$#{k}: #{v.inspect}"}.join(', ') if self.splat splat = args.empty? && keywords.empty? ? "" : ", " splat = "#{splat}#{self.splat.inspect}..." splat = "#{splat}, #{kwarg_splat.inspect}..." if kwarg_splat end "#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})" end
@return [String] A string representation of the function call
Source
# File lib/sass/script/tree/funcall.rb, line 80 def to_sass(opts = {}) arg_to_sass = lambda do |arg| sass = arg.to_sass(opts) sass = "(#{sass})" if arg.is_a?(Sass::Script::Tree::ListLiteral) && arg.separator == :comma sass end args = @args.map(&arg_to_sass) keywords = @keywords.as_stored.to_a.map {|k, v| "$#{dasherize(k, opts)}: #{arg_to_sass[v]}"} if self.splat splat = "#{arg_to_sass[self.splat]}..." kwarg_splat = "#{arg_to_sass[self.kwarg_splat]}..." if self.kwarg_splat end arglist = [args, splat, keywords, kwarg_splat].flatten.compact.join(', ') "#{dasherize(name, opts)}(#{arglist})" end
@see Node#to_sass
Protected Instance Methods
Source
# File lib/sass/script/tree/funcall.rb, line 127 def _perform(environment) args = @args.each_with_index. map {|a, i| perform_arg(a, environment, signature && signature.args[i])} keywords = Sass::Util.map_hash(@keywords) do |k, v| [k, perform_arg(v, environment, k.tr('-', '_'))] end splat = Sass::Tree::Visitors::Perform.perform_splat( @splat, keywords, @kwarg_splat, environment) fn = @callable || environment.function(@name) if fn && fn.origin == :stylesheet environment.stack.with_function(filename, line, name) do return without_original(perform_sass_fn(fn, args, splat, environment)) end end args = construct_ruby_args(ruby_name, args, splat, environment) if Sass::Script::Functions.callable?(ruby_name) && (!fn || fn.origin == :builtin) local_environment = Sass::Environment.new(environment.global_env, environment.options) local_environment.caller = Sass::ReadOnlyEnvironment.new(environment, environment.options) result = local_environment.stack.with_function(filename, line, name) do opts(Sass::Script::Functions::EvaluationContext.new( local_environment).send(ruby_name, *args)) end without_original(result) else opts(to_literal(args)) end rescue ArgumentError => e reformat_argument_error(e) end
Evaluates the function call.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Sass::Script::Value] The SassScript object that is the value of the function call @raise [Sass::SyntaxError] if the function call raises an ArgumentError
Source
# File lib/sass/script/tree/funcall.rb, line 163 def to_literal(args) to_value(args) end
Compass historically overrode this before it changed name to {Funcall#to_value}. We should get rid of it in the future.
Source
# File lib/sass/script/tree/funcall.rb, line 170 def to_value(args) Sass::Script::Value::String.new("#{name}(#{args.join(', ')})") end
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.