Class: Sass::Script::Tree::Interpolation
- Defined in:
- lib/sass/script/tree/interpolation.rb
Overview
A SassScript object representing #{}
interpolation outside a string.
Instance Attribute Summary collapse
-
#after ⇒ Node
readonly
The SassScript after the interpolation.
-
#before ⇒ Node
readonly
The SassScript before the interpolation.
-
#mid ⇒ Node
readonly
The SassScript within the interpolation.
-
#originally_text ⇒ Boolean
readonly
Whether the original format of the interpolation was plain text, not an interpolation.
-
#warn_for_color ⇒ Boolean
readonly
Whether a color value passed to the interpolation should generate a warning.
-
#whitespace_after ⇒ Boolean
readonly
Whether there was whitespace between
}
andafter
. -
#whitespace_before ⇒ Boolean
readonly
Whether there was whitespace between
before
and#{
.
Attributes inherited from Node
#filename, #line, #options, #source_range
Instance Method Summary collapse
-
#_perform(environment) ⇒ Sass::Script::Value::String
protected
Evaluates the interpolation.
-
#children ⇒ Array<Node>
Returns the three components of the interpolation,
before
,mid
, andafter
. - #deep_copy
-
#initialize(before, mid, after, wb, wa, originally_text = false, warn_for_color = false) ⇒ Interpolation
constructor
Interpolation in a property is of the form
before #{mid} after
. -
#inspect ⇒ String
A human-readable s-expression representation of the interpolation.
- #to_sass(opts = {})
Methods inherited from Node
Constructor Details
#initialize(before, mid, after, wb, wa, originally_text = false, warn_for_color = false) ⇒ Interpolation
Interpolation in a property is of the form before #{mid} after
.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sass/script/tree/interpolation.rb', line 41
def initialize(before, mid, after, wb, wa, originally_text = false, warn_for_color = false)
# rubocop:enable ParameterLists
@before = before
@mid = mid
@after = after
@whitespace_before = wb
@whitespace_after = wa
@originally_text = originally_text
@warn_for_color = warn_for_color
end
|
Instance Attribute Details
#after ⇒ Node (readonly)
Returns The SassScript after the interpolation.
13 14 15 |
# File 'lib/sass/script/tree/interpolation.rb', line 13
def after
@after
end
|
#before ⇒ Node (readonly)
Returns The SassScript before the interpolation.
7 8 9 |
# File 'lib/sass/script/tree/interpolation.rb', line 7
def before
@before
end
|
#mid ⇒ Node (readonly)
Returns The SassScript within the interpolation.
10 11 12 |
# File 'lib/sass/script/tree/interpolation.rb', line 10
def mid
@mid
end
|
#originally_text ⇒ Boolean (readonly)
Returns 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
|
#warn_for_color ⇒ Boolean (readonly)
Returns Whether a color value passed to the interpolation should generate a warning.
28 29 30 |
# File 'lib/sass/script/tree/interpolation.rb', line 28
def warn_for_color
@warn_for_color
end
|
#whitespace_after ⇒ Boolean (readonly)
Returns 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_before ⇒ Boolean (readonly)
Returns 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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sass/script/tree/interpolation.rb', line 95
def _perform(environment)
res = ""
res << @before.perform(environment).to_s if @before
res << " " if @before && @whitespace_before
val = @mid.perform(environment)
if @warn_for_color && val.is_a?(Sass::Script::Value::Color) && val.name
alternative = Operation.new(Sass::Script::Value::String.new("", :string), @mid, :plus)
Sass::Util.sass_warn <<MESSAGE
WARNING on line #{line}, column #{source_range.start_pos.offset}#{" of #{filename}" if filename}:
You probably don't mean to use the color value `#{val}' in interpolation here.
It may end up represented as #{val.inspect}, which will likely produce invalid CSS.
Always quote color names when using them as strings (for example, "#{val}").
If you really want to use the color value here, use `#{alternative.to_sass}'.
MESSAGE
end
res << val.to_s(:quote => :none)
res << " " if @after && @whitespace_after
res << @after.perform(environment).to_s if @after
opts(Sass::Script::Value::String.new(res))
end
|
#children ⇒ Array<Node>
Returns the three components of the interpolation, before
, mid
, and after
.
75 76 77 |
# File 'lib/sass/script/tree/interpolation.rb', line 75
def children
[@before, @mid, @after].compact
end
|
#deep_copy
80 81 82 83 84 85 86 |
# File 'lib/sass/script/tree/interpolation.rb', line 80
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 ⇒ String
Returns A human-readable s-expression representation of the interpolation.
53 54 55 |
# File 'lib/sass/script/tree/interpolation.rb', line 53
def inspect
"(interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
end
|
#to_sass(opts = {})
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sass/script/tree/interpolation.rb', line 58
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
|