Class: Sass::Script::StringInterpolation
- Defined in:
- lib/sass/script/string_interpolation.rb
Overview
A SassScript object representing #{}
interpolation within a string.
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#_perform(environment) ⇒ Sass::Script::String
protected
Evaluates the interpolation.
-
#children ⇒ Array<Node>
Returns the three components of the interpolation,
before
,mid
, andafter
. - #deep_copy
-
#initialize(before, mid, after) ⇒ StringInterpolation
constructor
Interpolation in a string is of the form
"before #{mid} after"
, wherebefore
andafter
may include more interpolation. -
#inspect ⇒ String
A human-readable s-expression representation of the interpolation.
- #to_sass(opts = {})
Methods inherited from Node
Constructor Details
#initialize(before, mid, after) ⇒ StringInterpolation
Interpolation in a string is of the form "before #{mid} after"
,
where before
and after
may include more interpolation.
12 13 14 15 16 |
# File 'lib/sass/script/string_interpolation.rb', line 12
def initialize(before, mid, after)
@before = before
@mid = mid
@after = after
end
|
Instance Method Details
#_perform(environment) ⇒ Sass::Script::String (protected)
Evaluates the interpolation.
78 79 80 81 82 83 84 85 86 |
# File 'lib/sass/script/string_interpolation.rb', line 78
def _perform(environment)
res = ""
before = @before.perform(environment)
res << before.value
mid = @mid.perform(environment)
res << (mid.is_a?(Sass::Script::String) ? mid.value : mid.to_s)
res << @after.perform(environment).value
opts(Sass::Script::String.new(res, before.type))
end
|
#children ⇒ Array<Node>
Returns the three components of the interpolation, before
, mid
, and after
.
59 60 61 |
# File 'lib/sass/script/string_interpolation.rb', line 59
def children
[@before, @mid, @after].compact
end
|
#deep_copy
64 65 66 67 68 69 70 |
# File 'lib/sass/script/string_interpolation.rb', line 64
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.
19 20 21 |
# File 'lib/sass/script/string_interpolation.rb', line 19
def inspect
"(string_interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
end
|
#to_sass(opts = {})
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sass/script/string_interpolation.rb', line 24
def to_sass(opts = {})
# We can get rid of all of this when we remove the deprecated :equals context
# XXX CE: It's gone now but I'm not sure what can be removed now.
before_unquote, before_quote_char, before_str = parse_str(@before.to_sass(opts))
after_unquote, after_quote_char, after_str = parse_str(@after.to_sass(opts))
unquote = before_unquote || after_unquote ||
(before_quote_char && !after_quote_char && !after_str.empty?) ||
(!before_quote_char && after_quote_char && !before_str.empty?)
quote_char =
if before_quote_char && after_quote_char && before_quote_char != after_quote_char
before_str.gsub!("\\'", "'")
before_str.gsub!('"', "\\\"")
after_str.gsub!("\\'", "'")
after_str.gsub!('"', "\\\"")
'"'
else
before_quote_char || after_quote_char
end
res = ""
res << 'unquote(' if unquote
res << quote_char if quote_char
res << before_str
res << '#{' << @mid.to_sass(opts) << '}'
res << after_str
res << quote_char if quote_char
res << ')' if unquote
res
end
|