Class: Sass::Script::Funcall
- Inherits:
-
Node
- Object
- Node
- Sass::Script::Funcall
- Defined in:
- /var/www/sass-pages/.sass/lib/sass/script/funcall.rb
Overview
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.
Instance Attribute Summary
- - (Array<Script::Node>) args readonly The arguments to the function.
- - ({String => Script::Node}) keywords readonly The keyword arguments to the function.
- - (String) name readonly The name of the function.
Instance Method Summary
- - (Literal) _perform(environment) protected Evaluates the function call.
- - (Array<Node>) children Returns the arguments to the function.
- - deep_copy
- - (Funcall) initialize(name, args, keywords) constructor A new instance of Funcall.
- - (String) inspect A string representation of the function call.
-
- to_literal(args)
protected
This method is factored out from
_performso that compass can override it with a cross-browser implementation for functions that require vendor prefixes in the generated css. - - to_sass(opts = {})
Methods inherited from Node
Constructor Details
- (Funcall) initialize(name, args, keywords)
A new instance of Funcall
29 30 31 32 33 34 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 29
def initialize(name, args, keywords)
@name = name
@args = args
@keywords = keywords
super()
end
|
Instance Attribute Details
- (Array<Script::Node>) args (readonly)
The arguments to the function.
19 20 21 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 19
def args
@args
end
|
- ({String => Script::Node}) keywords (readonly)
The keyword arguments to the function.
24 25 26 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 24
def keywords
@keywords
end
|
- (String) name (readonly)
The name of the function.
14 15 16 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 14
def name
@name
end
|
Instance Method Details
- (Literal) _perform(environment) (protected)
Evaluates the function call.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File '/var/www/sass-pages/.sass/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
# If this is a legitimate Ruby-raised argument error, re-raise it.
# Otherwise, it's an error in the user's stylesheet, so wrap it.
if e.message =~ /^wrong number of arguments \(\d+ for \d+\)/ &&
e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
raise e
end
raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
end
|
- (Array<Node>) children
Returns the arguments to the function.
56 57 58 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 56
def children
@args + @keywords.values
end
|
- deep_copy
61 62 63 64 65 66 |
# File '/var/www/sass-pages/.sass/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
|
- (String) inspect
A string representation of the function call
37 38 39 40 41 42 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 37
def inspect
args = @args.map {|a| a.inspect}.join(', ')
keywords = Sass::Util.hash_to_a(@keywords).
map {|k, v| "$#{k}: #{v.inspect}"}.join(', ')
"#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
end
|
- to_literal(args) (protected)
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.
103 104 105 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 103
def to_literal(args)
Script::String.new("#{name}(#{args.join(', ')})")
end
|
- to_sass(opts = {})
45 46 47 48 49 50 |
# File '/var/www/sass-pages/.sass/lib/sass/script/funcall.rb', line 45
def to_sass(opts = {})
args = @args.map {|a| a.to_sass(opts)}.join(', ')
keywords = Sass::Util.hash_to_a(@keywords).
map {|k, v| "$#{dasherize(k, opts)}: #{v.to_sass(opts)}"}.join(', ')
"#{dasherize(name, opts)}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
end
|