Class: Sass::Script::Funcall

Inherits:
Node show all
Defined in:
lib/sass/script/funcall.rb

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

Attributes inherited from Node

#context, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#dasherize, #perform

Constructor Details

#initialize(name, args) ⇒ Funcall

Returns a new instance of Funcall.

Parameters:



22
23
24
25
26
# File 'lib/sass/script/funcall.rb', line 22

def initialize(name, args)
  @name = name
  @args = args
  super()
end

Instance Attribute Details

#argsArray<Script::Node> (readonly)

The arguments to the function.

Returns:



18
19
20
# File 'lib/sass/script/funcall.rb', line 18

def args
  @args
end

#nameString (readonly)

The name of the function.

Returns:



13
14
15
# File 'lib/sass/script/funcall.rb', line 13

def name
  @name
end

Instance Method Details

#_perform(environment) ⇒ Literal (protected)

Evaluates the function call.

Parameters:

  • environment (Sass::Environment)

    The environment in which to evaluate the SassScript

Returns:

  • (Literal)

    The SassScript object that is the value of the function call

Raises:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sass/script/funcall.rb', line 53

def _perform(environment)
  args = self.args.map {|a| a.perform(environment)}
  ruby_name = name.gsub('-', '_')
  unless Haml::Util.has?(:public_instance_method, Functions, ruby_name) && ruby_name !~ /^__/
    return Script::String.new("#{name}(#{args.map {|a| a.perform(environment)}.join(', ')})")
  end

  result = Functions::EvaluationContext.new(environment.options).send(ruby_name, *args)
  result.options = environment.options
  return result
rescue ArgumentError => e
  raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
  raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
end

#childrenArray<Node>

Returns the arguments to the function.

Returns:

See Also:



42
43
44
# File 'lib/sass/script/funcall.rb', line 42

def children
  @args
end

#inspectString

Returns A string representation of the function call.

Returns:

  • (String)

    A string representation of the function call



29
30
31
# File 'lib/sass/script/funcall.rb', line 29

def inspect
  "#{name}(#{args.map {|a| a.inspect}.join(', ')})"
end

#to_sass(opts = {})

See Also:



34
35
36
# File 'lib/sass/script/funcall.rb', line 34

def to_sass(opts = {})
  "#{dasherize(name, opts)}(#{args.map {|a| a.to_sass(opts)}.join(', ')})"
end