class Sass::Script::Tree::StringInterpolation

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

@see Interpolation

Attributes

after[R]

@return [StringInterpolation, Literal]

The string literal or string interpolation before this interpolation.
before[R]

@return [Literal] The string literal before this interpolation.

mid[R]

@return [Node] The SassScript within the interpolation

Public Class Methods

new(before, mid, after) click to toggle source

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

@param before [StringInterpolation, Literal] See {StringInterpolation#before} @param mid [Node] See {StringInterpolation#mid} @param after [Literal] See {StringInterpolation#after}

# File lib/sass/script/tree/string_interpolation.rb, line 39
def initialize(before, mid, after)
  @before = before
  @mid = mid
  @after = after
end

Public Instance Methods

children() click to toggle source

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/string_interpolation.rb, line 69
def children
  [@before, @mid, @after].compact
end
deep_copy() click to toggle source

@see Sass::Script::Tree::Node#deep_copy

# File lib/sass/script/tree/string_interpolation.rb, line 74
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
inspect() click to toggle source

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

# File lib/sass/script/tree/string_interpolation.rb, line 46
def inspect
  "(string_interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
end
quote() click to toggle source

Returns the quote character that should be used to wrap a Sass representation of this interpolation.

# File lib/sass/script/tree/string_interpolation.rb, line 29
def quote
  quote_for(self) || '"'
end
to_sass(opts = {}) click to toggle source

@see Sass::Script::Tree::Node#to_sass

# File lib/sass/script/tree/string_interpolation.rb, line 51
def to_sass(opts = {})
  quote = type == :string ? opts[:quote] || quote_for(self) || '"' : :none
  opts = opts.merge(:quote => quote)

  res = ""
  res << quote if quote != :none
  res << _to_sass(before, opts)
  res << '#{' << @mid.to_sass(opts.merge(:quote => nil)) << '}'
  res << _to_sass(after, opts)
  res << quote if quote != :none
  res
end
type() click to toggle source

Whether this is a CSS string or a CSS identifier. The difference is that strings are written with double-quotes, while identifiers aren't.

String interpolations are only ever identifiers if they're quote-like functions such as `url()`.

@return [Symbol] `:string` or `:identifier`

# File lib/sass/script/tree/string_interpolation.rb, line 23
def type
  @before.value.type
end

Protected Instance Methods

_perform(environment) click to toggle source

Evaluates the interpolation.

@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Sass::Script::Value::String]

The SassScript string that is the value of the interpolation
# File lib/sass/script/tree/string_interpolation.rb, line 89
def _perform(environment)
  res = ""
  before = @before.perform(environment)
  res << before.value
  mid = @mid.perform(environment)
  res << (mid.is_a?(Sass::Script::Value::String) ? mid.value : mid.to_s(:quote => :none))
  res << @after.perform(environment).value
  opts(Sass::Script::Value::String.new(res, before.type))
end