Class: Sass::Script::Tree::Funcall
- Inherits:
- Node
- Object
- Node
- Sass::Script::Tree::Funcall
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/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)
- - (Array<Node>) args readonly
The arguments to the function.
- - (Sass::Util::NormalizedMap<Node>) keywords readonly
The keyword arguments to the function.
- - (Node?) kwarg_splat
The second splat argument for this function, if one exists.
- - (String) name readonly
The name of the function.
- - (Node?) splat
The first splat argument for this function, if one exists.
Attributes inherited from Node
#css_variable_warning, #filename, #line, #options, #source_range
Instance Method Summary (collapse)
- - (Sass::Script::Value) _perform(environment) protected
Evaluates the function call.
- - (Array<Node>) children
Returns the arguments to the function.
- - deep_copy
- - (Funcall) initialize(name, args, keywords, splat, kwarg_splat) constructor
A new instance of Funcall.
- - (String) inspect
A string representation of the function call.
- - to_literal(args) protected
Compass historically overrode this before it changed name to #to_value.
- - to_sass(opts = {})
- - to_value(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.
Methods inherited from Node
#dasherize, #force_division!, #opts, #perform
Constructor Details
- (Funcall) initialize(name, args, keywords, splat, kwarg_splat)
Returns a new instance of Funcall
47 48 49 50 51 52 53 54 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 47
def initialize(name, args, keywords, splat, kwarg_splat)
@name = name
@args = args
@keywords = keywords
@splat = splat
@kwarg_splat = kwarg_splat
super()
end |
Instance Attribute Details
- (Array<Node>) args (readonly)
The arguments to the function.
19 20 21 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 19
def args
@args
end |
- (Sass::Util::NormalizedMap<Node>) keywords (readonly)
The keyword arguments to the function.
24 25 26 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 24
def keywords
@keywords
end |
- (Node?) kwarg_splat
The second splat argument for this function, if one exists.
If this exists, it’s always a map of keyword arguments, and #splat is always either a list or an arglist.
40 41 42 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 40
def kwarg_splat
@kwarg_splat
end |
- (String) name (readonly)
The name of the function.
14 15 16 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 14
def name
@name
end |
- (Node?) splat
The first splat argument for this function, if one exists.
This could be a list of positional arguments, a map of keyword arguments, or an arglist containing both.
32 33 34 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 32
def splat
@splat
end |
Instance Method Details
- (Sass::Script::Value) _perform(environment) (protected)
Evaluates the function call.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 122
def _perform(environment)
args = Sass::Util.enum_with_index(@args).
map {|a, i| perform_arg(a, environment, signature && signature.args[i])}
keywords = Sass::Util.map_hash(@keywords) do |k, v|
[k, perform_arg(v, environment, k.tr('-', '_'))]
end
splat = Sass::Tree::Visitors::Perform.perform_splat(
@splat, keywords, @kwarg_splat, environment)
if (fn = environment.function(@name))
css_variable_warning.warn! if css_variable_warning
return without_original(perform_sass_fn(fn, args, splat, environment))
end
args = construct_ruby_args(ruby_name, args, splat, environment)
if Sass::Script::Functions.callable?(ruby_name)
css_variable_warning.warn! if css_variable_warning
local_environment = Sass::Environment.new(environment.global_env, environment.options)
local_environment.caller = Sass::ReadOnlyEnvironment.new(environment, environment.options)
result = opts(Sass::Script::Functions::EvaluationContext.new(
local_environment).send(ruby_name, *args))
without_original(result)
else
opts(to_literal(args))
end
rescue ArgumentError => e
reformat_argument_error(e)
end |
- (Array<Node>) children
Returns the arguments to the function.
98 99 100 101 102 103 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 98
def children
res = @args + @keywords.values
res << @splat if @splat
res << @kwarg_splat if @kwarg_splat
res
end |
- deep_copy
106 107 108 109 110 111 112 113 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 106
def deep_copy
node = dup
node.instance_variable_set('@args', args.map {|a| a.deep_copy})
copied_keywords = Sass::Util::NormalizedMap.new
@keywords.as_stored.each {|k, v| copied_keywords[k] = v.deep_copy}
node.instance_variable_set('@keywords', copied_keywords)
node
end |
- (String) inspect
Returns A string representation of the function call
57 58 59 60 61 62 63 64 65 66 67 68 69 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 57
def inspect
args = @args.map {|a| a.inspect}.join(', ')
keywords = Sass::Util.hash_to_a(@keywords.as_stored).
map {|k, v| "$#{k}: #{v.inspect}"}.join(', ')
# rubocop:disable RedundantSelf
if self.splat
splat = args.empty? && keywords.empty? ? "" : ", "
splat = "#{splat}#{self.splat.inspect}..."
splat = "#{splat}, #{kwarg_splat.inspect}..." if kwarg_splat
end
# rubocop:enable RedundantSelf
"#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})"
end |
- to_literal(args) (protected)
Compass historically overrode this before it changed name to #to_value. We should get rid of it in the future.
154 155 156 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 154
def to_literal(args)
to_value(args)
end |
- to_sass(opts = {})
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 72
def to_sass(opts = {})
arg_to_sass = lambda do |arg|
sass = arg.to_sass(opts)
sass = "(#{sass})" if arg.is_a?(Sass::Script::Tree::ListLiteral) && arg.separator == :comma
sass
end
args = @args.map(&arg_to_sass)
keywords = Sass::Util.hash_to_a(@keywords.as_stored).
map {|k, v| "$#{dasherize(k, opts)}: #{arg_to_sass[v]}"}
# rubocop:disable RedundantSelf
if self.splat
splat = "#{arg_to_sass[self.splat]}..."
kwarg_splat = "#{arg_to_sass[self.kwarg_splat]}..." if self.kwarg_splat
end
# rubocop:enable RedundantSelf
arglist = [args, splat, keywords, kwarg_splat].flatten.compact.join(', ')
"#{dasherize(name, opts)}(#{arglist})"
end |
- to_value(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.
161 162 163 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/funcall.rb', line 161
def to_value(args)
Sass::Script::Value::String.new("#{name}(#{args.join(', ')})")
end |