Class Index [+]

Quicksearch

Sass::Script::String

A SassScript object representing a CSS string or a CSS identifier.

Attributes

value[R]

The Ruby value of the string.

@return [String]

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`

Public Class Methods

new(value, type = :identifier) click to toggle source

Creates a new string.

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

    # 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) click to toggle source

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=

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

@see Literal#plus

    # 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 = {}) click to toggle source

@see Node#to_s

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

@see Node#to_sass

    # 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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.