class Sass::Script::Tree::Interpolation
A SassScript object representing `#{}` interpolation outside a string.
@see StringInterpolation
Attributes
@return [Node] The SassScript after the interpolation
@return [Node] The SassScript before the interpolation
The type of interpolation deprecation for this node.
This can be `:none`, indicating that the node doesn't use deprecated interpolation; `:immediate`, indicating that a deprecation warning should be emitted as soon as possible; or `:potential`, indicating that a deprecation warning should be emitted if the resulting string is used in a way that would distinguish it from a list.
@return [Symbol]
@return [Node] The SassScript within the interpolation
@return [Boolean] Whether the original format of the interpolation was
plain text, not an interpolation. This is used when converting back to SassScript.
@return [Boolean] Whether a color value passed to the interpolation should
generate a warning.
@return [Boolean] Whether there was whitespace between `}` and `after`
@return [Boolean] Whether there was whitespace between `before` and `#{`
Public Class Methods
Interpolation in a property is of the form `before #{mid} after`.
@param before [Node] See {Interpolation#before} @param mid [Node] See {Interpolation#mid} @param after [Node] See {Interpolation#after} @param wb [Boolean] See {Interpolation#whitespace_before} @param wa [Boolean] See {Interpolation#whitespace_after} @param #originally_text [Boolean] See {Interpolation#originally_text} @param #warn_for_color [Boolean] See {Interpolation#warn_for_color} @comment
rubocop:disable ParameterLists
# File lib/sass/script/tree/interpolation.rb, line 52 def initialize(before, mid, after, wb, wa, opts = {}) # rubocop:enable ParameterLists @before = before @mid = mid @after = after @whitespace_before = wb @whitespace_after = wa @originally_text = opts[:originally_text] || false @warn_for_color = opts[:warn_for_color] || false @deprecation = opts[:deprecation] || :none end
Public Instance Methods
Returns the three components of the interpolation, `before`, `mid`, and `after`.
@return [Array<Node>] @see initialize @see Sass::Script::Tree::Node#children
# File lib/sass/script/tree/interpolation.rb, line 102 def children [@before, @mid, @after].compact end
@see Sass::Script::Tree::Node#deep_copy
# File lib/sass/script/tree/interpolation.rb, line 107 def deep_copy node = dup node.instance_variable_set('@before', @before.deep_copy) if @before node.instance_variable_set('@mid', @mid.deep_copy) node.instance_variable_set('@after', @after.deep_copy) if @after node end
@return [String] A human-readable s-expression representation of the interpolation
# File lib/sass/script/tree/interpolation.rb, line 65 def inspect "(interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})" end
Returns an `unquote()` expression that will evaluate to the same value as this interpolation.
@return [Sass::Script::Tree::Node]
# File lib/sass/script/tree/interpolation.rb, line 88 def to_quoted_equivalent Funcall.new( "unquote", [to_string_interpolation(self)], Sass::Util::NormalizedMap.new, nil, nil) end
@see Sass::Script::Tree::Node#to_sass
# File lib/sass/script/tree/interpolation.rb, line 70 def to_sass(opts = {}) return to_quoted_equivalent.to_sass if deprecation == :immediate res = "" res << @before.to_sass(opts) if @before res << ' ' if @before && @whitespace_before res << '#{' unless @originally_text res << @mid.to_sass(opts) res << '}' unless @originally_text res << ' ' if @after && @whitespace_after res << @after.to_sass(opts) if @after res end
Protected Instance Methods
Converts a script node into a corresponding string interpolation expression.
@param node_or_interp [Sass::Script::Tree::Node] @return [Sass::Script::Tree::StringInterpolation]
# File lib/sass/script/tree/interpolation.rb, line 122 def to_string_interpolation(node_or_interp) unless node_or_interp.is_a?(Interpolation) node = node_or_interp return string_literal(node.value.to_s) if node.is_a?(Literal) if node.is_a?(StringInterpolation) return concat(string_literal(node.quote), concat(node, string_literal(node.quote))) end return StringInterpolation.new(string_literal(""), node, string_literal("")) end interp = node_or_interp after_string_or_interp = if interp.after to_string_interpolation(interp.after) else string_literal("") end if interp.after && interp.whitespace_after after_string_or_interp = concat(string_literal(' '), after_string_or_interp) end mid_string_or_interp = to_string_interpolation(interp.mid) before_string_or_interp = if interp.before to_string_interpolation(interp.before) else string_literal("") end if interp.before && interp.whitespace_before before_string_or_interp = concat(before_string_or_interp, string_literal(' ')) end concat(before_string_or_interp, concat(mid_string_or_interp, after_string_or_interp)) end