Class: Sass::Script::Value::String

Inherits:
Base
  • Object
show all
Defined in:
lib/sass/script/value/string.rb

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Base

#options, #source_range

Instance Method Summary collapse

Methods inherited from Base

#==, #_perform, #assert_int!, #div, #eq, #eql?, #hash, #inspect, #minus, #neq, #null?, #separator, #single_eq, #to_a, #to_bool, #to_h, #to_i, #unary_div, #unary_minus, #unary_not, #unary_plus

Constructor Details

#initialize(value, type = :identifier) ⇒ String

Creates a new string.

Parameters:

  • value (String)

    See #value

  • type (Symbol) (defaults to: :identifier)

    See #type



20
21
22
23
# File 'lib/sass/script/value/string.rb', line 20

def initialize(value, type = :identifier)
  super(value)
  @type = type
end

Instance Attribute Details

#typeSymbol (readonly)

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

Returns:

  • (Symbol)

    :string or :identifier



14
15
16
# File 'lib/sass/script/value/string.rb', line 14

def type
  @type
end

#valueString (readonly)

The Ruby value of the string.

Returns:



7
8
9
# File 'lib/sass/script/value/string.rb', line 7

def value
  @value
end

Instance Method Details

#plus(other)

See Also:

  • Value#plus


26
27
28
29
# File 'lib/sass/script/value/string.rb', line 26

def plus(other)
  other_str = other.is_a?(Sass::Script::Value::String) ? other.value : other.to_s
  Sass::Script::Value::String.new(value + other_str, type)
end

#to_s(opts = {})

See Also:

  • Value#to_s


32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sass/script/value/string.rb', line 32

def to_s(opts = {})
  if @type == :identifier
    return @value.gsub(/\n\s*/, " ")
  end

  return "\"#{value.gsub('"', "\\\"")}\"" if opts[:quote] == %q{"}
  return "'#{value.gsub("'", "\\'")}'" if opts[:quote] == %q{'}
  return "\"#{value}\"" unless value.include?('"')
  return "'#{value}'" unless value.include?("'")
  "\"#{value.gsub('"', "\\\"")}\"" # '
end

#to_sass(opts = {})

See Also:

  • Value#to_sass


45
46
47
# File 'lib/sass/script/value/string.rb', line 45

def to_sass(opts = {})
  to_s
end