Class: Sass::Script::Tree::StringInterpolation
- Inherits:
- Node
- Object
- Node
- Sass::Script::Tree::StringInterpolation
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb
Overview
A SassScript object representing #{}
interpolation within a string.
Instance Attribute Summary (collapse)
- - (StringInterpolation, Literal) after readonly
The string literal or string interpolation before this interpolation.
- - (Literal) before readonly
The string literal before this interpolation.
- - (Node) mid readonly
The SassScript within the interpolation.
Attributes inherited from Node
#css_variable_warning, #filename, #line, #options, #source_range
Instance Method Summary (collapse)
- - (Sass::Script::Value::String) _perform(environment) protected
Evaluates the interpolation.
- - (Array<Node>) children
Returns the three components of the interpolation,
before
,mid
, andafter
. - - deep_copy
- - (StringInterpolation) initialize(before, mid, after) constructor
Interpolation in a string is of the form
"before #{mid} after"
, wherebefore
andafter
may include more interpolation. - - (String) inspect
A human-readable s-expression representation of the interpolation.
- - quote
Returns the quote character that should be used to wrap a Sass representation of this interpolation.
- - to_sass(opts = {})
- - (Symbol) type
Whether this is a CSS string or a CSS identifier.
Methods inherited from Node
#dasherize, #force_division!, #opts, #perform
Constructor Details
- (StringInterpolation) initialize(before, mid, after)
Interpolation in a string is of the form "before #{mid} after"
, where before
and after
may include more interpolation.
39 40 41 42 43 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 39
def initialize(before, mid, after)
@before = before
@mid = mid
@after = after
end |
Instance Attribute Details
- (StringInterpolation, Literal) after (readonly)
Returns The string literal or string interpolation before this interpolation.
14 15 16 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 14
def after
@after
end |
- (Literal) before (readonly)
Returns The string literal before this interpolation.
7 8 9 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 7
def before
@before
end |
- (Node) mid (readonly)
Returns The SassScript within the interpolation
10 11 12 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 10
def mid
@mid
end |
Instance Method Details
- (Sass::Script::Value::String) _perform(environment) (protected)
Evaluates the interpolation.
89 90 91 92 93 94 95 96 97 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 89
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 |
- (Array<Node>) children
Returns the three components of the interpolation, before
, mid
, and after
.
69 70 71 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 69
def children
[@before, @mid, @after].compact
end |
- deep_copy
74 75 76 77 78 79 80 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 74
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 |
- (String) inspect
Returns A human-readable s-expression representation of the interpolation
46 47 48 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 46
def inspect
"(string_interpolation #{@before.inspect} #{@mid.inspect} #{@after.inspect})"
end |
- quote
Returns the quote character that should be used to wrap a Sass representation of this interpolation.
29 30 31 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 29
def quote
quote_for(self) || '"'
end |
- to_sass(opts = {})
51 52 53 54 55 56 57 58 59 60 61 62 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 51
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 |
- (Symbol) type
Whether this is a CSS string or a CSS identifier. The difference is that strings are written with double-quotes, while identifiers aren’t.
String interpolations are only ever identifiers if they’re quote-like functions such as url()
.
23 24 25 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/script/tree/string_interpolation.rb', line 23
def type
@before.value.type
end |