Sha256: e848361001394b5a6cd04e9deb5362c557c524a4e1f6435a3815205c304c190f

Contents?: true

Size: 1.35 KB

Versions: 489

Compression:

Stored size: 1.35 KB

Contents

require 'sass/script/literal'

module Sass::Script
  # A SassScript object representing a CSS string *or* a CSS identifier.
  class String < Literal
    # The Ruby value of the string.
    #
    # @return [String]
    attr_reader :value

    # 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`
    attr_reader :type

    # Creates a new string.
    #
    # @param value [String] See \{#value}
    # @param type [Symbol] See \{#type}
    def initialize(value, type = :identifier)
      super(value)
      @type = type
    end

    # @see Literal#plus
    def plus(other)
      other_str = other.is_a?(Sass::Script::String) ? other.value : other.to_s
      Sass::Script::String.new(self.value + other_str, self.type)
    end

    # @see Node#to_s
    def to_s(opts = {})
      if @type == :identifier
        return @value.tr("\n", " ")
      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

    # @see Node#to_sass
    def to_sass(opts = {})
      to_s
    end
  end
end

Version data entries

489 entries across 208 versions & 9 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/haml-3.1.6/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.18/lib/sass/script/string.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.15/lib/sass/script/string.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.17/lib/sass/script/string.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.19/lib/sass/script/string.rb
classiccms-0.7.5 vendor/bundle/gems/haml-3.1.5/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.5 vendor/bundle/gems/haml-3.1.4/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.15/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.17/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/haml-3.1.5/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/haml-3.1.4/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.18/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.19/lib/sass/script/string.rb
classiccms-0.7.4 vendor/bundle/gems/haml-3.1.6/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.3 vendor/bundle/gems/haml-3.1.6/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.3 vendor/bundle/gems/haml-3.1.5/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.15/lib/sass/script/string.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.18/lib/sass/script/string.rb
classiccms-0.7.3 vendor/bundle/gems/haml-3.1.4/vendor/sass/lib/sass/script/string.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.17/lib/sass/script/string.rb