Class Sass::Script::StringInterpolation
In: lib/sass/script/string_interpolation.rb
Parent: Node
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class SelectorPseudoClass Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Interpolation Variable Lexer CssLexer Number Bool String Parser Parser CssParser EvaluationContext StaticParser SassParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode ExtendNode VariableNode WarnNode RootNode WhileNode RuleNode MixinDefNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/literal.rb lib/sass/script/node.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptLexer ScriptParser RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_85_0.png

A SassScript object representing `#{}` interpolation within a string.

@see Interpolation

Methods

_perform   children   inspect   new   parse_str   to_sass  

Public Class methods

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

[Source]

    # 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

Public Instance methods

Returns the three components of the interpolation, `before`, `mid`, and `after`.

@return [Array<Node>] @see initialize @see Node#children

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

Protected Instance methods

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

[Source]

    # 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

Private Instance methods

[Source]

    # File lib/sass/script/string_interpolation.rb, line 80
80:     def parse_str(str)
81:       case str
82:       when /^unquote\((["'])(.*)\1\)$/
83:         return true, $1, $2
84:       when '""'
85:         return false, nil, ""
86:       when /^(["'])(.*)\1$/
87:         return false, $1, $2
88:       else
89:         return false, nil, str
90:       end
91:     end

[Validate]