Class | Sass::Script::Interpolation |
In: |
lib/sass/script/interpolation.rb
|
Parent: | Node |
A SassScript object representing `#{}` interpolation outside a string.
@see StringInterpolation
Interpolation in a property is of the form `before #{mid} after`.
@param before [Node] The SassScript before the interpolation @param mid [Node] The SassScript within the interpolation @param after [Node] The SassScript after the interpolation @param wb [Boolean] Whether there was whitespace between `before` and `#{` @param wa [Boolean] Whether there was whitespace between `}` and `after`
# File lib/sass/script/interpolation.rb, line 13 13: def initialize(before, mid, after, wb, wa) 14: @before = before 15: @mid = mid 16: @after = after 17: @whitespace_before = wb 18: @whitespace_after = wa 19: end
Returns the three components of the interpolation, `before`, `mid`, and `after`.
@return [Array<Node>] @see initialize @see Node#children
# File lib/sass/script/interpolation.rb, line 42 42: def children 43: [@before, @mid, @after].compact 44: end
@see Node#to_sass
# File lib/sass/script/interpolation.rb, line 27 27: def to_sass(opts = {}) 28: res = "" 29: res << @before.to_sass(opts) if @before 30: res << ' ' if @before && @whitespace_before 31: res << '#{' << @mid.to_sass(opts) << '}' 32: res << ' ' if @after && @whitespace_after 33: res << @after.to_sass(opts) if @after 34: res 35: end
Evaluates the interpolation.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Sass::Script::String] The SassScript string that is the value of the interpolation
# File lib/sass/script/interpolation.rb, line 52 52: def _perform(environment) 53: res = "" 54: res << @before.perform(environment).to_s if @before 55: res << " " if @before && @whitespace_before 56: val = @mid.perform(environment) 57: res << (val.is_a?(Sass::Script::String) ? val.value : val.to_s) 58: res << " " if @after && @whitespace_after 59: res << @after.perform(environment).to_s if @after 60: Sass::Script::String.new(res) 61: end