Class: Sass::Script::Interpolation

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

Overview

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

See Also:

Instance Method Summary

Methods inherited from Node

#dasherize, #opts, #perform

Constructor Details

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

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

Parameters:

  • (Node) before — The SassScript before the interpolation
  • (Node) mid — The SassScript within the interpolation
  • (Node) after — The SassScript after the interpolation
  • (Boolean) wb — Whether there was whitespace between before and #{
  • (Boolean) wa — Whether there was whitespace between } and after
  • (Boolean) originally_text (defaults to: false) — Whether the original format of the interpolation was plain text, not an interpolation. This is used when converting back to SassScript.


17
18
19
20
21
22
23
24
# File '/var/www/sass-pages/.sass/lib/sass/script/interpolation.rb', line 17

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

Instance Method Details

- (Sass::Script::String) _perform(environment) (protected)

Evaluates the interpolation.

Parameters:

  • (Sass::Environment) environment — The environment in which to evaluate the SassScript

Returns:



68
69
70
71
72
73
74
75
76
77
# File '/var/www/sass-pages/.sass/lib/sass/script/interpolation.rb', line 68

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
  opts(Sass::Script::String.new(res))
end

- (Array<Node>) children

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

Returns:

See Also:



49
50
51
# File '/var/www/sass-pages/.sass/lib/sass/script/interpolation.rb', line 49

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

- deep_copy

See Also:



54
55
56
57
58
59
60
# File '/var/www/sass-pages/.sass/lib/sass/script/interpolation.rb', line 54

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

- (String) inspect

A human-readable s-expression representation of the interpolation

Returns:

  • (String) — A human-readable s-expression representation of the interpolation


27
28
29
# File '/var/www/sass-pages/.sass/lib/sass/script/interpolation.rb', line 27

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

- to_sass(opts = {})

See Also:



32
33
34
35
36
37
38
39
40
41
42
# File '/var/www/sass-pages/.sass/lib/sass/script/interpolation.rb', line 32

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