A SassScript object representing `#{}` interpolation within a string.
@see Interpolation
Interpolation in a string is of the form `“before #{mid} after”`, where `before` and `after` may include more interpolation.
@param before [Node] The string before the interpolation @param mid [Node] The SassScript within the interpolation @param after [Node] The string after the interpolation
# File lib/sass/script/string_interpolation.rb, line 12 12: def initialize(before, mid, after) 13: @before = before 14: @mid = mid 15: @after = after 16: end
Returns the three components of the interpolation, `before`, `mid`, and `after`.
@return [Array
# File lib/sass/script/string_interpolation.rb, line 58 58: def children 59: [@before, @mid, @after].compact 60: end
@return [String] A human-readable s-expression representation of the interpolation
# File lib/sass/script/string_interpolation.rb, line 19 19: def inspect 20: "(string_interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})" 21: end
@see Node#to_sass
# File lib/sass/script/string_interpolation.rb, line 24 24: def to_sass(opts = {}) 25: # We can get rid of all of this when we remove the deprecated :equals context 26: before_unquote, before_quote_char, before_str = parse_str(@before.to_sass(opts)) 27: after_unquote, after_quote_char, after_str = parse_str(@after.to_sass(opts)) 28: unquote = before_unquote || after_unquote || 29: (before_quote_char && !after_quote_char && !after_str.empty?) || 30: (!before_quote_char && after_quote_char && !before_str.empty?) 31: quote_char = 32: if before_quote_char && after_quote_char && before_quote_char != after_quote_char 33: before_str.gsub!("\\'", "'") 34: before_str.gsub!('"', "\\\"") 35: after_str.gsub!("\\'", "'") 36: after_str.gsub!('"', "\\\"") 37: '"' 38: else 39: before_quote_char || after_quote_char 40: end 41: 42: res = "" 43: res << 'unquote(' if unquote 44: res << quote_char if quote_char 45: res << before_str 46: res << '#{' << @mid.to_sass(opts) << '}' 47: res << after_str 48: res << quote_char if quote_char 49: res << ')' if unquote 50: res 51: 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/string_interpolation.rb, line 68 68: def _perform(environment) 69: res = "" 70: before = @before.perform(environment) 71: res << before.value 72: mid = @mid.perform(environment) 73: res << (mid.is_a?(Sass::Script::String) ? mid.value : mid.to_s) 74: res << @after.perform(environment).value 75: Sass::Script::String.new(res, before.type) 76: end
# File lib/sass/script/string_interpolation.rb, line 80 80: def parse_str(str) 81: case str 82: when /^unquote\((["'])(.*)\11\\)$/ 83: return true, $1, $2 84: when '""' 85: return false, nil, "" 86: when /^(["'])(.*)\11$$/ 87: return false, $1, $2 88: else 89: return false, nil, str 90: end 91: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.