class Sass::Script::Tree::StringInterpolation
@see Interpolation
A SassScript object representing ‘#{}` interpolation within a string.
def _perform(environment)
-
(Sass::Script::Value::String)
-
Parameters:
-
environment
(Sass::Environment
) -- The environment in which to evaluate the SassScript
def _perform(environment) res = "" before = @before.perform(environment) res << before.value mid = @mid.perform(environment) res << (mid.is_a?(Sass::Script::Value::String) ? mid.value : mid.to_s(:quote => :none)) res << @after.perform(environment).value opts(Sass::Script::Value::String.new(res, before.type)) end
def _to_sass(string_or_interp, opts)
def _to_sass(string_or_interp, opts) result = string_or_interp.to_sass(opts) opts[:quote] == :none ? result : result.slice(1...-1) end
def children
- See: Node#children -
See: #initialize -
Returns:
-
(Array
-)
def children [@before, @mid, @after].compact end
def deep_copy
- See: Node#deep_copy -
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
def initialize(before, mid, after)
-
after
(Literal
) -- See {StringInterpolation#after} -
mid
(Node
) -- See {StringInterpolation#mid} -
before
(StringInterpolation, Literal
) -- See {StringInterpolation#before}
def initialize(before, mid, after) @before = before @mid = mid @after = after end
def inspect
-
(String)
- A human-readable s-expression representation of the interpolation
def inspect "(string_interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})" end
def quote
Returns the quote character that should be used to wrap a Sass
def quote quote_for(self) || '"' end
def quote_for(string_or_interp)
def quote_for(string_or_interp) if string_or_interp.is_a?(Sass::Script::Tree::Literal) return nil if string_or_interp.value.value.empty? return '"' if string_or_interp.value.value.include?("'") return "'" if string_or_interp.value.value.include?('"') return nil end # Double-quotes take precedence over single quotes. before_quote = quote_for(string_or_interp.before) return '"' if before_quote == '"' after_quote = quote_for(string_or_interp.after) return '"' if after_quote == '"' # Returns "'" if either or both insist on single quotes, and nil # otherwise. before_quote || after_quote end
def to_sass(opts = {})
- See: Node#to_sass -
def to_sass(opts = {}) quote = type == :string ? opts[:quote] || quote_for(self) || '"' : :none opts = opts.merge(:quote => quote) res = "" res << quote if quote != :none res << _to_sass(before, opts) res << '#{' << @mid.to_sass(opts.merge(:quote => nil)) << '}' res << _to_sass(after, opts) res << quote if quote != :none res end
def type
-
(Symbol)
- `:string` or `:identifier`
def type @before.value.type end