Class: Sass::Script::Tree::Funcall
- Inherits:
-
Node
- Object
- Node
- Sass::Script::Tree::Funcall
- Defined in:
- .ruby-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)
-
#args ⇒ Array<Node>
readonly
The arguments to the function.
-
#callable ⇒ Sass::Callable
readonly
The callable to be invoked.
-
#keywords ⇒ Sass::Util::NormalizedMap<Node>
readonly
The keyword arguments to the function.
-
#kwarg_splat ⇒ Node?
The second splat argument for this function, if one exists.
-
#name ⇒ String
readonly
The name of the function.
-
#splat ⇒ Node?
The first splat argument for this function, if one exists.
Attributes inherited from Node
#filename, #line, #options, #source_range
Instance Method Summary (collapse)
-
#children ⇒ Array<Node>
Returns the arguments to the function.
- #deep_copy ⇒ Object
-
#initialize(name_or_callable, args, keywords, splat, kwarg_splat) ⇒ Funcall
constructor
A new instance of Funcall.
-
#inspect ⇒ String
A string representation of the function call.
- #to_sass(opts = {}) ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(name_or_callable, args, keywords, splat, kwarg_splat) ⇒ Funcall
Returns a new instance of Funcall
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 52 def initialize(name_or_callable, args, keywords, splat, kwarg_splat) if name_or_callable.is_a?(Sass::Callable) @callable = name_or_callable @name = name_or_callable.name else @callable = nil @name = name_or_callable end @args = args @keywords = keywords @splat = splat @kwarg_splat = kwarg_splat super() end |
Constructor Details
#initialize(name_or_callable, args, keywords, splat, kwarg_splat) ⇒ Funcall
Returns a new instance of Funcall
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 52 def initialize(name_or_callable, args, keywords, splat, kwarg_splat) if name_or_callable.is_a?(Sass::Callable) @callable = name_or_callable @name = name_or_callable.name else @callable = nil @name = name_or_callable end @args = args @keywords = keywords @splat = splat @kwarg_splat = kwarg_splat super() end |
Instance Attribute Details
#args ⇒ Array<Node> (readonly)
The arguments to the function.
24 25 26 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 24 def args @args end |
#callable ⇒ Sass::Callable (readonly)
The callable to be invoked
19 20 21 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 19 def callable @callable end |
#keywords ⇒ Sass::Util::NormalizedMap<Node> (readonly)
The keyword arguments to the function.
29 30 31 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 29 def keywords @keywords end |
#kwarg_splat ⇒ Node?
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.
45 46 47 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 45 def kwarg_splat @kwarg_splat end |
#name ⇒ String (readonly)
The name of the function.
14 15 16 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 14 def name @name end |
#splat ⇒ Node?
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.
37 38 39 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 37 def splat @splat end |
Instance Method Details
#children ⇒ Array<Node>
Returns the arguments to the function.
107 108 109 110 111 112 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 107 def children res = @args + @keywords.values res << @splat if @splat res << @kwarg_splat if @kwarg_splat res end |
#deep_copy ⇒ Object
115 116 117 118 119 120 121 122 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 115 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 |
#inspect ⇒ String
Returns A string representation of the function call
68 69 70 71 72 73 74 75 76 77 78 79 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 68 def inspect args = @args.map {|a| a.inspect}.join(', ') keywords = @keywords.as_stored.to_a.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_sass(opts = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File '.ruby-sass/lib/sass/script/tree/funcall.rb', line 82 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 = @keywords.as_stored.to_a.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 |