Class Sass::Script::String
In: lib/sass/script/string.rb
Parent: Literal
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 a CSS string or a CSS identifier.

Methods

context=   new   plus   to_s   to_sass  

Attributes

type  [R]  Whether this is a CSS string or a CSS identifier. The difference is that strings are written with double-quotes, while identifiers aren‘t.

@return [Symbol] `:string` or `:identifier`

value  [R]  The Ruby value of the string.

@return [String]

Public Class methods

Creates a new string.

@param value [String] See \{value} @param type [Symbol] See \{type}

[Source]

    # File lib/sass/script/string.rb, line 31
31:     def initialize(value, type = :identifier)
32:       super(value)
33:       @type = type
34:     end

Public Instance methods

In addition to setting the \{context} of the string, this sets the string to be an identifier if the context is `:equals`.

@see Node#context=

[Source]

    # File lib/sass/script/string.rb, line 22
22:     def context=(context)
23:       super
24:       @type = :identifier if context == :equals
25:     end

@see Literal#plus

[Source]

    # File lib/sass/script/string.rb, line 37
37:     def plus(other)
38:       other_str = other.is_a?(Sass::Script::String) ? other.value : other.to_s
39:       Sass::Script::String.new(self.value + other_str, self.type)
40:     end

@see Node#to_s

[Source]

    # File lib/sass/script/string.rb, line 43
43:     def to_s(opts = {})
44:       if self.type == :identifier
45:         return %q{""} if context == :equals && self.value.size == 0
46:         return self.value.gsub("\n", " ")
47:       end
48: 
49:       return "\"#{value.gsub('"', "\\\"")}\"" if opts[:quote] == %q{"}
50:       return "'#{value.gsub("'", "\\'")}'" if opts[:quote] == %q{'}
51:       return "\"#{value}\"" unless value.include?('"')
52:       return "'#{value}'" unless value.include?("'")
53:       "\"#{value.gsub('"', "\\\"")}\"" #'
54:     end

@see Node#to_sass

[Source]

    # File lib/sass/script/string.rb, line 57
57:     def to_sass(opts = {})
58:       if self.type == :identifier && context == :equals &&
59:           self.value !~ Sass::SCSS::RX::URI &&
60:           Sass::SCSS::RX.escape_ident(self.value).include?(?\\)
61:         return "unquote(#{Sass::Script::String.new(self.value, :string).to_sass})"
62:       else
63:         return to_s
64:       end
65:     end

[Validate]