Class | Sass::Script::Funcall |
In: |
lib/sass/script/funcall.rb
|
Parent: | Node |
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.
args | [R] |
The arguments to the function.
@return [Array<Script::Node>] |
name | [R] |
The name of the function.
@return [String] |
@param name [String] See \{name} @param name [Array<Script::Node>] See \{args}
# File lib/sass/script/funcall.rb, line 31 31: def initialize(name, args) 32: @name = name 33: @args = args 34: super() 35: end
Returns the arguments to the function.
@return [Array<Node>] @see Node#children
# File lib/sass/script/funcall.rb, line 51 51: def children 52: @args 53: end
Don‘t set the context for child nodes if this is `url()`, since `url()` allows quoted strings.
@param context [Symbol] @see Node#context=
# File lib/sass/script/funcall.rb, line 25 25: def context=(context) 26: super unless @name == "url" 27: end
@see Node#to_sass
# File lib/sass/script/funcall.rb, line 43 43: def to_sass(opts = {}) 44: "#{dasherize(name, opts)}(#{args.map {|a| a.to_sass(opts)}.join(', ')})" 45: end
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 62 62: def _perform(environment) 63: args = self.args.map {|a| a.perform(environment)} 64: ruby_name = name.gsub('-', '_') 65: unless Haml::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/ 66: return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})") 67: end 68: 69: result = Functions::EvaluationContext.new(environment.options).send(ruby_name, *args) 70: result.options = environment.options 71: return result 72: rescue ArgumentError => e 73: raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/} 74: raise Sass::SyntaxError.new("#{e.message} for `#{name}'") 75: end