Class: Sass::Script::Funcall
Overview
A SassScript parse node representing a function call.
A function call either calls one of the functions in Functions, or if no function with the given name exists it returns a string representation of the function call.
Instance Attribute Summary collapse
-
#args ⇒ Array<Script::Node>
readonly
The arguments to the function.
-
#name ⇒ String
readonly
The name of the function.
Instance Method Summary collapse
-
#initialize(name, args) ⇒ Funcall
constructor
A new instance of Funcall.
-
#inspect ⇒ String
A string representation of the function call.
-
#perform(environment) ⇒ Literal
Evaluates the function call.
Constructor Details
#initialize(name, args) ⇒ Funcall
Returns a new instance of Funcall.
22 23 24 25 |
# File 'lib/sass/script/funcall.rb', line 22
def initialize(name, args)
@name = name
@args = args
end
|
Instance Attribute Details
#args ⇒ Array<Script::Node> (readonly)
The arguments to the function.
18 19 20 |
# File 'lib/sass/script/funcall.rb', line 18
def args
@args
end
|
#name ⇒ String (readonly)
The name of the function.
13 14 15 |
# File 'lib/sass/script/funcall.rb', line 13
def name
@name
end
|
Instance Method Details
#inspect ⇒ String
Returns A string representation of the function call.
28 29 30 |
# File 'lib/sass/script/funcall.rb', line 28
def inspect
"#{name}(#{args.map {|a| a.inspect}.join(', ')})"
end
|
#perform(environment) ⇒ Literal
Evaluates the function call.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sass/script/funcall.rb', line 37
def perform(environment)
args = self.args.map {|a| a.perform(environment)}
unless Haml::Util.has?(:public_instance_method, Functions, name) && name !~ /^__/
return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
end
return Functions::EvaluationContext.new(environment.options).send(name, *args)
rescue ArgumentError => e
raise e unless e.backtrace.first =~ /:in `(block in )?(#{name}|perform)'$/
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
end
|