Class | Sass::Script::StringInterpolation
In: | lib/sass/script/string_interpolation.rb
Parent: | Node

A SassScript object representing `#{}` interpolation within a string.

@see Interpolation

### Methods

_perform children inspect new to_sass

### Public Class methods

new(before, mid, after)

Interpolation in a string is of the form `"before #{mid} after"`, where `before` and `after` may include more interpolation.

@param before [Node] The string before the interpolation @param mid [Node] The SassScript within the interpolation @param after [Node] The string after the interpolation

[Source]

        # File lib/sass/script/string_interpolation.rb, line 12
    12:     def initialize(before, mid, after)
    13:       @before = before
    14:       @mid = mid
    15:       @after = after
    16:     end

### Public Instance methods

children()

Returns the three components of the interpolation, `before`, `mid`, and `after`.

@return [Array<Node>] @see initialize @see Node#children

[Source]

        # File lib/sass/script/string_interpolation.rb, line 58
    58:     def children
    59:       [@before, @mid, @after].compact
    60:     end

inspect()

@return [String] A human-readable s-expression representation of the interpolation

[Source]

        # File lib/sass/script/string_interpolation.rb, line 19
    19:     def inspect
    20:       "(string_interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
    21:     end

to_sass(opts = {})

@see Node#to_sass

[Source]

        # File lib/sass/script/string_interpolation.rb, line 24
    24:     def to_sass(opts = {})
    25:       # We can get rid of all of this when we remove the deprecated :equals context
    26:       before_unquote, before_quote_char, before_str = parse_str(@before.to_sass(opts))
    27:       after_unquote, after_quote_char, after_str = parse_str(@after.to_sass(opts))
    28:       unquote = before_unquote || after_unquote ||
    29:         (before_quote_char && !after_quote_char && !after_str.empty?) ||
    30:         (!before_quote_char && after_quote_char && !before_str.empty?)
    31:       quote_char =
    32:         if before_quote_char && after_quote_char && before_quote_char != after_quote_char
    33:           before_str.gsub!("\\'", "'")
    34:           before_str.gsub!('"', "\\\"")
    35:           after_str.gsub!("\\'", "'")
    36:           after_str.gsub!('"', "\\\"")
    37:           '"'
    38:         else
    39:           before_quote_char || after_quote_char
    40:         end
    41:
    42:       res = ""
    43:       res << 'unquote(' if unquote
    44:       res << quote_char if quote_char
    45:       res << before_str
    46:       res << '#{' << @mid.to_sass(opts) << '}'
    47:       res << after_str
    48:       res << quote_char if quote_char
    49:       res << ')' if unquote
    50:       res
    51:     end

### Protected Instance methods

_perform(environment)

Evaluates the interpolation.

@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Sass::Script::String] The SassScript string that is the value of the interpolation

[Source]

        # File lib/sass/script/string_interpolation.rb, line 68
    68:     def _perform(environment)
    69:       res = ""
    70:       before = @before.perform(environment)
    71:       res << before.value
    72:       mid = @mid.perform(environment)
    73:       res << (mid.is_a?(Sass::Script::String) ? mid.value : mid.to_s)
    74:       res << @after.perform(environment).value
    75:       Sass::Script::String.new(res, before.type)
    76:     end

[Validate]