Class | Sass::Script::String
In: | lib/sass/script/string.rb
Parent: | Literal

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

new(value, type = :identifier)

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

context=(context)

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

plus(other)

@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

to_s(opts = {})

@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

to_sass(opts = {})

@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]