Class/Module Index [+]

Quicksearch

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]

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 56
def children
  @args + @keywords.values
end
deep_copy() click to toggle source

@see Node#deep_copy

# File lib/sass/script/funcall.rb, line 61
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 37
def inspect
  args = @args.map {|a| a.inspect}.join(', ')
  keywords = @keywords.sort_by {|k, v| k}.
      map {|k, v| "$#{k}: #{v.inspect}"}.join(', ')
  "#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
end
to_sass(opts = {}) click to toggle source

@see Node#to_sass

# File lib/sass/script/funcall.rb, line 45
def to_sass(opts = {})
  args = @args.map {|a| a.to_sass(opts)}.join(', ')
  keywords = @keywords.sort_by {|k, v| k}.
    map {|k, v| "$#{dasherize(k, opts)}: #{v.to_sass(opts)}"}.join(', ')
  "#{dasherize(name, opts)}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
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 75
def _perform(environment)
  args = @args.map {|a| a.perform(environment)}
  if fn = environment.function(@name)
    keywords = Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
    return perform_sass_fn(fn, args, keywords)
  end

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

  unless Functions.callable?(ruby_name)
    opts(to_literal(args))
  else
    opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
  end
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
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 98
def to_literal(args)
  Script::String.new("#{name}(#{args.join(', ')})")
end

Public Class Methods

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

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.