Class: Sass::Script::Interpolation

Inherits:
Node
  • Object
show all
Defined in:
lib/sass/script/interpolation.rb

Overview

A SassScript object representing #{} interpolation outside a string.

Instance Attribute Summary

Attributes inherited from Node

#context, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#dasherize, #perform

Constructor Details

#initialize(before, mid, after, wb, wa) ⇒ Interpolation

Interpolation in a property is of the form before #{mid} after.

Parameters:

  • before (Node)

    The SassScript before the interpolation

  • mid (Node)

    The SassScript within the interpolation

  • after (Node)

    The SassScript after the interpolation

  • wb (Boolean)

    Whether there was whitespace between before and #{

  • wa (Boolean)

    Whether there was whitespace between } and after



13
14
15
16
17
18
19
# File 'lib/sass/script/interpolation.rb', line 13

def initialize(before, mid, after, wb, wa)
  @before = before
  @mid = mid
  @after = after
  @whitespace_before = wb
  @whitespace_after = wa
end

Instance Method Details

#_perform(environment) ⇒ Sass::Script::String (protected)

Evaluates the interpolation.

Parameters:

  • environment (Sass::Environment)

    The environment in which to evaluate the SassScript

Returns:



52
53
54
55
56
57
58
59
60
61
# File 'lib/sass/script/interpolation.rb', line 52

def _perform(environment)
  res = ""
  res << @before.perform(environment).to_s if @before
  res << " " if @before && @whitespace_before
  val = @mid.perform(environment)
  res << (val.is_a?(Sass::Script::String) ? val.value : val.to_s)
  res << " " if @after && @whitespace_after
  res << @after.perform(environment).to_s if @after
  Sass::Script::String.new(res)
end

#childrenArray<Node>

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

Returns:

See Also:



42
43
44
# File 'lib/sass/script/interpolation.rb', line 42

def children
  [@before, @mid, @after].compact
end

#inspectString

Returns A human-readable s-expression representation of the interpolation.

Returns:

  • (String)

    A human-readable s-expression representation of the interpolation



22
23
24
# File 'lib/sass/script/interpolation.rb', line 22

def inspect
  "(interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
end

#to_sass(opts = {})

See Also:



27
28
29
30
31
32
33
34
35
# File 'lib/sass/script/interpolation.rb', line 27

def to_sass(opts = {})
  res = ""
  res << @before.to_sass(opts) if @before
  res << ' ' if @before && @whitespace_before
  res << '#{' << @mid.to_sass(opts) << '}'
  res << ' ' if @after && @whitespace_after
  res << @after.to_sass(opts) if @after
  res
end