class Sass::Script::Tree::Interpolation
@see StringInterpolation
A SassScript object representing ‘#{}` interpolation outside 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 = "" 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 ING on line #{line}, column #{source_range.start_pos.offset}#{" of #{filename}" if filename}: probably don't mean to use the color value `#{val}' in interpolation here. ay end up represented as #{val.inspect}, which will likely produce invalid CSS. ys quote color names when using them as strings (for example, "#{val}"). ou really want to use the color value here, use `#{alternative.to_sass}'. AGE end res << val.to_s(:quote => :none) res << " " if @after && @whitespace_after res << @after.perform(environment).to_s if @after str = Sass::Script::Value::String.new( res, :identifier, (to_quoted_equivalent.to_sass if deprecation == :potential)) str.source_range = source_range opts(str) end
def children
- See: Node#children -
See: #initialize -
Returns:
-
(Array
-)
def children [@before, @mid, @after].compact end
def concat(string_or_interp1, string_or_interp2)
-
(Sass::Script::Tree::StringInterpolation)
-
Parameters:
-
string_or_interp2
(Sass::Script::Tree::Literal|Sass::Script::Tree::StringInterpolation
) -- -
string_or_interp1
(Sass::Script::Tree::Literal|Sass::Script::Tree::StringInterpolation
) --
def concat(string_or_interp1, string_or_interp2) if string_or_interp1.is_a?(Literal) && string_or_interp2.is_a?(Literal) return string_literal(string_or_interp1.value.value + string_or_interp2.value.value) end if string_or_interp1.is_a?(Literal) string = string_or_interp1 interp = string_or_interp2 before = string_literal(string.value.value + interp.before.value.value) return StringInterpolation.new(before, interp.mid, interp.after) end StringInterpolation.new( string_or_interp1.before, string_or_interp1.mid, concat(string_or_interp1.after, string_or_interp2)) 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, wb, wa, opts = {})
-
warn_for_color
(Boolean
) -- See {Interpolation#warn_for_color} -
originally_text
(Boolean
) -- See {Interpolation#originally_text} -
wa
(Boolean
) -- See {Interpolation#whitespace_after} -
wb
(Boolean
) -- See {Interpolation#whitespace_before} -
after
(Node
) -- See {Interpolation#after} -
mid
(Node
) -- See {Interpolation#mid} -
before
(Node
) -- See {Interpolation#before}
def initialize(before, mid, after, wb, wa, opts = {}) @before = before @mid = mid @after = after @whitespace_before = wb @whitespace_after = wa @originally_text = opts[:originally_text] || false @warn_for_color = opts[:warn_for_color] || false @deprecation = opts[:deprecation] || :none end
def inspect
-
(String)
- A human-readable s-expression representation of the interpolation
def inspect "(interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})" end
def string_literal(string)
-
string
(String
) --
def string_literal(string) Literal.new(Sass::Script::Value::String.new(string, :string)) end
def to_quoted_equivalent
-
(Sass::Script::Tree::Node)
-
def to_quoted_equivalent Funcall.new( "unquote", [to_string_interpolation(self)], Sass::Util::NormalizedMap.new, nil, nil) end
def to_sass(opts = {})
- See: Node#to_sass -
def to_sass(opts = {}) return to_quoted_equivalent.to_sass if deprecation == :immediate 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
def to_string_interpolation(node_or_interp)
-
(Sass::Script::Tree::StringInterpolation)
-
Parameters:
-
node_or_interp
(Sass::Script::Tree::Node
) --
def to_string_interpolation(node_or_interp) unless node_or_interp.is_a?(Interpolation) node = node_or_interp return string_literal(node.value.to_s) if node.is_a?(Literal) if node.is_a?(StringInterpolation) return concat(string_literal(node.quote), concat(node, string_literal(node.quote))) end return StringInterpolation.new(string_literal(""), node, string_literal("")) end interp = node_or_interp after_string_or_interp = if interp.after to_string_interpolation(interp.after) else string_literal("") end if interp.after && interp.whitespace_after after_string_or_interp = concat(string_literal(' '), after_string_or_interp) end mid_string_or_interp = to_string_interpolation(interp.mid) before_string_or_interp = if interp.before to_string_interpolation(interp.before) else string_literal("") end if interp.before && interp.whitespace_before before_string_or_interp = concat(before_string_or_interp, string_literal(' ')) end concat(before_string_or_interp, concat(mid_string_or_interp, after_string_or_interp)) end