Class: Sass::Script::Tree::Interpolation

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

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Node

#filename, #line, #options, #source_range

Instance Method Summary collapse

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

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

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

Parameters:



36
37
38
39
40
41
42
43
44
# File 'lib/sass/script/tree/interpolation.rb', line 36

def initialize(before, mid, after, wb, wa, originally_text = false)
  # rubocop:enable ParameterLists
  @before = before
  @mid = mid
  @after = after
  @whitespace_before = wb
  @whitespace_after = wa
  @originally_text = originally_text
end

Instance Attribute Details

#afterNode (readonly)

Returns The SassScript after the interpolation.

Returns:

  • (Node)

    The SassScript after the interpolation



13
14
15
# File 'lib/sass/script/tree/interpolation.rb', line 13

def after
  @after
end

#beforeNode (readonly)

Returns The SassScript before the interpolation.

Returns:

  • (Node)

    The SassScript before the interpolation



7
8
9
# File 'lib/sass/script/tree/interpolation.rb', line 7

def before
  @before
end

#midNode (readonly)

Returns The SassScript within the interpolation.

Returns:

  • (Node)

    The SassScript within the interpolation



10
11
12
# File 'lib/sass/script/tree/interpolation.rb', line 10

def mid
  @mid
end

#originally_textBoolean (readonly)

Returns Whether the original format of the interpolation was plain text, not an interpolation. This is used when converting back to SassScript.

Returns:

  • (Boolean)

    Whether the original format of the interpolation was plain text, not an interpolation. This is used when converting back to SassScript.



24
25
26
# File 'lib/sass/script/tree/interpolation.rb', line 24

def originally_text
  @originally_text
end

#whitespace_afterBoolean (readonly)

Returns Whether there was whitespace between } and after.

Returns:

  • (Boolean)

    Whether there was whitespace between } and after



19
20
21
# File 'lib/sass/script/tree/interpolation.rb', line 19

def whitespace_after
  @whitespace_after
end

#whitespace_beforeBoolean (readonly)

Returns Whether there was whitespace between before and #{.

Returns:

  • (Boolean)

    Whether there was whitespace between before and #{



16
17
18
# File 'lib/sass/script/tree/interpolation.rb', line 16

def whitespace_before
  @whitespace_before
end

Instance Method Details

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

Evaluates the interpolation.

Parameters:

  • environment (Sass::Environment)

    The environment in which to evaluate the SassScript

Returns:



89
90
91
92
93
94
95
96
97
98
# File 'lib/sass/script/tree/interpolation.rb', line 89

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::Value::String) ? val.value : val.to_s)
  res << " " if @after && @whitespace_after
  res << @after.perform(environment).to_s if @after
  opts(Sass::Script::Value::String.new(res))
end

#childrenArray<Node>

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

Returns:

See Also:



69
70
71
# File 'lib/sass/script/tree/interpolation.rb', line 69

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

#deep_copy

See Also:



74
75
76
77
78
79
80
# File 'lib/sass/script/tree/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

#inspectString

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

Returns:

  • (String)

    A human-readable s-expression representation of the interpolation



47
48
49
# File 'lib/sass/script/tree/interpolation.rb', line 47

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

#to_sass(opts = {})

See Also:



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

def to_sass(opts = {})
  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